Ejemplo n.º 1
0
        private FileStream Open(string path, FileMode mode, FileAccess access, FileShare share)
        {
            // Future: Support System.IO.FileOptions which is the dwFlagsAndAttribute parameter.
            var fileHandle = NativeMethods.CreateFileTransactedW(path,
                                                                 access.ToNative(),
                                                                 share.ToNative(),
                                                                 IntPtr.Zero,
                                                                 mode.ToNative(),
                                                                 0, IntPtr.Zero,
                                                                 _TransactionHandle,
                                                                 IntPtr.Zero, IntPtr.Zero);
            var error = Marshal.GetLastWin32Error();

            if (fileHandle.IsInvalid)
            {
                var baseStr = string.Format("Transaction \"{1}\": Unable to open a file descriptor to \"{0}\".", path,
                                            Name ?? "[no name]");

                if (error == TxFCodes.ERROR_TRANSACTIONAL_CONFLICT)
                {
                    throw new TransactionalConflictException(baseStr
                                                             +
                                                             " You will get this error if you are accessing the transacted file from a non-transacted API before the transaction has "
                                                             + "committed. See HelperLink for details.",
                                                             new Uri("http://msdn.microsoft.com/en-us/library/aa365536%28VS.85%29.aspx"));
                }

                throw new TransactionException(baseStr + "Please see the inner exceptions for details.",
                                               LastEx());
            }

            return(new FileStream(fileHandle, access));
        }
Ejemplo n.º 2
0
        private static SafeFileHandle GetFileHandle(string normalizedPath, FileMode mode, FileAccess access, FileShare share,
                                                    FileOptions options)
        {
            var handle = NativeMethods.CreateFile(normalizedPath, access.ToNative(), share.ToNative(), IntPtr.Zero,
                                                  mode.ToNative(),
                                                  options.ToNative(), IntPtr.Zero);

            if (handle.IsInvalid)
            {
                throw LongPathCommon.GetExceptionFromLastWin32Error();
            }

            return(handle);
        }
Ejemplo n.º 3
0
		private FileStream Open(string path, FileMode mode, FileAccess access, FileShare share)
		{
			// Future: Support System.IO.FileOptions which is the dwFlagsAndAttribute parameter.
			var fileHandle = NativeMethods.CreateFileTransactedW(path,
			                                                     access.ToNative(),
			                                                     share.ToNative(),
			                                                     IntPtr.Zero,
			                                                     mode.ToNative(),
			                                                     0, IntPtr.Zero,
			                                                     _TransactionHandle, 
			                                                     IntPtr.Zero, IntPtr.Zero);
			var error = Marshal.GetLastWin32Error();

			if (fileHandle.IsInvalid)
			{
				var baseStr = string.Format("Transaction \"{1}\": Unable to open a file descriptor to \"{0}\".", path,
				                            Name ?? "[no name]");

				if (error == TxFCodes.ERROR_TRANSACTIONAL_CONFLICT)
					throw new TransactionalConflictException(baseStr
					                                         +
					                                         " You will get this error if you are accessing the transacted file from a non-transacted API before the transaction has "
					                                         + "committed. See HelperLink for details.",
					                                         new Uri("http://msdn.microsoft.com/en-us/library/aa365536%28VS.85%29.aspx"));

				throw new TransactionException(baseStr + "Please see the inner exceptions for details.",
				                               LastEx());
			}

			return new FileStream(fileHandle, access);
		}
Ejemplo n.º 4
0
        private static SafeFileHandle GetFileHandle(string normalizedPath, FileMode mode, FileAccess access, FileShare share,
            FileOptions options)
        {
            var handle = NativeMethods.CreateFile(normalizedPath, access.ToNative(), share.ToNative(), IntPtr.Zero,
                                                  mode.ToNative(),
                                                  options.ToNative(), IntPtr.Zero);
            if (handle.IsInvalid)
                throw LongPathCommon.GetExceptionFromLastWin32Error();

            return handle;
        }