简体   繁体   English

在WinXP上使用.NET进行文件系统事务

[英]File System Transactions using .NET on WinXP

I'm using WinXP on clients and Win2003 on a server. 我在客户端上使用WinXP,在服务器上使用Win2003。

I need do atomic actions: create-moving files, insert-update database. 我需要执行原子操作:创建移动文件,插入更新数据库。

Are there any good practices for file system transactions using WinXP? 是否有使用WinXP进行文件系统事务的良好实践? I know in Vista/Win2008/Win7 there are TxF transaction (NTFS) but not in WinXP. 我知道在Vista / Win2008 / Win7中有TxF事务(NTFS),但在WinXP中却没有

I don't want use COM+, neither other complex solutions. 我不想使用COM +,也不想使用其他复杂的解决方案。 Only need good sample code, for good practices. 仅需良好的示例代码,即可获得良好实践。

Transactions and file-actions by Alberto Poblacion 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. 在Windows Vista之前的Windows版本中,文件系统不是事务性的,因此您需要一个单独的工具来对文件进行事务处理。

You could use Component Services (COM+) to implement a Compensating Resource Manager (CRM). 您可以使用组件服务(COM +)来实现补偿资源管理器(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. CRM将提供事务日志,并且如果在文件更新期间崩溃则在系统重新启动期间回滚更改,但是您必须提供代码(在您自己的DLL中)来提交和回滚转换,通常是通过以下方式将文件移入和移出临时文件夹的过程。 It can all be done in .Net by means of the System.EnterpriseServices namespace. 可以通过System.EnterpriseServices命名空间在.Net中完成所有操作。 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. 如果我没记错的话,Microsoft官方课程2557包含一章,该章讲授如何创建CRM,它们使用的示例正是基于对文件系统的更改而建立的。

In newer versions of Windows, you can do transactional operations on NTFS: 在Windows的较新版本中,可以在NTFS上执行事务操作:

http://msdn.microsoft.com/en-us/library/bb986748(VS.85).aspx http://msdn.microsoft.com/zh-cn/library/bb986748(VS.85).aspx

http://msdn.microsoft.com/en-us/magazine/cc163388.aspx http://msdn.microsoft.com/zh-CN/magazine/cc163388.aspx

http://codeproject.com/KB/vista/VistaKTM.aspx http://codeproject.com/KB/vista/VistaKTM.aspx

Edit. 编辑。

References: 参考文献:

https://transactionalfilemgr.codeplex.com/ https://transactionalfilemgr.codeplex.com/

http://www.codeproject.com/Articles/690136/All-About-TransactionScope http://www.codeproject.com/Articles/690136/All-About-TransactionScope

http://ayende.com/blog/4528/who-stole-my-transaction http://ayende.com/blog/4528/who-stole-my-transaction

http://www.chinhdo.com/20080825/transactional-file-manager/ http://www.chinhdo.com/20080825/transactional-file-manager/

http://bmegias.wordpress.com/2010/10/25/ejecutar-acciones-al-finalizar-la-transaccion-transactioncompleted-vs-enlistvolatile/ http://bmegias.wordpress.com/2010/10/25/ejecutar-acciones-al-finalizar-la-transaccion-transactioncompleted-vs-enlistvolatile/

You could create your own class that implements IEnlistmentNotification. 您可以创建自己的实现IEnlistmentNotification的类。

Here's an example of someone that did: http://www.chinhdo.com/20080825/transactional-file-manager/ 这是某人的示例: http : //www.chinhdo.com/20080825/transactional-file-manager/

The .NET Transactional File Manager should work under XP. .NET事务性文件管理器应在XP下运行。

Out of interest, TxF is likely to be pulled from future releases of Windows (certain features have been deprecated in Win 8). 出于兴趣,TxF可能会从Windows的将来版本中撤消(某些功能在Win 8中已弃用)。

See How to write a transaction to cover Moving a file and Inserting record in database? 请参阅如何编写事务以涵盖移动文件和在数据库中插入记录? .

You might want to look at the File.Replace method which I think uses transactions since it requires NTFS. 您可能想要查看File.Replace方法,我认为它使用事务,因为它需要NTFS。 http://msdn.microsoft.com/en-us/library/9d9h163f(v=vs.100).aspx http://msdn.microsoft.com/zh-CN/library/9d9h163f(v=vs.100).aspx

You won't get true filesystem transactions for NTFS in XP. 您将无法获得XP中NTFS的真实文件系统事务。 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. 例如,通过软件安装,您可以使用Windows Installer之类的东西来很大程度上免费获取事务的语义。

What is it you are looking to ultimately accomplish? 您希望最终实现什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM