예제 #1
0
 /// <summary>
 /// Handles any errors that CreateDirectoryEx may encounter
 /// </summary>
 private static void HandleCreateDirectoryExError(string template, string target, int errorCode)
 {
     Win32Exception win32Exception = new Win32Exception(errorCode);
     Exception error;
     switch ((Win32Error)errorCode)
     {
         case Win32Error.ACCESS_DENIED:
             error = new UnauthorizedAccessException(
                 string.Format("Access was denied to clone '{0}' to '{1}'.", template, target),
                 win32Exception);
             break;
         case Win32Error.PATH_NOT_FOUND:
             error = new DirectoryNotFoundException(
                 string.Format("The path '{0}' or '{1}' could not be found.", template, target),
                 win32Exception);
             break;
         case Win32Error.SHARING_VIOLATION:
             error = new SharingViolationException(
                 string.Format("The source or destination file was in use when copying '{0}' to '{1}'.", template, target),
                 win32Exception);
             break;
         case Win32Error.ALREADY_EXISTS:
             //If the directory already exists don't worry about it.
             return;
         default:
             error = win32Exception;
             break;
     }
     throw error;
 }
예제 #2
0
 /// <summary>
 /// Handles any errors returned from CopyEx
 /// </summary>
 private static void HandleCopyExError(string source, string destination, int errorCode)
 {
     Win32Exception win32Exception = new Win32Exception(errorCode);
     Exception error;
     switch ((Win32Error)errorCode)
     {
         case Win32Error.ACCESS_DENIED:
             error = new UnauthorizedAccessException(
                 string.Format("Access was denied to copy '{0}' to '{1}'.", source, destination),
                 win32Exception);
             break;
         case Win32Error.FILE_NOT_FOUND | Win32Error.PATH_NOT_FOUND:
             error = new FileNotFoundException(
                 string.Format("The file '{0}' could not be found.", source),
                 source,
                 win32Exception);
             break;
         case Win32Error.SHARING_VIOLATION:
             error = new SharingViolationException(
                 string.Format("The source or destination file was in use when copying '{0}' to '{1}'.", source, destination),
                 win32Exception);
             break;
         case Win32Error.DISK_FULL | Win32Error.HANDLE_DISK_FULL:
             error = new DiskFullException(
                 string.Format("The destination disk for '{0}' is full.", destination),
                 win32Exception);
             break;
         case Win32Error.REQUEST_ABORTED:
             return;
         default:
             error = win32Exception;
             break;
     }
     throw error;
 }