public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, FileName fileName, FileErrorPolicy policy = FileErrorPolicy.Inform) { return(ObservedLoad(loadFile, fileName, ResourceService.GetString("ICSharpCode.Services.FileUtilityService.CantLoadFileStandardText"), policy)); }
public FileOperationResult ObservedLoad(NamedFileOperationDelegate loadNamedFileDelegate, string fileName, string message, FileErrorPolicy policy) { LoadWrapper loadWrapper = new LoadWrapper(loadNamedFileDelegate, fileName); FileOperationDelegate fileOperationDelegate = new FileOperationDelegate(loadWrapper.Invoke); return(ObservedLoad(fileOperationDelegate, fileName, message, policy)); }
public static FileOperationResult ObservedSave(FileOperationDelegate saveFile, FileName fileName, FileErrorPolicy policy = FileErrorPolicy.Inform) { return(ObservedSave(saveFile, fileName, Current.ResourceService.GetString("ICSharpCode.Services.FileUtilityService.CantSaveFileStandardText"), policy)); }
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); }
public static FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName, FileErrorPolicy policy) { return(ObservedSave(saveFile, fileName, ResourceService.GetString("FanHai.Gui.Framework.Services.FileUtilityService.CantSaveFileStandardText"), policy)); }
// Observe LOAD functions public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string fileName, string message, FileErrorPolicy policy) { try { loadFile(); OnFileLoaded(new FileNameEventArgs(fileName)); return(FileOperationResult.OK); } catch (Exception e) { switch (policy) { case FileErrorPolicy.Inform: using (SaveErrorInformDialog informDialog = new SaveErrorInformDialog(fileName, message, "${res:FileUtilityService.ErrorWhileLoading}", e)) { informDialog.ShowDialog(); } break; case FileErrorPolicy.ProvideAlternative: using (SaveErrorChooseDialog chooseDialog = new SaveErrorChooseDialog(fileName, message, "${res:FileUtilityService.ErrorWhileLoading}", e, false)) { switch (chooseDialog.ShowDialog()) { case DialogResult.OK: // choose location (never happens here) break; case DialogResult.Retry: return(ObservedLoad(loadFile, fileName, message, policy)); case DialogResult.Ignore: return(FileOperationResult.Failed); } } break; } } return(FileOperationResult.Failed); }
// Observe SAVE functions public static FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName, string message, FileErrorPolicy policy) { System.Diagnostics.Debug.Assert(IsValidPath(fileName)); try { saveFile(); OnFileSaved(new FileNameEventArgs(fileName)); return(FileOperationResult.OK); } catch (Exception e) { switch (policy) { case FileErrorPolicy.Inform: ServiceManager.MessageService.InformSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e); break; case FileErrorPolicy.ProvideAlternative: ChooseSaveErrorResult r = ServiceManager.MessageService.ChooseSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e, false); if (r.IsRetry) { return(ObservedSave(saveFile, fileName, message, policy)); } else if (r.IsIgnore) { return(FileOperationResult.Failed); } break; } } return(FileOperationResult.Failed); }
// Observe LOAD functions public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string fileName, string message, FileErrorPolicy policy) { try { loadFile(); OnFileLoaded(new FileNameEventArgs(fileName)); return(FileOperationResult.OK); } catch (Exception e) { switch (policy) { case FileErrorPolicy.Inform: ServiceManager.MessageService.InformSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileLoading}", e); break; case FileErrorPolicy.ProvideAlternative: ChooseSaveErrorResult r = ServiceManager.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); }
public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string fileName, FileErrorPolicy policy) { return(ObservedLoad(loadFile, fileName, ResourceService.GetString("Libra.Services.FileUtilityService.CantLoadFileStandardText"), policy)); }
public void RequestOplockAndOperateFileRequest( RequestedOplockLevel_Values requestedOplockLevel, OplockFileOperation fileOperation, out OplockLevel_Values grantedOplockLevel, out OplockConfig c) { Smb2CreateContextResponse[] serverCreateContexts; string fileName = GetTestFileName(uncSharePath); OplockLevel_Values grantedTmp = OplockLevel_Values.OPLOCK_LEVEL_NONE; testClient.Create( treeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out fileId, out serverCreateContexts, requestedOplockLevel_Values: requestedOplockLevel, checker: (header, response) => { grantedTmp = response.OplockLevel; }); Site.Log.Add(LogEntryKind.Debug, "OplockLevel granted by server: {0}", grantedTmp); grantedOplockLevel = grantedTmp; c = oplockConfig; oplockLevelOnOpen = grantedTmp; fileOperationInvoker = new FileOperationDelegate(FileOperation); var task = Task.Run(() => fileOperationInvoker.Invoke(fileOperation, fileName)); task.Wait(500);// Assume that notification will arrive in .5 sec if there's any }
public FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName, FileErrorPolicy policy) { return(ObservedSave(saveFile, fileName, resourceService.GetString("NetFocus.Services.FileUtilityService.CantSaveFileStandardText"), policy)); }
/// <summary> /// /// </summary> /// <param name="operation">The operation.</param> /// <param name="types">The types.</param> /// <param name="defaultTypeIndex">zero-based filter index</param> /// <param name="title">The title.</param> /// <returns></returns> public OperationResult SafeOpen(FileOperationDelegate operation, FileType[] types, int defaultTypeIndex, string title) { FileType[] fileTypes = null; string filter = FileType.CombineFilters(out fileTypes, types); if ((fileTypes == null) || (fileTypes.Length == 0)) { fileTypes = new FileType[] { FileType.ALL }; filter = FileType.ALL.Filter; } if (defaultTypeIndex >= fileTypes.Length) { defaultTypeIndex = 0; } OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = filter; ofd.FilterIndex = defaultTypeIndex + 1; // FilterIndex est basé sur 1 ofd.Title = title; ofd.SupportMultiDottedExtensions = true; ofd.RestoreDirectory = true; ofd.Multiselect = false; DialogResult result = ShowDialog(ofd); if (result == DialogResult.OK) { int typeIndex = ofd.FilterIndex - 1; // FilterIndex est basé sur 1 FileType selectedFileType = FileType.UNKNOWN; if (typeIndex < fileTypes.Length) { selectedFileType = types[typeIndex]; } try { operation(ofd.FileName, selectedFileType); return(OperationResult.OK); } catch (Exception ex) { LogError(ex); return(OperationResult.Failed); } } else { return(OperationResult.Cancelled); } }
// Observe LOAD functions public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string 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)); } }
// Observe SAVE functions public static FileOperationResult ObservedSave(FileOperationDelegate saveFile, FileName fileName, string message, FileErrorPolicy policy = FileErrorPolicy.Inform) { System.Diagnostics.Debug.Assert(IsValidPath(fileName)); try { saveFile(); RaiseFileSaved(new FileNameEventArgs(fileName)); return(FileOperationResult.OK); } catch (IOException e) { return(ObservedSaveHandleException(e, saveFile, fileName, message, policy)); } catch (UnauthorizedAccessException e) { return(ObservedSaveHandleException(e, saveFile, fileName, message, policy)); } }
/// <summary> /// /// </summary> /// <param name="operation">The operation.</param> /// <param name="types">The types.</param> /// <param name="defaultTypeIndex">zero-based filter index</param> /// <param name="title">The title.</param> /// <returns></returns> public OperationResult SafeOpen(FileOperationDelegate operation, FileType[] types, int defaultTypeIndex, string title) { FileType[] fileTypes = null; string filter = FileType.CombineFilters(out fileTypes, types); if ((fileTypes == null) || (fileTypes.Length == 0)) { fileTypes = new FileType[] { FileType.ALL }; filter = FileType.ALL.Filter; } if (defaultTypeIndex >= fileTypes.Length) defaultTypeIndex = 0; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = filter; ofd.FilterIndex = defaultTypeIndex + 1; // FilterIndex est basé sur 1 ofd.Title = title; ofd.SupportMultiDottedExtensions = true; ofd.RestoreDirectory = true; ofd.Multiselect = false; DialogResult result = ShowDialog(ofd); if (result == DialogResult.OK) { int typeIndex = ofd.FilterIndex - 1; // FilterIndex est basé sur 1 FileType selectedFileType = FileType.UNKNOWN; if (typeIndex < fileTypes.Length) selectedFileType = types[typeIndex]; try { operation(ofd.FileName, selectedFileType); return OperationResult.OK; } catch (Exception ex) { LogError(ex); return OperationResult.Failed; } } else return OperationResult.Cancelled; }
public FileOperationResult ObservedLoad(FileOperationDelegate loadFileDelegate, string fileName, string message, FileErrorPolicy policy) { Debug.Assert(IsValidFileName(fileName)); //Eventually do the load file action. try { loadFileDelegate(); //通过这个委托来真正最后调用实际的方法,所有的ObservedLoad方法 //无论是NamedFileOperation还是FileOperation最终都会通过这个委托来调用所对应的方�? return(FileOperationResult.OK); } catch (Exception e) { switch (policy) { case FileErrorPolicy.Inform: using (SaveErrorInformDialog informDialog = new SaveErrorInformDialog(fileName, message, "Error while loading", e)) { informDialog.ShowDialog(); } break; case FileErrorPolicy.ProvideAlternative: using (SaveErrorChooseDialog chooseDialog = new SaveErrorChooseDialog(fileName, message, "Error while loading", e, false)) { switch (chooseDialog.ShowDialog()) { case DialogResult.OK: // choose location (never happens here) break; case DialogResult.Retry: return(ObservedLoad(loadFileDelegate, fileName, message, policy)); case DialogResult.Ignore: return(FileOperationResult.Failed); } } break; } } return(FileOperationResult.Failed); }
//定义一些受保护的加载文件和保存文件的方�?具体执行的函数是通过委托实例来执行的. #region ObservedSaveOrLoad Methods public FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName, string message, FileErrorPolicy policy) { Debug.Assert(IsValidFileName(fileName)); try { saveFile(); return(FileOperationResult.OK); } catch (Exception e) { switch (policy) { case FileErrorPolicy.Inform: using (SaveErrorInformDialog informDialog = new SaveErrorInformDialog(fileName, message, "Error while saving", e)) { informDialog.ShowDialog(); } break; case FileErrorPolicy.ProvideAlternative: using (SaveErrorChooseDialog chooseDialog = new SaveErrorChooseDialog(fileName, message, "Error while saving", e, false)) { switch (chooseDialog.ShowDialog()) { case DialogResult.OK: // choose location (never happens here) break; case DialogResult.Retry: return(ObservedSave(saveFile, fileName, message, policy)); case DialogResult.Ignore: return(FileOperationResult.Failed); } } break; } } return(FileOperationResult.Failed); }
static FileOperationResult ObservedSaveHandleException(Exception e, FileOperationDelegate saveFile, string fileName, string message, FileErrorPolicy policy) { switch (policy) { case FileErrorPolicy.Inform: ServiceManager.Instance.MessageService.InformSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e); break; case FileErrorPolicy.ProvideAlternative: ChooseSaveErrorResult r = ServiceManager.Instance.MessageService.ChooseSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e, false); if (r.IsRetry) { return(ObservedSave(saveFile, fileName, message, policy)); } else if (r.IsIgnore) { return(FileOperationResult.Failed); } break; } return(FileOperationResult.Failed); }
private static FileOperationResult ObservedSaveHandleException(Exception e, FileOperationDelegate saveFile, FileName fileName, string message, FileErrorPolicy policy) { var messageService = Altaxo.Current.GetRequiredService <IMessageService>(); switch (policy) { case FileErrorPolicy.Inform: messageService.InformSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e); break; case FileErrorPolicy.ProvideAlternative: ChooseSaveErrorResult r = messageService.ChooseSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e, false); if (r.IsRetry) { return(ObservedSave(saveFile, fileName, message, policy)); } else if (r.IsIgnore) { return(FileOperationResult.Failed); } break; } return(FileOperationResult.Failed); }
public void RequestOplockAndOperateFileRequest( RequestedOplockLevel_Values requestedOplockLevel, OplockFileOperation fileOperation, out OplockLevel_Values grantedOplockLevel, out OplockConfig c) { Smb2CreateContextResponse[] serverCreateContexts; string fileName = "OplockMBT_" + Guid.NewGuid().ToString(); OplockLevel_Values grantedTmp = OplockLevel_Values.OPLOCK_LEVEL_NONE; testClient.Create( treeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out fileId, out serverCreateContexts, requestedOplockLevel_Values: requestedOplockLevel, checker: (header, response) => { grantedTmp = response.OplockLevel; }); Site.Log.Add(LogEntryKind.Debug, "OplockLevel granted by server: {0}", grantedTmp); grantedOplockLevel = grantedTmp; c = oplockConfig; oplockLevelOnOpen = grantedTmp; fileOperationInvoker = new FileOperationDelegate(FileOperation); fileOperationInvoker.BeginInvoke(fileOperation, fileName, null, null); // Assume that notification will arrive in .5 sec if there's any // Without such sleep, OplockBreakNotification would not be expected by SE Thread.Sleep(500); }
public OperationResult SafeSave(FileOperationDelegate operation, string filename, FileType[] types) { return SafeSave(operation, filename, types, 0); }
public OperationResult SafeSave(FileOperationDelegate operation, string filename, FileType[] types, int defaultTypeIndex) { return(SafeSave(operation, filename, types, defaultTypeIndex, "Save File As")); }
public FileOperationResult ObservedLoad(NamedFileOperationDelegate loadNamedFileDelegate, string fileName, string message, FileErrorPolicy policy) { LoadWrapper loadWrapper = new LoadWrapper(loadNamedFileDelegate, fileName); FileOperationDelegate fileOperationDelegate = new FileOperationDelegate(loadWrapper.Invoke); return ObservedLoad(fileOperationDelegate, fileName, message, policy); }
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; }
public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string fileName) { return ObservedLoad(loadFile, fileName, FileErrorPolicy.Inform); }
public static FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName, FileErrorPolicy policy) { return ObservedSave(saveFile, fileName, ResourceService.GetString("ICSharpCode.Services.FileUtilityService.CantSaveFileStandardText"), policy); }
// Observe LOAD functions public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string fileName, string message, FileErrorPolicy policy) { try { loadFile(); OnFileLoaded(new FileNameEventArgs(fileName)); return FileOperationResult.OK; } catch (Exception e) { switch (policy) { case FileErrorPolicy.Inform: ServiceManager.MessageService.InformSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileLoading}", e); break; case FileErrorPolicy.ProvideAlternative: ChooseSaveErrorResult r = ServiceManager.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; }
public FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName, FileErrorPolicy policy) { return ObservedSave(saveFile, fileName, GettextCatalog.GetString ("Unable to save file."), policy); }
public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string fileName, FileErrorPolicy policy = FileErrorPolicy.Inform) { return ObservedLoad(loadFile, fileName, ResourceService.GetString("ICSharpCode.Services.FileUtilityService.CantLoadFileStandardText"), policy); }
public OperationResult SafeSave(FileOperationDelegate operation, string filename) { return(SafeSave(operation, filename, new FileType[] { FileType.ALL })); }
public OperationResult SafeSave(FileOperationDelegate operation, string filename) { return SafeSave(operation, filename, new FileType[] { FileType.ALL }); }
public OperationResult SafeOpen(FileOperationDelegate operation, FileType[] types, int defaultTypeIndex) { return(SafeOpen(operation, types, defaultTypeIndex, "Open...")); }
public OperationResult SafeOpen(FileOperationDelegate operation, FileType[] types) { return(SafeOpen(operation, types, 0)); }
public OperationResult SafeOpen(FileOperationDelegate operation) { return(SafeOpen(operation, new FileType[] { FileType.ALL })); }
public static FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName, string message, FileErrorPolicy policy) { try { saveFile(); OnFileSaved(new FileNameEventArgs(fileName)); return FileOperationResult.OK; } catch (Exception exception) { switch (policy) { case FileErrorPolicy.Inform: using (SaveErrorInformDialog dialog = new SaveErrorInformDialog(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", exception)) { dialog.ShowDialog(); } goto Label_00C7; case FileErrorPolicy.ProvideAlternative: using (SaveErrorChooseDialog dialog2 = new SaveErrorChooseDialog(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", exception, false)) { switch (dialog2.ShowDialog()) { case DialogResult.OK: case DialogResult.Cancel: case DialogResult.Abort: goto Label_00C7; case DialogResult.Retry: return ObservedSave(saveFile, fileName, message, policy); case DialogResult.Ignore: return FileOperationResult.Failed; } } goto Label_00C7; } } Label_00C7: return FileOperationResult.Failed; }
// Observe SAVE functions public static FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName, string message, FileErrorPolicy policy) { System.Diagnostics.Debug.Assert(IsValidPath(fileName)); try { saveFile(); RaiseFileSaved(new FileNameEventArgs(fileName)); return FileOperationResult.OK; } catch (Exception e) { switch (policy) { case FileErrorPolicy.Inform: ServiceManager.MessageService.InformSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e); break; case FileErrorPolicy.ProvideAlternative: ChooseSaveErrorResult r = ServiceManager.MessageService.ChooseSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e, false); if (r.IsRetry) { return ObservedSave(saveFile, fileName, message, policy); } else if (r.IsIgnore) { return FileOperationResult.Failed; } break; } } return FileOperationResult.Failed; }
public OperationResult SafeOpen(FileOperationDelegate operation, FileType[] types, int defaultTypeIndex) { return SafeOpen(operation, types, defaultTypeIndex, "Open..."); }
public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string fileName, FileErrorPolicy policy) { return ObservedLoad(loadFile, fileName, ResourceService.GetString("ECBC.Services.FileUtil.CantLoadFileStandardText"), policy); }
public static FileOperationResult ObservedSave(FileOperationDelegate saveFile, FileName fileName, FileErrorPolicy policy = FileErrorPolicy.Inform) { return ObservedSave(saveFile, fileName, (string)LocalizeDictionary.Instance.GetLocalizedObject("BVEEditor", "StringResources", "Services_FileUtilities_CantSaveFileStandardText", LocalizeDictionary.CurrentCulture), policy); }
// Observe LOAD functions public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string fileName, string message, FileErrorPolicy policy) { try { loadFile(); OnFileLoaded(new FileNameEventArgs(fileName)); return FileOperationResult.OK; } catch (Exception e) { switch (policy) { case FileErrorPolicy.Inform: using (SaveErrorInformDialog informDialog = new SaveErrorInformDialog(fileName, message, "${res:FileUtilityService.ErrorWhileLoading}", e)) { informDialog.ShowDialog(); } break; case FileErrorPolicy.ProvideAlternative: using (SaveErrorChooseDialog chooseDialog = new SaveErrorChooseDialog(fileName, message, "${res:FileUtilityService.ErrorWhileLoading}", e, false)) { switch (chooseDialog.ShowDialog()) { case DialogResult.OK: // choose location (never happens here) break; case DialogResult.Retry: return ObservedLoad(loadFile, fileName, message, policy); case DialogResult.Ignore: return FileOperationResult.Failed; } } break; } } return FileOperationResult.Failed; }
public FileOperationResult ObservedLoad(FileOperationDelegate loadFileDelegate, string fileName, FileErrorPolicy policy) { string cantLoadFileStandardText = resourceService.GetString("NetFocus.Services.FileUtilityService.CantLoadFileStandardText"); return ObservedLoad(loadFileDelegate,fileName,cantLoadFileStandardText,policy); }
public void RequestOplockAndOperateFileRequest( RequestedOplockLevel_Values requestedOplockLevel, OplockFileOperation fileOperation, out OplockLevel_Values grantedOplockLevel, out OplockConfig c) { Smb2CreateContextResponse[] serverCreateContexts; string fileName = "OplockMBT_"+ Guid.NewGuid().ToString(); OplockLevel_Values grantedTmp = OplockLevel_Values.OPLOCK_LEVEL_NONE; testClient.Create( treeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out fileId, out serverCreateContexts, requestedOplockLevel_Values: requestedOplockLevel, checker: (header, response) => { grantedTmp = response.OplockLevel; }); Site.Log.Add(LogEntryKind.Debug, "OplockLevel granted by server: {0}", grantedTmp); grantedOplockLevel = grantedTmp; c = oplockConfig; oplockLevelOnOpen = grantedTmp; fileOperationInvoker = new FileOperationDelegate(FileOperation); fileOperationInvoker.BeginInvoke(fileOperation, fileName, null, null); // Assume that notification will arrive in .5 sec if there's any // Without such sleep, OplockBreakNotification would not be expected by SE Thread.Sleep(500); }
public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string fileName) { return(ObservedLoad(loadFile, fileName, FileErrorPolicy.Inform)); }
static FileOperationResult ObservedSaveHandleException(Exception e, FileOperationDelegate saveFile, FileName fileName, string message, FileErrorPolicy policy) { var messageService = ServiceSingleton.GetRequiredService<IMessageService>(); switch (policy) { case FileErrorPolicy.Inform: messageService.InformSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e); break; case FileErrorPolicy.ProvideAlternative: ChooseSaveErrorResult r = messageService.ChooseSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e, false); if (r.IsRetry) { return ObservedSave(saveFile, fileName, message, policy); } else if (r.IsIgnore) { return FileOperationResult.Failed; } break; } return FileOperationResult.Failed; }
// Observe LOAD functions public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string 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); } }
public static FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName) { return(ObservedSave(saveFile, fileName, FileErrorPolicy.Inform)); }
public OperationResult SafeSave(FileOperationDelegate operation, string filename, FileType[] types) { return(SafeSave(operation, filename, types, 0)); }
public FileOperationResult ObservedLoad(FileOperationDelegate loadFileDelegate, string fileName, string message, FileErrorPolicy policy) { Debug.Assert(IsValidFileName(fileName)); //Eventually do the load file action. try { loadFileDelegate();//通过这个委托来真正最后调用实际的方法,所有的ObservedLoad方法 //无论是NamedFileOperation还是FileOperation最终都会通过这个委托来调用所对应的方�? return FileOperationResult.OK; } catch (Exception e) { switch (policy) { case FileErrorPolicy.Inform: using (SaveErrorInformDialog informDialog = new SaveErrorInformDialog(fileName, message, "Error while loading", e)) { informDialog.ShowDialog(); } break; case FileErrorPolicy.ProvideAlternative: using (SaveErrorChooseDialog chooseDialog = new SaveErrorChooseDialog(fileName, message, "Error while loading", e, false)) { switch (chooseDialog.ShowDialog()) { case DialogResult.OK: // choose location (never happens here) break; case DialogResult.Retry: return ObservedLoad(loadFileDelegate, fileName, message, policy); case DialogResult.Ignore: return FileOperationResult.Failed; } } break; } } return FileOperationResult.Failed; }
public OperationResult SafeOpen(FileOperationDelegate operation, FileType[] types) { return SafeOpen(operation, types, 0); }
// Observe SAVE functions public static FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName, string message, FileErrorPolicy policy = FileErrorPolicy.Inform) { System.Diagnostics.Debug.Assert(IsValidPath(fileName)); try { saveFile(); RaiseFileSaved(new FileNameEventArgs(fileName)); return FileOperationResult.OK; } catch (IOException e) { return ObservedSaveHandleException(e, saveFile, fileName, message, policy); } catch (UnauthorizedAccessException e) { return ObservedSaveHandleException(e, saveFile, fileName, message, policy); } }
public OperationResult SafeOpen(FileOperationDelegate operation) { return SafeOpen(operation, new FileType[] { FileType.ALL }); }
static FileOperationResult ObservedLoadHandleException(Exception e, FileOperationDelegate loadFile, string fileName, string message, FileErrorPolicy policy) { switch (policy) { case FileErrorPolicy.Inform: ServiceManager.Instance.MessageService.InformSaveError(fileName, message, "${res:FileUtilityService.ErrorWhileLoading}", e); break; case FileErrorPolicy.ProvideAlternative: ChooseSaveErrorResult r = ServiceManager.Instance.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; }
public OperationResult SafeSave(FileOperationDelegate operation, string filename, FileType[] types, int defaultTypeIndex) { return SafeSave(operation, filename, types, defaultTypeIndex, "Save File As"); }
// Observe SAVE functions public FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName, string message, FileErrorPolicy policy) { Debug.Assert(IsValidFileName(fileName)); #if false try { saveFile(); return FileOperationResult.OK; } catch (Exception e) { switch (policy) { case FileErrorPolicy.Inform: using (SaveErrorInformDialog informDialog = new SaveErrorInformDialog(fileName, message, "Error while saving", e)) { informDialog.ShowDialog(); } break; case FileErrorPolicy.ProvideAlternative: using (SaveErrorChooseDialog chooseDialog = new SaveErrorChooseDialog(fileName, message, "Error while saving", e, false)) { switch (chooseDialog.ShowDialog()) { case DialogResult.OK: // choose location (never happens here) break; case DialogResult.Retry: return ObservedSave(saveFile, fileName, message, policy); case DialogResult.Ignore: return FileOperationResult.Failed; } } break; } } #else try { saveFile(); return FileOperationResult.OK; } catch (Exception e) { Console.WriteLine("Error while saving : " + e.ToString()); } #endif return FileOperationResult.Failed; }
public FileOperationResult ObservedLoad(FileOperationDelegate loadFileDelegate, string fileName, FileErrorPolicy policy) { string cantLoadFileStandardText = resourceService.GetString("NetFocus.Services.FileUtilityService.CantLoadFileStandardText"); return(ObservedLoad(loadFileDelegate, fileName, cantLoadFileStandardText, policy)); }
public FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName) { return ObservedSave(saveFile, fileName, FileErrorPolicy.Inform); }
public static void DoFileOperation(string filepath, FileOperationDelegate fileOperationDelegate) { BaseCache.DoFileOperation(filepath, fileOperationDelegate); }