Beispiel #1
0
 public FileNameEventArgs(string fileName)
 {
     this.fileName = FileName.Create(fileName);
 }
Beispiel #2
0
 public static FileOperationResult ObservedLoad(NamedFileOperationDelegate saveFileAs, FileName fileName, FileErrorPolicy policy = FileErrorPolicy.Inform)
 {
     return(ObservedLoad(saveFileAs,
                         fileName,
                         ResourceService.GetString("ICSharpCode.Services.FileUtilityService.CantLoadFileStandardText"),
                         policy));
 }
Beispiel #3
0
 public FileNameEventArgs(FileName fileName)
 {
     this.fileName = fileName;
 }
Beispiel #4
0
 public static FileOperationResult ObservedLoad(NamedFileOperationDelegate saveFileAs, FileName fileName, string message, FileErrorPolicy policy = FileErrorPolicy.Inform)
 {
     return(ObservedLoad(new FileOperationDelegate(delegate { saveFileAs(fileName); }), fileName, message, policy));
 }
Beispiel #5
0
        static FileOperationResult ObservedLoadHandleException(Exception e, FileOperationDelegate loadFile, FileName fileName, string message, FileErrorPolicy policy)
        {
            message = message + Environment.NewLine + Environment.NewLine + e.Message;
            var messageService = ServiceSingleton.GetRequiredService <IMessageService>();

            switch (policy)
            {
            case FileErrorPolicy.Inform:
                messageService.InformSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileLoading}", e);
                break;

            case FileErrorPolicy.ProvideAlternative:
                ChooseSaveErrorResult r = messageService.ChooseSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileLoading}", e, false);
                if (r.IsRetry)
                {
                    return(ObservedLoad(loadFile, fileName, message, policy));
                }
                else if (r.IsIgnore)
                {
                    return(FileOperationResult.Failed);
                }
                break;
            }
            return(FileOperationResult.Failed);
        }
Beispiel #6
0
 // Observe LOAD functions
 public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, FileName fileName, string message, FileErrorPolicy policy)
 {
     try
     {
         loadFile();
         OnFileLoaded(new FileNameEventArgs(fileName));
         return(FileOperationResult.OK);
     }
     catch (IOException e)
     {
         return(ObservedLoadHandleException(e, loadFile, fileName, message, policy));
     }
     catch (UnauthorizedAccessException e)
     {
         return(ObservedLoadHandleException(e, loadFile, fileName, message, policy));
     }
     catch (FormatException e)
     {
         return(ObservedLoadHandleException(e, loadFile, fileName, message, policy));
     }
 }
Beispiel #7
0
 public static FileOperationResult ObservedSave(NamedFileOperationDelegate saveFileAs, FileName fileName, string message, FileErrorPolicy policy = FileErrorPolicy.Inform)
 {
     System.Diagnostics.Debug.Assert(IsValidPath(fileName));
     try
     {
         Directory.CreateDirectory(fileName.GetParentDirectory());
         saveFileAs(fileName);
         RaiseFileSaved(new FileNameEventArgs(fileName));
         return(FileOperationResult.OK);
     }
     catch (IOException e)
     {
         return(ObservedSaveHandleError(e, saveFileAs, fileName, message, policy));
     }
     catch (UnauthorizedAccessException e)
     {
         return(ObservedSaveHandleError(e, saveFileAs, fileName, message, policy));
     }
 }
Beispiel #8
0
 public static bool IsEqualFileName(FileName fileName1, FileName fileName2)
 {
     return(fileName1 == fileName2);
 }