简体   繁体   English

C#中的事务性文件管理

[英]Transactional file management in C#

I have a scenario in my application is that i need to upload some files (Zip files) from the client to the server and in the server i want to extract the Zip file and replace those files which i getting from extracting the Zip file into some other folder. 我的应用程序中有一种情况是,我需要从客户端向服务器上载一些文件(Zip文件),并且在服务器中我想提取Zip文件并替换那些我从Zip文件提取得到的文件中其他文件夹。

The files which i need to be replaced is mostly dll files. 我需要替换的文件主要是dll文件。 So one thing that i need to ensure that either all files should be replaced or none of them get replaced. 因此,我需要确保要么替换所有文件,要么都不替换任何文件。

Is there any way in C# to achieve this (like Transaction in SQL) ? C#中有什么方法可以实现这一点(例如SQL中的Transaction)? If anything bad occurs while replacing files (Example: no memory space), every changes happened to the previous files should be rollbacked. 如果替换文件时发生任何不良情况(例如:没有内存空间),则应回滚对先前文件所做的所有更改。

Hope you understand the problem. 希望您理解问题。

Any help ? 有什么帮助吗?

NTFS允许文件系统事务,请参阅https://msdn.microsoft.com/zh-cn/magazine/cc163388.aspx

Having a quick poke around, only way I can see you doing this would be through https://msdn.microsoft.com/en-us/magazine/cc163388.aspx which involves some native code. 快速查看一下,我可以看到的唯一方法是通过https://msdn.microsoft.com/zh-cn/magazine/cc163388.aspx ,其中涉及一些本机代码。 Otherwise you could use a third party tool such as http://transactionalfilemgr.codeplex.com/ 否则,您可以使用第三方工具,例如http://transactionalfilemgr.codeplex.com/

If you wanted to manage it yourself or go for a simpler approach, I would suggest backing up the existing files somewhere before trying to copy the new files. 如果您想自己管理它或采用更简单的方法,我建议在尝试复制新文件之前将现有文件备份到某个位置。 This could be in another folder or zipped up. 该文件可能位于另一个文件夹中或已压缩。 Then if the copy fails, you handle this and revert all the files to their original state. 然后,如果复制失败,则可以处理此问题并将所有文件还原为原始状态。

Whatever you choose, make sure you have plenty of logging so you can see what's happening and if/when something goes wrong :) 无论您选择什么,请确保您有足够的日志记录,以便可以查看正在发生的情况以及是否/何时出现问题:)

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

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