Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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;
        }