예제 #1
0
        // 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);
        }
예제 #2
0
        public static FileOperationResult ObservedSave(NamedFileOperationDelegate saveFileAs, string fileName, string message, FileErrorPolicy policy)
        {
            System.Diagnostics.Debug.Assert(IsValidFileName(fileName));
            try {
                string directory = Path.GetDirectoryName(fileName);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                saveFileAs(fileName);
                OnFileSaved(new FileNameEventArgs(fileName));
                return(FileOperationResult.OK);
            } catch (Exception e) {
                switch (policy)
                {
                case FileErrorPolicy.Inform:
                    using (SaveErrorInformDialog informDialog = new SaveErrorInformDialog(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e)) {
                        informDialog.ShowDialog();
                    }
                    break;

                case FileErrorPolicy.ProvideAlternative:
restartlabel:
                    using (SaveErrorChooseDialog chooseDialog = new SaveErrorChooseDialog(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", 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;
                }
            }
            return(FileOperationResult.Failed);
        }
예제 #3
0
		// 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;
		}
예제 #4
0
		public static FileOperationResult ObservedSave(NamedFileOperationDelegate saveFileAs, string fileName, string message, FileErrorPolicy policy)
		{
			System.Diagnostics.Debug.Assert(IsValidFileName(fileName));
			try {
				string directory = Path.GetDirectoryName(fileName);
				if (!Directory.Exists(directory)) {
					Directory.CreateDirectory(directory);
				}
				saveFileAs(fileName);
				OnFileSaved(new FileNameEventArgs(fileName));
				return FileOperationResult.OK;
			} catch (Exception e) {
				switch (policy) {
					case FileErrorPolicy.Inform:
						using (SaveErrorInformDialog informDialog = new SaveErrorInformDialog(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", e)) {
							informDialog.ShowDialog();
						}
						break;
					case FileErrorPolicy.ProvideAlternative:
					restartlabel:
						using (SaveErrorChooseDialog chooseDialog = new SaveErrorChooseDialog(fileName, message, "${res:FileUtilityService.ErrorWhileSaving}", 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;
				}
			}
			return FileOperationResult.Failed;
		}