如何在事务中传输文件。 [英] How to transfer file in a Transaction.

查看:136
本文介绍了如何在事务中传输文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我的应用程序中有一个场景,我需要将20个文件从源位置传输到目标位置(所有本地传输),如果其中一个文件无法传输,无论出于何种原因我需要滚动返回一个事务,以便所有文件都保留在源位置并从目标中消失。我已经看过这个交易范围,但我正在读,也许这不是最好的方法。有没有任何关于如何实现我的目标的例子。非常感谢

Hey guys, I have a scenario in my application where I need to transfer 20 files from a source location to a destination location (all local transfers), if one of the files fail to transfer, for whatever reason I need to roll back a transaction so that all the file remain in the source location and are gone from the destination. I have looked at transaction scope for this but I'm reading that maybe this is not the best approach for this. Has anyone any examples on how to achieve my goal. Thanks very much

推荐答案

在将文件传输到客户端(目标)时出现故障时需要引发异常。所以这就像



There needs to be an exception that gets raised when there is a failure while transfering the files to the client (destination). So that would be like

try {
  // send all the files
} catch (Exception er) {
  // exception was raised, 
  // if the exception was the File Not Transferred sort of thing
  // delete all of the Files from the Client.
}





这是一般情况,您尝试执行某些操作,如果错误触发,您删除(取消,回滚)您在客户端计算机上所做的任何更改。它类似于复制/粘贴功能,在取消单击后,更改将被删除,计算机又回到初始阶段。



编辑



当我离线时,我在考虑一个更好地解决这个问题。也就是说,您可以通过Internet连接传输文件,并记录已传输的每个文件及其传递报告(成功或失败)。执行此操作后,您将能够捕获详细信息并重新发送有问题的文件。因为删除成功发送的整个文件集并重试将文件发送到客户端不是一个好方法。只需重新发送一个文件。



不知怎的,你仍然对FileSystem事务类的东西感兴趣,你可以在Windows上找到'交易NTFS [ ^ ]。或者阅读 MSDN杂志 [ ^ ]。或者使用 Transactional NTFS [ ^ 。另请注意,有一个事务性文件管理器 [ ^ ]供您使用。



祝您好运。 : - )



This is a general case, where you attempt to do something, if error triggers, you delete (cancel, roll back) any changes that you've made on the clients computer. It is similar to a copy/paste function, upon Cancel click, the changes are removed and the computer is back in its initial stage.

Edit

While I was offline, I was thinking about a better solution for this problem. Which is, you can transfer the files over the internet connection and log each file that was transferred and the delivery report for it (either successfull or failure). Once you do this, you will be able to capture the details and resend the file that had a trouble. Because deleting the entire file set that was sent successfully and retrying to send the files to the client is not a good way. Just resend that one file.

Somehow you're still interested in the FileSystem transaction kind of thing, you can have a read at the Windows' Transactional NTFS[^]. Or read this MSDN magazine[^]. Or a simple Windows developer documentation for using Transactional NTFS[^]. Also note that there is a Transactional File Manager[^] available for you to use.

Good luck. :-)


尝试使用 .NET事务文件管理器 [ ^ ]


这篇关于如何在事务中传输文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