Ejemplo n.º 1
0
 /// <summary>
 /// Creates (but does not throw) an exception for this result. The result must not be successful.
 /// </summary>
 public static Exception CreateExceptionForError(this OpenFileResult result)
 {
     Contract.Requires(result.Status != OpenFileStatus.Success);
     return(result.Status == OpenFileStatus.UnknownError
         ? new NativeWin32Exception(result.NativeErrorCode, "Opening a file handle failed")
         : new NativeWin32Exception(result.NativeErrorCode, I($"Opening a file handle failed: {result.Status:G}")));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="Failure"/> representing this result. The result must not be successful.
        /// </summary>
        public static Failure CreateFailureForError(this OpenFileResult result)
        {
            Contract.Requires(result.Status != OpenFileStatus.Success);

            return
                (new NativeFailure(result.NativeErrorCode).Annotate(
                     result.Status == OpenFileStatus.UnknownError ? "Opening a file handle failed" : I($"Opening a file handle failed: {result.Status:G}")));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a string representing information about the <see cref="OpenFileResult"/> error.
        /// </summary>
        private static string GetErrorOrFailureMessage(OpenFileResult result)
        {
            var message = result.Status == OpenFileStatus.UnknownError
                            ? "Opening a file handle failed"
                            : I($"Opening a file handle failed: {result.Status:G}");

            if (result.ImpliesOtherProcessBlockingHandle && result.Path != null)
            {
                message += Environment.NewLine;
                message += FileUtilities.TryFindOpenHandlesToFile(result.Path, out var info)
                    ? info
                    : "Attempt to find processes with open handles to the file failed.";
            }

            return(message);
        }
Ejemplo n.º 4
0
 /// <see cref="IFileSystem.TryPosixDelete(string, out OpenFileResult)"/>
 public static unsafe bool TryPosixDelete(string pathToDelete, out OpenFileResult openFileResult)
 {
     return(s_fileSystem.TryPosixDelete(pathToDelete, out openFileResult));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a <see cref="Failure"/> representing this result. The result must not be successful.
 /// </summary>
 public static Failure CreateFailureForError(this OpenFileResult result)
 {
     Contract.Requires(result.Status != OpenFileStatus.Success);
     return(new NativeFailure(result.NativeErrorCode).Annotate(GetErrorOrFailureMessage(result)));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates (but does not throw) an exception for this result. The result must not be successful.
 /// </summary>
 public static Exception CreateExceptionForError(this OpenFileResult result)
 {
     Contract.Requires(result.Status != OpenFileStatus.Success);
     return(new NativeWin32Exception(result.NativeErrorCode, GetErrorOrFailureMessage(result)));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Throws an exception for a failed open.
 /// </summary>
 public static Exception ThrowForError(this OpenFileResult result)
 {
     Contract.Requires(result.Status != OpenFileStatus.Success);
     throw result.Status == OpenFileStatus.UnknownError ? result.ThrowForUnknownError() : result.ThrowForKnownError();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Throws an exception if the native error code could not be canonicalized (a fairly exceptional circumstance).
 /// </summary>
 /// <remarks>
 /// This is a good <c>default:</c> case when switching on every possible <see cref="OpenFileStatus"/>
 /// </remarks>
 public static Exception ThrowForUnknownError(this OpenFileResult result)
 {
     Contract.Requires(result.Status == OpenFileStatus.UnknownError);
     throw result.CreateExceptionForError();
 }