我在客户端上使用WinXP,在服务器上使用Win2003。
我需要执行原子操作:创建移动文件、插入更新数据库。
使用 WinXP 进行文件系统事务有什么好的做法吗?
我知道在 Vista/Win2008/Win7 中有 TxF 事务 (NTFS),但在 WinXP 中没有。
我不想使用 COM+,也不想使用其他复杂的解决方案。只需要好的示例代码即可获得良好的实践。
事务和文件操作作者:阿尔贝托·波夫拉西翁
在早于 Vista 的 Windows 版本中,文件系统不是
事务性的,因此您需要一个单独的工具来对文件进行事务处理。
您可以使用组件服务 (COM+) 来实现补偿资源
经理(客户关系管理)。 CRM将提供事务日志并回滚
如果系统在更新期间崩溃,则系统重新启动期间会发生更改
文件,但您必须提供代码(在您自己的 DLL 中)来提交和
回滚事务,通常通过将文件移入和移出
临时文件夹。这一切都可以在 .Net 中通过以下方式完成
System.EnterpriseServices 命名空间。如果我没记错的话,微软
官方课程 2557 包含一章教授如何创建 CRM,
他们使用的示例正是基于对
文件系统。
在较新版本的 Windows 中,您可以在
NTFS:
http://msdn.microsoft.com/ en-us/library/bb986748(VS.85).aspx
http://msdn.microsoft.com/en-us/magazine /cc163388.aspx
http://codeproject.com/KB/vista/VistaKTM.aspx
编辑。
参考文献:
https://transactionalfilemgr.codeplex.com/
http://www.codeproject.com/Articles/690136/All-About-TransactionScope
http://ayende.com/blog/4528/who-stole-my-transaction
< a href="http://www.chinhdo.com/20080825/transactional-file-manager/" rel="nofollow noreferrer">http://www.chinhdo.com/20080825/transactional-file-manager/
http ://bmegias.wordpress.com/2010/10/25/ejecutar-acciones-al-finalizar-la-transaccion-transactioncompleted-vs-enlistvolatile/
I'm using WinXP on clients and Win2003 on a server.
I need do atomic actions: create-moving files, insert-update database.
Are there any good practices for file system transactions using WinXP?
I know in Vista/Win2008/Win7 there are TxF transaction (NTFS) but not in WinXP.
I don't want use COM+, neither other complex solutions. Only need good sample code, for good practices.
Transactions and file-actions by Alberto Poblacion
In versions of Windows earlier than Vista, the filesystem is not
transactional, so you need a separate tool to do transactions on your files.
You could use Component Services (COM+) to implement a Compensating Resource
Manager (CRM). The CRM will provide the transaction log and will roll back
changes during a system restart if it crashed during the update of your
files, but you will have to provide the code (in your own DLL) to commit and
rollback the transation, typically by means of moving files in and out of a
temp folder. It can all be done in .Net by means of the
System.EnterpriseServices namespace. If I recall correctly, Microsoft
Official Course 2557 contains a chapter that teaches how to create a CRM,
and the example that they use is built precisely on changes to the
filesystem.
In newer versions of Windows, you can do transactional operations on
NTFS:
http://msdn.microsoft.com/en-us/library/bb986748(VS.85).aspx
http://msdn.microsoft.com/en-us/magazine/cc163388.aspx
http://codeproject.com/KB/vista/VistaKTM.aspx
Edit.
References:
https://transactionalfilemgr.codeplex.com/
http://www.codeproject.com/Articles/690136/All-About-TransactionScope
http://ayende.com/blog/4528/who-stole-my-transaction
http://www.chinhdo.com/20080825/transactional-file-manager/
http://bmegias.wordpress.com/2010/10/25/ejecutar-acciones-al-finalizar-la-transaccion-transactioncompleted-vs-enlistvolatile/
发布评论
评论(4)
您可以创建自己的类来实现 IEnlistmentNotification。
以下是有人这样做的示例: http://www.chinhdo.com/20080825 /事务文件管理器/
You could create your own class that implements IEnlistmentNotification.
Here's an example of someone that did: http://www.chinhdo.com/20080825/transactional-file-manager/
您可能想查看 File.Replace 方法,我认为该方法使用事务,因为它需要 NTFS。 http://msdn.microsoft.com/en-我们/library/9d9h163f(v=vs.100).aspx
You might want to look at the File.Replace method which I think uses transactions since it requires NTFS. http://msdn.microsoft.com/en-us/library/9d9h163f(v=vs.100).aspx
在 XP 中,您不会获得 NTFS 的真实文件系统事务。也就是说,您可能不需要它。
例如,在软件安装中,您可以通过使用 Windows Installer 等工具免费获得交易语义。
您希望最终实现什么目标?
You won't get true filesystem transactions for NTFS in XP. That said, you may not need it.
For example, with software installation, you can largely get the semantics of transactions for free by using something like Windows Installer.
What is it you are looking to ultimately accomplish?
.NET 事务文件管理器 应该在 XP 下工作。
出于兴趣,TxF 可能会从 Windows 的未来版本中删除(某些功能在 Win 8 中已被弃用)。
请参阅如何编写事务来涵盖移动文件和在数据库中插入记录?。
The .NET Transactional File Manager should work under XP.
Out of interest, TxF is likely to be pulled from future releases of Windows (certain features have been deprecated in Win 8).
See How to write a transaction to cover Moving a file and Inserting record in database?.