• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Filesystem.KernelTransaction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Alphaleonis.Win32.Filesystem.KernelTransaction的典型用法代码示例。如果您正苦于以下问题:C# KernelTransaction类的具体用法?C# KernelTransaction怎么用?C# KernelTransaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



KernelTransaction类属于Alphaleonis.Win32.Filesystem命名空间,在下文中一共展示了KernelTransaction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: EnumerateAlternateDataStreamsInternal

      internal static IEnumerable<AlternateDataStreamInfo> EnumerateAlternateDataStreamsInternal(KernelTransaction transaction, string path, PathFormat pathFormat)
      {
         using (var buffer = new SafeGlobalMemoryBufferHandle(Marshal.SizeOf(typeof(NativeMethods.WIN32_FIND_STREAM_DATA))))
         {
            path = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.CheckInvalidPathChars | GetFullPathOptions.CheckAdditional);
            using (var handle = transaction == null 
               ? NativeMethods.FindFirstStreamW(path, NativeMethods.StreamInfoLevels.FindStreamInfoStandard, buffer, 0) 
               : NativeMethods.FindFirstStreamTransactedW(path, NativeMethods.StreamInfoLevels.FindStreamInfoStandard, buffer, 0, transaction.SafeHandle))
            {
               if (handle.IsInvalid)
               {
                  int errorCode = Marshal.GetLastWin32Error();
                  if (errorCode == Win32Errors.ERROR_HANDLE_EOF)
                     yield break;

                  NativeError.ThrowException(errorCode);
               }

               while (true)
               {
                  NativeMethods.WIN32_FIND_STREAM_DATA data = buffer.PtrToStructure<NativeMethods.WIN32_FIND_STREAM_DATA>();
                  yield return new AlternateDataStreamInfo(path, data);
                  if (!NativeMethods.FindNextStreamW(handle, buffer))
                  {
                     int lastError = Marshal.GetLastWin32Error();
                     if (lastError == Win32Errors.ERROR_HANDLE_EOF)
                        break;

                     NativeError.ThrowException(lastError, path);
                  }
               }
            }
         }
      }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:34,代码来源:File.EnumerateAlternateDataStreams.cs


示例2: GetParentInternal

      internal static DirectoryInfo GetParentInternal(KernelTransaction transaction, string path, PathFormat pathFormat)
      {
         string pathLp = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.CheckInvalidPathChars);

         pathLp = Path.GetRegularPathInternal(pathLp, GetFullPathOptions.None);
         string dirName = Path.GetDirectoryName(pathLp, false);

         return Utils.IsNullOrWhiteSpace(dirName) ? null : new DirectoryInfo(transaction, dirName, PathFormat.RelativePath);
      }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:9,代码来源:Directory.GetParent.cs


示例3: DirectoryInfo

      private DirectoryInfo(KernelTransaction transaction, string fullPath, bool junk1, bool junk2)
      {
         IsDirectory = true;
         Transaction = transaction;

         LongFullName = Path.GetLongPathInternal(fullPath, GetFullPathOptions.None);

         OriginalPath = Path.GetFileName(fullPath, true);

         FullPath = fullPath;

         // GetDisplayName()
         DisplayPath = OriginalPath.Length != 2 || (OriginalPath[1] != Path.VolumeSeparatorChar) ? OriginalPath : Path.CurrentDirectoryPrefix;
      }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:14,代码来源:DirectoryInfo.cs


