使用事务性 NTFS 的替代方案 [英] Alternatives to using Transactional NTFS

查看:29
本文介绍了使用事务性 NTFS 的替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于 Microsoft 已弃用事务性 NTFS (TxF):

Given that Microsoft has deprecated Transactional NTFS (TxF):

Microsoft 强烈建议开发人员使用替代方法来满足您的应用程序需求.可以通过更简单、更容易获得的技术来实现 TxF 所针对的许多场景.此外,TxF 可能在 Microsoft Windows 的未来版本中不可用.

Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in future versions of Microsoft Windows.

虽然 TxF 是一组强大的 API,但自 Windows Vista 以来,开发人员对该 API 平台的兴趣极其有限,主要是因为其复杂性和开发人员在应用程序开发过程中需要考虑的各种细微差别.因此,Microsoft 正在考虑在未来版本的 Windows 中弃用 TxF API,以便将开发和维护工作重点放在对大多数客户更有价值的其他功能和 API 上.

While TxF is a powerful set of APIs, there has been extremely limited developer interest in this API platform since Windows Vista primarily due to its complexity and various nuances which developers need to consider as part of application development. As a result, Microsoft is considering deprecating TxF APIs in a future version of Windows to focus development and maintenance efforts on other features and APIs which have more value to a larger majority of customers.

这意味着我需要一个替代方案:

This means that i need an alternative to:

我的交易要求相当简单 - 移动两个文件:

My transacted requirements are fairly simple - move two files:

tx = BeginTransaction();
{
   MoveFile(testResults, testResultsArchive); //throws if there's a problem
   MoveFile(cdcResponse, cdcResponseArchive); //throws if there's a problem

   CommitTransaction(tx);
}
finally
{
    CloseHandle(tx);
}

我想过把 MoveFile 变成 CopyFile + DeleteFile:

i've thought about turning MoveFile in to CopyFile + DeleteFile:

CopyFile(testResults, testResultsArchive); //throws if there's a problem
CopyFile(cdcResponse, cdcResponseArchive); //throws if there's a problem

DeleteFile(testResults);
DeleteFile(cdcResponse);

但我希望有一个好的解决方案,而不是一个有问题的解决方案.所以我再试一次:

But i was hoping for a good solution, not a buggy solution. So i try again:

CopyFile(testResults, testResultsArchive); //throws if there's a problem
CopyFile(cdcResponse, cdcResponseArchive); //throws if there's a problem

try
{
    DeleteFile(testResults);
}
catch (Exception e)
{
   DeleteFile(testResultsArchive);
   throw e;
}
try
{
    DeleteFile(cdcResponse);
}
catch (Exception e)
{
   DeleteFile(cdcResponseArchive);
}

除了我希望有一个好的解决方案,而不是一个错误的解决方案.

Except i was hoping for a good solution, not a buggy one.

推荐答案

试用 .NET 事务文件管理器.安全使用它相当简单.页面中的以下示例显示了该方法.甚至看起来作者是响应式的,并且能够使用新的有用功能扩展库.

Give a try to .NET Transactional File Manager. It is fairly simple to use it safely. The following example from the page shows the way. It even looks like the author is responsive and is able to extend the library with new useful features.

// Wrap a file copy and a database insert in the same transaction
TxFileManager fileMgr = new TxFileManager();
using (TransactionScope scope1 = new TransactionScope())
{
    // Copy a file
    fileMgr.Copy(srcFileName, destFileName);

    // Insert a database record
    dbMgr.ExecuteNonQuery(insertSql);

    scope1.Complete();
} 

如果您对自己的事务管理器感兴趣,请务必查看 这篇 文章.如果你仔细检查上面提到的库,你会发现它是这样实现的.

In case you are interested in your own transactional manager, be sure you check out this article. If you carefully examine the above mentioned library, you will find that it is implemented right this way.

这篇关于使用事务性 NTFS 的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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