/// <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);
            }
        }
Exemple #3
0
 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);
 }
Exemple #4
0
        public void setUndoPoint(string name, DOCUMENT_TYPE obj)
        {
            //undoBuffer is inactive if maxUndo is set to 0
            if (maxUndo == 0)
            {
                return;
            }

            redoBuffer.Clear();
            if (undoBuffer.Count >= maxUndo)
            {
                if (undoBuffer.Count > 0)
                {
                    //undoBuffer.Pop();
                    undoBuffer.Dequeue();
                }
            }
            try
            {
                undoBuffer.Push(new UndoEvent(name, obj));
            }
            catch (System.InvalidOperationException ex)
            {
                WDAppLog.logError(ErrorLevel.Error, "Undo is failing, critical memory shortage is likely", ex.Message);
            }
        }
Exemple #5
0
 /// <summary>
 /// If True, Logs the reason via WDAppLog
 /// </summary>
 public static void LogIfTrue(this Why why,
                              ErrorLevel priority              = ErrorLevel.Error,
                              [CallerLineNumber] int line      = 0,
                              [CallerFilePath] string file     = "",
                              [CallerMemberName] string member = "")
 {
     if (why)
     {
         WDAppLog.logError(priority, why.Reason ?? "(no reason given)", "", line, file, member);
     }
 }
        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);
            }
        }
Exemple #8
0
 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);
     }
 }