示例4: Delete

 public static void Delete(KernelTransaction transaction, string path)
 {
    DeleteFileInternal(transaction, path, false, PathFormat.RelativePath);
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:4,代码来源:File.Delete.cs


示例5: GetDirectoryNameWithoutRoot

      public static string GetDirectoryNameWithoutRoot(KernelTransaction transaction, string path)
      {
         if (path == null)
            return null;

         DirectoryInfo di = Directory.GetParentInternal(transaction, path, PathFormat.RelativePath);
         return di != null && di.Parent != null ? di.Name : null;
      }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:8,代码来源:Path.GetComponents.cs


示例6: ReadAllText

 public static string ReadAllText(KernelTransaction transaction, string path)
 {
    return ReadAllTextInternal(transaction, path, NativeMethods.DefaultFileEncoding, PathFormat.RelativePath);
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:4,代码来源:File.ReadAllText.cs


示例7: CountFileSystemObjects

 public static long CountFileSystemObjects(KernelTransaction transaction, string path, string searchPattern, DirectoryEnumerationOptions options, PathFormat pathFormat)
 {
    return EnumerateFileSystemEntryInfosInternal<string>(transaction, path, searchPattern, options, pathFormat).Count();
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:4,代码来源:Directory.CountFileSystemObjects.cs


示例8: ReadAllLines

 public static string[] ReadAllLines(KernelTransaction transaction, string path, Encoding encoding)
 {
    return ReadAllLinesInternal(transaction, path, encoding, PathFormat.RelativePath).ToArray();
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:4,代码来源:File.ReadAllLines.cs


示例9: ReadAllLinesInternal

 internal static IEnumerable<string> ReadAllLinesInternal(KernelTransaction transaction, string path, Encoding encoding, PathFormat pathFormat)
 {
    using (StreamReader sr = new StreamReader(OpenInternal(transaction, path, FileMode.Open, 0, FileAccess.Read, FileShare.Read, ExtendedFileAttributes.SequentialScan, pathFormat), encoding))
    {
       string line;
       while ((line = sr.ReadLine()) != null)
          yield return line;
    }
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:9,代码来源:File.ReadAllLines.cs


示例10: GetLinkTargetInfo

 public static LinkTargetInfo GetLinkTargetInfo(KernelTransaction transaction, string path)
 {
    return GetLinkTargetInfoInternal(transaction, path, PathFormat.RelativePath);
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:4,代码来源:File.GetLinkTargetInfo.cs


示例11: GetChangeTime

 public static DateTime GetChangeTime(KernelTransaction transaction, string path)
 {
    return GetChangeTimeInternal(false, transaction, null, path, false, PathFormat.RelativePath);
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:4,代码来源:File.GetChangeTime.cs


示例12: GetChangeTimeInternal

      internal static DateTime GetChangeTimeInternal(bool isFolder, KernelTransaction transaction, SafeFileHandle safeHandle, string path, bool getUtc, PathFormat pathFormat)
      {
         if (!NativeMethods.IsAtLeastWindowsVista)
            throw new PlatformNotSupportedException(Resources.RequiresWindowsVistaOrHigher);

         bool callerHandle = safeHandle != null;
         if (!callerHandle)
         {
            if (pathFormat != PathFormat.LongFullPath && Utils.IsNullOrWhiteSpace(path))
               throw new ArgumentNullException("path");

            string pathLp = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.CheckInvalidPathChars);

            safeHandle = CreateFileInternal(transaction, pathLp, isFolder ? ExtendedFileAttributes.BackupSemantics : ExtendedFileAttributes.Normal, null, FileMode.Open, FileSystemRights.ReadData, FileShare.ReadWrite, true, PathFormat.LongFullPath);
         }


         try
         {
            NativeMethods.IsValidHandle(safeHandle);
            
            using (var safeBuffer = new SafeGlobalMemoryBufferHandle(IntPtr.Size + Marshal.SizeOf(typeof(NativeMethods.FileBasicInfo))))
            {
               NativeMethods.FileBasicInfo fbi;

               if (!NativeMethods.GetFileInformationByHandleEx_FileBasicInfo(safeHandle, NativeMethods.FileInfoByHandleClass.FileBasicInfo, out fbi, (uint)safeBuffer.Capacity))
                  NativeError.ThrowException(Marshal.GetLastWin32Error());

               safeBuffer.StructureToPtr(fbi, true);
               NativeMethods.FileTime changeTime = safeBuffer.PtrToStructure<NativeMethods.FileBasicInfo>().ChangeTime;

               return getUtc
                  ? DateTime.FromFileTimeUtc(changeTime)
                  : DateTime.FromFileTime(changeTime);
            }
         }
         finally
         {
            // Handle is ours, dispose.
            if (!callerHandle && safeHandle != null)
               safeHandle.Close();
         }
      }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:43,代码来源:File.GetChangeTime.cs


示例13: GetChangeTimeUtc

 public static DateTime GetChangeTimeUtc(KernelTransaction transaction, string path, PathFormat pathFormat)
 {
    return GetChangeTimeInternal(false, transaction, null, path, true, pathFormat);
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:4,代码来源:File.GetChangeTime.cs


示例14: GetSizeInternal

      internal static long GetSizeInternal(KernelTransaction transaction, SafeFileHandle safeHandle, string path, PathFormat pathFormat)
      {
         bool callerHandle = safeHandle != null;
         if (!callerHandle)
         {
            string pathLp = Path.GetExtendedLengthPathInternal(transaction, path, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck);

            safeHandle = CreateFileInternal(transaction, pathLp, ExtendedFileAttributes.None, null, FileMode.Open, FileSystemRights.ReadData, FileShare.Read, true, PathFormat.LongFullPath);
         }


         long fileSize;

         try
         {
            NativeMethods.GetFileSizeEx(safeHandle, out fileSize);
         }
         finally
         {
            // Handle is ours, dispose.
            if (!callerHandle && safeHandle != null)
               safeHandle.Close();
         }

         return fileSize;
      }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:26,代码来源:File.GetSize.cs


示例15: GetSize

 public static long GetSize(KernelTransaction transaction, string path)
 {
    return GetSizeInternal(transaction, null, path, PathFormat.RelativePath);
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:4,代码来源:File.GetSize.cs


示例16: Move

 public static void Move(KernelTransaction transaction, string sourceFileName, string destinationFileName, MoveOptions moveOptions, PathFormat pathFormat)
 {
    CopyMoveInternal(false, transaction, sourceFileName, destinationFileName, false, null, moveOptions, null, null, pathFormat);
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:4,代码来源:File.CopyMove.cs


示例17: GetLinkTargetInfoInternal

 internal static LinkTargetInfo GetLinkTargetInfoInternal(KernelTransaction transaction, string path, PathFormat pathFormat)
 {
    using (SafeFileHandle safeHandle = CreateFileInternal(transaction, path, ExtendedFileAttributes.OpenReparsePoint | ExtendedFileAttributes.BackupSemantics, null, FileMode.Open, 0, FileShare.ReadWrite, true, pathFormat))
       return Device.GetLinkTargetInfoInternal(safeHandle);
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:5,代码来源:File.GetLinkTargetInfo.cs


示例18: CopyMoveInternal

      internal static CopyMoveResult CopyMoveInternal(bool isFolder, KernelTransaction transaction, string sourceFileName, string destinationFileName, bool preserveDates, CopyOptions? copyOptions, MoveOptions? moveOptions, CopyMoveProgressRoutine progressHandler, object userProgressData, PathFormat pathFormat)
      {
         #region Setup

         if (pathFormat == PathFormat.RelativePath)
         {
            Path.CheckValidPath(sourceFileName, true, true);
            Path.CheckValidPath(destinationFileName, true, true);
         }
         else
         {
            // MSDN:. NET 3.5+: NotSupportedException: Path contains a colon character (:) that is not part of a drive label ("C:\").
            Path.CheckValidPath(sourceFileName, false, false);
            Path.CheckValidPath(destinationFileName, false, false);
         }

         string sourceFileNameLp = Path.GetExtendedLengthPathInternal(transaction, sourceFileName, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator);
         string destFileNameLp = Path.GetExtendedLengthPathInternal(transaction, destinationFileName, pathFormat, GetFullPathOptions.RemoveTrailingDirectorySeparator);


         // MSDN: If this flag is set to TRUE during the copy/move operation, the operation is canceled.
         // Otherwise, the copy/move operation will continue to completion.
         bool cancel = false;

         // Determine Copy or Move action.
         bool doCopy = copyOptions != null;
         bool doMove = !doCopy && moveOptions != null;

         if ((!doCopy && !doMove) || (doCopy && doMove))
            throw new NotSupportedException(Resources.UndeterminedCopyMoveAction);

         bool overwrite = doCopy
            ? (((CopyOptions) copyOptions & CopyOptions.FailIfExists) != CopyOptions.FailIfExists)
            : (((MoveOptions) moveOptions & MoveOptions.ReplaceExisting) == MoveOptions.ReplaceExisting);

         bool raiseException = progressHandler == null;

         // Setup callback function for progress notifications.
         var routine = (progressHandler != null)
            ? (totalFileSize, totalBytesTransferred, streamSize, streamBytesTransferred, dwStreamNumber, dwCallbackReason, hSourceFile, hDestinationFile, lpData)
               =>
               progressHandler(totalFileSize, totalBytesTransferred, streamSize, streamBytesTransferred, dwStreamNumber, dwCallbackReason, userProgressData)
            : (NativeMethods.NativeCopyMoveProgressRoutine) null;

         #endregion //Setup

         startCopyMove:

         uint lastError = Win32Errors.ERROR_SUCCESS;

         #region Win32 Copy/Move

         if (!(transaction == null || !NativeMethods.IsAtLeastWindowsVista
            ? doMove
               // MoveFileWithProgress() / MoveFileTransacted()
               // In the ANSI version of this function, the name is limited to MAX_PATH characters.
               // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
               // 2013-04-15: MSDN confirms LongPath usage.

               // CopyFileEx() / CopyFileTransacted()
               // In the ANSI version of this function, the name is limited to MAX_PATH characters.
               // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
               // 2013-04-15: MSDN confirms LongPath usage.

               ? NativeMethods.MoveFileWithProgress(sourceFileNameLp, destFileNameLp, routine, IntPtr.Zero, (MoveOptions) moveOptions)
               : NativeMethods.CopyFileEx(sourceFileNameLp, destFileNameLp, routine, IntPtr.Zero, out cancel, (CopyOptions) copyOptions)

            : doMove
               ? NativeMethods.MoveFileTransacted(sourceFileNameLp, destFileNameLp, routine, IntPtr.Zero, (MoveOptions) moveOptions, transaction.SafeHandle)
               : NativeMethods.CopyFileTransacted(sourceFileNameLp, destFileNameLp, routine, IntPtr.Zero, out cancel, (CopyOptions) copyOptions, transaction.SafeHandle)))
         {
            lastError = (uint) Marshal.GetLastWin32Error();

            if (lastError == Win32Errors.ERROR_REQUEST_ABORTED)
            {
               // If lpProgressRoutine returns PROGRESS_CANCEL due to the user canceling the operation,
               // CopyFileEx will return zero and GetLastError will return ERROR_REQUEST_ABORTED.
               // In this case, the partially copied destination file is deleted.
               //
               // If lpProgressRoutine returns PROGRESS_STOP due to the user stopping the operation,
               // CopyFileEx will return zero and GetLastError will return ERROR_REQUEST_ABORTED.
               // In this case, the partially copied destination file is left intact.

               cancel = true;
            }

            else if (raiseException)
            {
               #region Win32Errors

               switch (lastError)
               {
                  case Win32Errors.ERROR_FILE_NOT_FOUND:
                     // File.Copy()
                     // File.Move()
                     // MSDN: .NET 3.5+: FileNotFoundException: sourceFileName was not found. 
                     NativeError.ThrowException(lastError, sourceFileNameLp);
                     break;

                  case Win32Errors.ERROR_PATH_NOT_FOUND:
//.........这里部分代码省略.........
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:101,代码来源:File.CopyMove.cs


示例19: Copy

 public static void Copy(KernelTransaction transaction, string sourceFileName, string destinationFileName, bool overwrite, PathFormat pathFormat)
 {
    CopyMoveInternal(false, transaction, sourceFileName, destinationFileName, false, overwrite ? CopyOptions.None : CopyOptions.FailIfExists, null, null, null, pathFormat);
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:4,代码来源:File.CopyMove.cs


示例20: ReadAllTextInternal

 internal static string ReadAllTextInternal(KernelTransaction transaction, string path, Encoding encoding, PathFormat pathFormat)
 {
    using (StreamReader sr = new StreamReader(OpenInternal(transaction, path, FileMode.Open, 0, FileAccess.Read, FileShare.Read, ExtendedFileAttributes.SequentialScan, pathFormat), encoding))
       return sr.ReadToEnd();
 }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:5,代码来源:File.ReadAllText.cs



注:本文中的Alphaleonis.Win32.Filesystem.KernelTransaction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Calc.ComplexFloat类代码示例发布时间:2022-05-24
下一篇:
C# Model.Track类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap