Exemplo n.º 1
0
        private static FileOperationResult ObservedLoadHandleException(Exception e, FileOperationDelegate loadFile, FileName fileName, string message, FileErrorPolicy policy)
        {
            message = message + Environment.NewLine + Environment.NewLine + e.Message;
            var messageService = Altaxo.Current.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);
        }
Exemplo n.º 2
0
        public ChooseSaveErrorResult ChooseSaveError(FileName fileName, string message, string dialogName, Exception exceptionGot, bool chooseLocationEnabled)
        {
            ChooseSaveErrorResult r = ChooseSaveErrorResult.Ignore;

restartlabel:
            var dlg = new SaveErrorChooseDialog(fileName, message, dialogName, exceptionGot, chooseLocationEnabled);

            ((GuiFactoryServiceWpfWin)Current.Gui).ShowDialog(dlg);

            switch (dlg.DetailedDialogResult)
            {
            case SaveErrorChooseDialog.SaveErrorChooseDialogResult.ChooseLocation:
            {
                // choose location:
                var fdiag = new SaveFileDialog
                {
                    OverwritePrompt = true,
                    AddExtension    = true,
                    CheckFileExists = false,
                    CheckPathExists = true,
                    Title           = "Choose alternate file name",
                    FileName        = fileName
                };
                if (fdiag.ShowDialog() == true)
                {
                    r = ChooseSaveErrorResult.SaveAlternative(FileName.Create(fdiag.FileName));
                    break;
                }
                else
                {
                    goto restartlabel;
                }
            }

            case SaveErrorChooseDialog.SaveErrorChooseDialogResult.Retry:
                r = ChooseSaveErrorResult.Retry;
                break;

            default:
                r = ChooseSaveErrorResult.Ignore;
                break;
            }

            return(r);
        }