/// <summary> /// Call this from the Open menu and you are done. /// </summary> public static bool DoFileOpen(this IMenuSaveOpenNewCloseExit app) { //save existing file if (!saveExistingFileBeforeNewOrOpen(app)) { return(false); } //open new file OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = FileFormat.MakeFileDialogeString(app.SupportedOpenFormats, false, ""); ofd.CheckFileExists = true; if (ofd.ShowDialog(app as IWin32Window) == DialogResult.OK) { string fileName = ofd.FileName; try { app.OpenFile(fileName); app.FileName = fileName; app.FileModified = false; } catch (Exception ex) { WDAppLog.logException(ErrorLevel.Error, ex); showErrorDialoge(app, "Could not open file ({0}): {1}.", app.FileName, ex.Message); return(false); } app.FileModified = false; return(true); } return(false); }
/// <summary> /// Call this from the New menu and you are done. /// </summary> public static bool DoFileNew(this IMenuSaveOpenNewCloseExit app) { //save existing file if (!saveExistingFileBeforeNewOrOpen(app)) { return(false); } try { if (app.NewFile()) { app.FileModified = true; app.FileName = null; return(true); } return(false); // a new file was not created for some reason (maybe the user pressed cancel on a dialogue). } catch (Exception ex) { WDAppLog.logException(ErrorLevel.Error, ex); showErrorDialoge(app, "Could create new file ({0}): {1}.", app.FileName, ex.Message); return(false); } }
public static void RaiseTestErrors() { WDAppLog.Debug("Next error is just a test"); WDAppLog.logCallToMethodStub(); WDAppLog.Debug("Next error is just a test"); WDAppLog.logError(ErrorLevel.Debug, "Error test (debug)"); WDAppLog.Debug("Next error is just a test"); WDAppLog.logError(ErrorLevel.Error, "Error test (Error)"); WDAppLog.Debug("Next error is just a test"); WDAppLog.logError(ErrorLevel.SmallError, "Error test (SmallError)"); WDAppLog.Debug("Next error is just a test"); WDAppLog.logError(ErrorLevel.SystemError, "Error test (SystemError)"); WDAppLog.Debug("Next error is just a test"); WDAppLog.logError(ErrorLevel.TerminalError, "Error test (TerminalError)"); WDAppLog.Debug("Next error is just a test"); WDAppLog.logError(ErrorLevel.Warning, "Error test (Warning)"); WDAppLog.Debug("Next error is just a test"); WDAppLog.LogNeverSupposedToBeHere(); WDAppLog.Debug("Next error is just a test"); WDAppLog.logException(ErrorLevel.Error, new NotImplementedException("Just a test")); WDAppLog.Debug("Next error is just a test"); WDAppLog.logFileOpenError(ErrorLevel.Error, @"C:\just a test.txt"); WDAppLog.Debug("Next error is just a test"); WDAppLog.logFileSaveError(ErrorLevel.Error, @"C:\just a test.txt"); WDAppLog.Debug("Next error is just a test"); WDAppLog.logTaggedError(ErrorLevel.Error, "Test error", null, "TEST_TAG"); WDAppLog.Debug("Next error is just a test"); WDAppLog.logTaggedError(ErrorLevel.Error, "Test error 2", Misc.LoremIpsum, "TEST_TAG"); WDAppLog.Debug("Next error is just a test"); WDAppLog.logError(ErrorLevel.Error, "long (Error)" + Misc.LoremIpsum); WDAppLog.Debug("Next error is just a test"); WDAppLog.Debug(Misc.LoremIpsum); }
private static bool applicationSave(IMenuSaveOpenNewCloseExit app, string path) { string fileName = path; try { app.SaveFile(fileName); app.FileModified = false; app.FileName = fileName; return(true); } catch (Exception ex) { WDAppLog.logException(ErrorLevel.Error, ex); showErrorDialoge(app, "Could not save file ({0}): {1}.", path, ex.Message); return(false); } }
/// <summary> /// Call this from the Close menu and you are done. /// </summary> public static bool DoFileClose(this IMenuSaveOpenNewCloseExit app) { //save existing file if (!saveExistingFileBeforeNewOrOpen(app)) { return(false); } try { app.CloseFile(); app.FileModified = false; app.FileName = null; return(true); } catch (Exception ex) { WDAppLog.logException(ErrorLevel.Error, ex); showErrorDialoge(app, "Could create new file ({0}): {1}.", app.FileName, ex.Message); return(false); } }
public static void TryCatchLogged(Action tryBlock, ErrorLevel errorLevelIfCatch, [CallerLineNumber] int line = 0, [CallerFilePath] string file = "", [CallerMemberName] string member = "") { if (tryBlock != null) { try { tryBlock(); } catch (Exception ex) { WDAppLog.logException(ErrorLevel.Error, ex, line, file, member); } } else { WDAppLog.logError(ErrorLevel.Warning, "TryCatchLogged was given a null tryBlock", line, file, member); } }