목차
프로젝트 설명
백엔드 개발 C#.Net 튜토리얼 Transactional File Manager의 예에 대한 자세한 설명

Transactional File Manager의 예에 대한 자세한 설명

Apr 25, 2017 am 09:12 AM

推荐一个文件事물管리 Transactional File Manager

프로젝트 설명

Transactional File Manager는 파일 복사, 트랜잭션에서 이동, 삭제, 추가 등을 수행합니다. System.Transaction.IEnlistmentNotification(System.Transactions.TransactionScope와 함께 작동)의 구현입니다.

이 라이브러리를 사용하면 다음과 같은 트랜잭션에서 파일 시스템 작업을 래핑할 수 있습니다.

// Wrap a file copy and a database insert in the same transactionTxFileManager fileMgr = new TxFileManager();using (TransactionScope scope1 = new TransactionScope())
{// Copy a file
fileMgr.Copy(srcFileName, destFileName);// Insert a database record
dbMgr.ExecuteNonQuery(insertSql);scope1.Complete();
}
로그인 후 복사

Current 기능

  • 트랜잭션에서 다음 파일 작업을 지원합니다:

    • AppendAllText

    • 복사

    • 디렉터리 만들기

    • 디렉터리 삭제

    • 파일 삭제

    • 이동

    • 스냅샷

    • WriteAllText

    • WriteAllBytes

이 라이브러리는 모든 파일 시스템을 지원하며 트랜잭션 NTFS에 대한 래퍼가 아닙니다(AlphaFS 참조).

// Completely unrealistic example showing how various file operations, including operations done // by library/3rd party code, can participate in transactions.IFileManager fileManager = new TxFileManager();using (TransactionScope scope1 = new TransactionScope())
{    fileManager.WriteAllText(inFileName, xml);    // Snapshot allows any file operation to be part of our transaction.
    // All we need to know is the file name.
    //The statement below tells the TxFileManager to remember the state of this file.
    // So even though XslCompiledTransform has no knowledge of our TxFileManager, the file it creates (outFileName)
    // will still be restored to this state in the event of a rollback.
    fileManager.Snapshot(outFileName);    XslCompiledTransform xsl = new XslCompiledTransform(true);    xsl.Load(uri);    xsl.Transform(inFileName, outFileName);    // write to database 1. This database op will get committed/rolled back along with the file operations we are doing in this transaction.
    myDb1.ExecuteNonQuery(sql1);    // write to database 2. The transaction is promoted to a distributed transaction here.
    myDb2.ExecuteNonQuery(sql2);    // let's delete some files
    for (string fileName in filesToDelete)
    {
        fileManager.Delete(fileName);
    }    // Just for kicks, let's start a new nested  transaction. Since we specify RequiresNew here, this nested transaction
    // will be committed/rolled back separately from the main transaction.
    // Note that we can still use the same fileManager instance. It knows how to sort things out correctly.
    using (TransactionScope scope2 = new TransactionScope(TransactionScopeOptions.RequiresNew))
    {        fileManager.MoveFile(anotherFile, anotherFileDest);
    }    // move some files
    for (string fileName in filesToMove)
    {
        fileManager.Move(fileName, GetNewFileName(fileName));
    }    // Finally, let's create a few temporary files...
    // disk space has to be used for something.
    // The nice thing about FileManager.GetTempFileName is that
    // The temp file will be cleaned up automatically for you when the TransactionScope completes.
    // No more worries about temp files that get left behind.
    for (int i=0; i<10; i++)
    {
        fileManager.WriteAllText(fileManager.GetTempFileName(), "testing 1 2");
    }    scope1.Complete();    // In the event an exception occurs, everything done here will be rolled back including the output xsl file.}
로그인 후 복사

这是一个开源项目。原始项目网站是  事务文件管理器。

版权所有(c)2008-2013 Chinh Do

特此授予任何获得本软件和关文档文件(“软件”)副本的人免费许可,无限제지处理本软件,包括但不限于使用,复system,修改,合并的权利,发布,分发,再授权and/或take售本软件的副本,并允许提供本软件的人员遵守以下条件:

上述版权声明和本许可声明应包含在本软件的所有副本或主要分。

该软件“按原样”,提供任不附带任何明示或暗示的保证,包括但不限于适销性,适用于特任何索赔,损害或其他责任负责,无论是否因与本软件或本软件件的使用或其他交易易关的任何何,侵权行为或其他方面은 行为软件。

위 내용은 Transactional File Manager의 예에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

C#을 사용한 Active Directory C#을 사용한 Active Directory Sep 03, 2024 pm 03:33 PM

C#을 사용한 Active Directory

C#의 액세스 한정자 C#의 액세스 한정자 Sep 03, 2024 pm 03:24 PM

C#의 액세스 한정자

C#의 난수 생성기 C#의 난수 생성기 Sep 03, 2024 pm 03:34 PM

C#의 난수 생성기

C# 데이터 그리드 보기 C# 데이터 그리드 보기 Sep 03, 2024 pm 03:32 PM

C# 데이터 그리드 보기

C# 스트링리더 C# 스트링리더 Sep 03, 2024 pm 03:23 PM

C# 스트링리더

C#의 패턴 C#의 패턴 Sep 03, 2024 pm 03:33 PM

C#의 패턴

C# 스트링라이터 C# 스트링라이터 Sep 03, 2024 pm 03:23 PM

C# 스트링라이터

C#의 BinaryWriter C#의 BinaryWriter Sep 03, 2024 pm 03:22 PM

C#의 BinaryWriter

See all articles