本文整理汇总了C#中FileErrorPolicy类的典型用法代码示例。如果您正苦于以下问题:C# FileErrorPolicy类的具体用法?C# FileErrorPolicy怎么用?C# FileErrorPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileErrorPolicy类属于命名空间,在下文中一共展示了FileErrorPolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObservedSaveHandleException
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;
}
示例2: ObservedSave
public FileOperationResult ObservedSave(NamedFileOperationDelegate saveFileAs, string fileName, string message, FileErrorPolicy policy)
{
Debug.Assert(IsValidFileName(fileName));
#if false
try {
fileName = System.IO.Path.GetFullPath (fileName);
saveFileAs(fileName);
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:
restartlabel:
using (SaveErrorChooseDialog chooseDialog = new SaveErrorChooseDialog(fileName, message, "Error while saving", e, true)) {
switch (chooseDialog.ShowDialog()) {
case DialogResult.OK:
using (SaveFileDialog fdiag = new SaveFileDialog()) {
fdiag.OverwritePrompt = true;
fdiag.AddExtension = true;
fdiag.CheckFileExists = false;
fdiag.CheckPathExists = true;
fdiag.Title = "Choose alternate file name";
fdiag.FileName = fileName;
if (fdiag.ShowDialog() == DialogResult.OK) {
return ObservedSave(saveFileAs, fdiag.FileName, message, policy);
} else {
goto restartlabel;
}
}
case DialogResult.Retry:
return ObservedSave(saveFileAs, fileName, message, policy);
case DialogResult.Ignore:
return FileOperationResult.Failed;
}
}
break;
}
}
#else
try {
saveFileAs(fileName);
return FileOperationResult.OK;
} catch (Exception e) {
Console.WriteLine("Error while saving as : " + e.ToString());
}
#endif
return FileOperationResult.Failed;
}
示例3: ObservedSave
public static FileOperationResult ObservedSave(NamedFileOperationDelegate saveFileAs, string fileName, string message, FileErrorPolicy policy)
{
try
{
string directoryName = Path.GetDirectoryName(fileName);
if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}
saveFileAs(fileName);
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_016F;
case FileErrorPolicy.ProvideAlternative:
goto Label_0084;
default:
goto Label_016F;
}
Label_0084:
using (SaveErrorChooseDialog dialog2 = new SaveErrorChooseDialog(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", exception, true))
{
switch (dialog2.ShowDialog())
{
case DialogResult.OK:
{
using (SaveFileDialog dialog3 = new SaveFileDialog())
{
dialog3.OverwritePrompt = true;
dialog3.AddExtension = true;
dialog3.CheckFileExists = false;
dialog3.CheckPathExists = true;
dialog3.Title = "Choose alternate file name";
dialog3.FileName = fileName;
if (dialog3.ShowDialog() == DialogResult.OK)
{
return ObservedSave(saveFileAs, dialog3.FileName, message, policy);
}
goto Label_0084;
}
}
case DialogResult.Cancel:
case DialogResult.Abort:
goto Label_016F;
case DialogResult.Retry:
return ObservedSave(saveFileAs, fileName, message, policy);
case DialogResult.Ignore:
return FileOperationResult.Failed;
}
goto Label_016F;
}
}
Label_016F:
return FileOperationResult.Failed;
}
示例4: ObservedLoad
public static FileOperationResult ObservedLoad(NamedFileOperationDelegate saveFileAs, string fileName, FileErrorPolicy policy = FileErrorPolicy.Inform)
{
return ObservedLoad(saveFileAs,
fileName,
ResourceService.GetString("ICSharpCode.Services.FileUtilityService.CantLoadFileStandardText"),
policy);
}
示例5: ObservedLoad
public FileOperationResult ObservedLoad(NamedFileOperationDelegate saveFileAs, string fileName, string message, FileErrorPolicy policy)
{
return ObservedLoad(new FileOperationDelegate(new LoadWrapper(saveFileAs, fileName).Invoke), fileName, message, policy);
}
示例6: ObservedSaveHandleError
static FileOperationResult ObservedSaveHandleError(Exception e, NamedFileOperationDelegate saveFileAs, 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, true);
if (r.IsRetry) {
return ObservedSave(saveFileAs, fileName, message, policy);
} else if (r.IsIgnore) {
return FileOperationResult.Failed;
} else if (r.IsSaveAlternative) {
return ObservedSave(saveFileAs, r.AlternativeFileName, message, policy);
}
break;
}
return FileOperationResult.Failed;
}
示例7: ObservedLoadHandleException
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;
}
示例8: ObservedSave
public static FileOperationResult ObservedSave(NamedFileOperationDelegate saveFileAs, string fileName, FileErrorPolicy policy)
{
return ObservedSave(saveFileAs,
fileName,
ResourceService.GetString("ECBC.Services.FileUtil.CantSaveFileStandardText"),
policy);
}
示例9: ObservedLoad
// 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;
}
示例10: ObservedLoad
public static FileOperationResult ObservedLoad(FileOperationDelegate loadFile, string fileName, FileErrorPolicy policy)
{
return ObservedLoad(loadFile,
fileName,
ResourceService.GetString("ECBC.Services.FileUtil.CantLoadFileStandardText"),
policy);
}
示例11: ObservedLoad
public FileOperationResult ObservedLoad(NamedFileOperationDelegate loadFileAsDelegate, string fileName, FileErrorPolicy policy)
{
string cantLoadFileStandardText = resourceService.GetString("NetFocus.Services.FileUtilityService.CantLoadFileStandardText");
return ObservedLoad(loadFileAsDelegate,fileName,cantLoadFileStandardText,policy);
}
示例12: ObservedSave
// 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);
}
}
示例13: ObservedSave
public static FileOperationResult ObservedSave(NamedFileOperationDelegate saveFileAs, string fileName, string message, FileErrorPolicy policy)
{
System.Diagnostics.Debug.Assert(IsValidPath(fileName));
try {
string directory = Path.GetDirectoryName(fileName);
if (!Directory.Exists(directory)) {
Directory.CreateDirectory(directory);
}
saveFileAs(fileName);
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, true);
if (r.IsRetry) {
return ObservedSave(saveFileAs, fileName, message, policy);
} else if (r.IsIgnore) {
return FileOperationResult.Failed;
} else if (r.IsSaveAlternative) {
return ObservedSave(saveFileAs, r.AlternativeFileName, message, policy);
}
break;
}
}
return FileOperationResult.Failed;
}
示例14: ObservedSave
public static FileOperationResult ObservedSave(NamedFileOperationDelegate saveFileAs, FileName fileName, FileErrorPolicy policy = FileErrorPolicy.Inform)
{
return ObservedSave(saveFileAs,
fileName,
(string)LocalizeDictionary.Instance.GetLocalizedObject("BVEEditor", "StringResources", "Services_FileUtilities_CantSaveFileStandardText", LocalizeDictionary.CurrentCulture),
policy);
}
示例15: ObservedSave
public static FileOperationResult ObservedSave(FileOperationDelegate saveFile, string fileName, FileErrorPolicy policy)
{
return ObservedSave(saveFile,
fileName,
ResourceService.GetString("ICSharpCode.Services.FileUtilityService.CantSaveFileStandardText"),
policy);
}