internal static extern bool MoveFileTransacted( [In, MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName , [In, MarshalAs(UnmanagedType.LPWStr)] string lpNewFileName , [In] IntPtr lpProgressRoutine , [In] IntPtr lpData , [In] MoveFileFlags dwFlags , [In] KtmTransactionHandle hTransaction);
/// <summary> /// Create and begin new local KTM transaction (no DTC) /// </summary> /// <returns> /// New <see cref="KtmTransaction" /> instance representing newly started transaction. /// </returns> public static KtmTransaction BeginLocal() { _log.Debug("Starting local standalone KTM transaction"); KtmTransaction retval = new KtmTransaction(KtmTransactionHandle.CreateLocalTransaction(), null); Check.DoEnsure(retval.IsHandleValid, "KtmTransaction failed to initialise"); return(retval); }
internal static extern FindFileHandle FindFirstFileTransacted( [In] string lpDirSpec , [In] WindowsNative.FINDEX_INFO_LEVELS fInfoLevelId , [Out] out WIN32_FIND_DATA lpFindFileData , [In] WindowsNative.FINDEX_SEARCH_OPS fSearchOp , [In] IntPtr lpSearchFilter , [In] int dwAdditionalFlags , [In] KtmTransactionHandle hTransaction);
internal static extern bool CopyFileTransacted( [In] string lpExistingFileName , [In] string lpNewFileName , [In] IntPtr lpProgressRoutine , [In] IntPtr lpData , [In, MarshalAs(UnmanagedType.Bool)] ref bool pbCancel , [In] CopyFileFlags dwCopyFlags , [In] KtmTransactionHandle hTransaction);
/// <summary> /// Get KTM transaction from ambient managed transaction (<see cref="Transaction.Current" />) /// </summary> /// <remarks> /// Currently this will require MS DTC service running. The created transaction should not be committed /// or rolled back itself explicitly. Use the owning managed transaction to control it. /// http://msdn.microsoft.com/en-us/library/cc303707.aspx /// </remarks> public static KtmTransactionHandle GetFromAmbientTransaction() { if (Transaction.Current == null) { throw new InvalidOperationException("Cannot create a KTM handle without Transaction.Current"); } return(KtmTransactionHandle.GetFromManaged(Transaction.Current)); }
internal static extern SafeFileHandle CreateFileTransacted( [In, MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [In] WindowsNative.FileAccess dwDesiredAccess, [In] WindowsNative.FileShare dwShareMode, [In] IntPtr lpSecurityAttributes, [In] WindowsNative.FileMode dwCreationDisposition, [In] EFileAttributes dwFlagsAndAttributes, [In] IntPtr hTemplateFile, [In] KtmTransactionHandle hTransaction, [In] IntPtr pusMiniVersion, [In] IntPtr pExtendedParameter);
/// <summary> /// Create new instance. /// </summary> /// <param name="handle"> /// Transaction handle /// </param> /// <param name="masterTransaction"> /// Managed /// </param> /// <remarks> /// The only constructor ensures that the KTM transaction instance is subscribed exactly once to the /// owning transaction completion if owning transaction is specified. /// </remarks> protected KtmTransaction(KtmTransactionHandle handle, Transaction masterTransaction) { Check.DoRequireArgumentNotNull(handle, "handle"); Check.DoAssertLambda(!handle.IsClosed && !handle.IsInvalid , () => new ArgumentException("Transactin handle does not represent an active transaction.")); Check.DoAssertLambda( masterTransaction == null || masterTransaction.TransactionInformation.Status == TransactionStatus.Active , () => new ArgumentException("Owning managed transaction is not active.")); _ktmHandle = handle; MasterTransaction = masterTransaction; _status = TransactionStatus.Active; Check.Ensure(IsHandleValid); }
private static SafeFileHandle GetFileHandle(LongPath path, FileMode mode, FileAccess access, FileShare share, FileOptions options) { SafeFileHandle handle; if (KtmTransaction.IsInTransaction) { WindowsNative.FileMode internalMode = WindowsNative.TranslateFileMode(mode); WindowsNative.FileShare internalShare = WindowsNative.TranslateFileShare(share); WindowsNative.FileAccess internalAccess = WindowsNative.TranslateFileAccess(access); KtmTransactionHandle ktmTx = KtmTransaction.Current.Hanlde; // Create the transacted file using P/Invoke. handle = WindowsNative.CreateFileTransacted( path.PathString, internalAccess, internalShare, IntPtr.Zero, internalMode, WindowsNative.EFileAttributes.Normal, IntPtr.Zero, KtmTransaction.Current.Hanlde, IntPtr.Zero, IntPtr.Zero); } else { WindowsNative.EFileAccess underlyingAccess = WindowsNative.GetUnderlyingAccess(access); handle = WindowsNative.CreateFile(path.PathString, underlyingAccess, (uint)share, IntPtr.Zero, (uint)mode, (uint)options, IntPtr.Zero); } if (handle.IsInvalid) { WindowsNative.HandleWindowsError(); } return(handle); }
/// <summary> /// Get KtmTransaction from managed transaction /// </summary> /// <param name="managedTransaction"> /// Owning managed transaction. /// </param> /// <returns> /// <see cref="KtmTransaction" /> participating in <paramref name="managedTransaction" /> /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="managedTransaction" /> is <see langword="null"/> /// </exception> public static KtmTransaction Get(Transaction managedTransaction) { _log.Debug("Getting KTM transaction from managed"); Check.DoRequireArgumentNotNull(managedTransaction, "managedTransaction"); return(new KtmTransaction(KtmTransactionHandle.GetFromManaged(managedTransaction), managedTransaction)); }
internal static extern bool RollbackTransaction(KtmTransactionHandle transaction);
internal static extern bool CommitTransaction(KtmTransactionHandle transaction);
internal static extern bool GetFileAttributesTransacted( [In] string lpFileName , [In] GET_FILEEX_INFO_LEVELS fInfoLevelId , [Out] out WIN32_FILE_ATTRIBUTE_DATA attributes , [In] KtmTransactionHandle hTransaction);
internal static extern bool RemoveDirectoryTransacted( [In, MarshalAs(UnmanagedType.LPWStr)] string lpPathName , [In] KtmTransactionHandle transaction);
internal static extern bool DeleteFileTransacted( [In, MarshalAs(UnmanagedType.LPWStr)] string file , [In] KtmTransactionHandle transaction);
internal static extern bool CreateDirectoryTransacted( [In, MarshalAs(UnmanagedType.LPWStr)] string lpTemplateDirectory, [In, MarshalAs(UnmanagedType.LPWStr)] string lpNewDirectory, [In] IntPtr lpSecurityAttributes, [In] KtmTransactionHandle hTransaction);