Beispiel #1
0
        public static void Shutdown()
        {
            View.StatusUpdate(StatusModel.StartStopWatch);
            View.StatusUpdate(StatusModel.Update("Closing"));

            // ReSharper disable AssignNullToNotNullAttribute
            var configFile = DataPath.GetConfigFilePath();
            // ReSharper restore AssignNullToNotNullAttribute

            var path = Path.GetDirectoryName(configFile);

            if (path != null)
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }
            else
            {
                throw new Exception("DockPanel.config path is null");
            }

            if (SkipSaveLayout)
            {
                if (File.Exists(configFile))
                {
                    File.Delete(configFile);
                }
            }
            else
            {
                View.DockPanel.SaveAsXml(configFile);
            }

            SaveRestoreOpenDocuments();

            XmlDal.Save();
        }
Beispiel #2
0
        public static void StartUp(MainForm view, string fileOnStartupPath)
        {
            StopWatchOutput.Log = OutputService.Log;
            ReleaseOutput.Log   = OutputService.Log;
            View = view;

            Log.WriteTrace("Starting Sara.LogReader", typeof(MainViewModel).Name, MethodBase.GetCurrentMethod().Name);

            #region Loading Data
            PerformanceService.StartEvent(PerformanceService.CONST_LoadingDataFile);
            View.StatusUpdate(StatusModel.StartCountdown(PerformanceService.GetLastDuration("Loading DataFile")));
            View.StatusUpdate(StatusModel.Update("Starting Sara.LogReader", "Loading Cache"));

            try
            {
                MainService.LoadDataFile();
            }
            catch (Exception ex)
            {
                View.ShowError(ex.Message);
            }
            PerformanceService.StopEvent(PerformanceService.CONST_LoadingDataFile);

            View.StatusUpdate(StatusModel.StopCountdown);

            #endregion

            #region Loading Layout
            PerformanceService.StartEvent(PerformanceService.CONST_LoadingLayout);
            View.StatusUpdate(StatusModel.Update("Starting Sara.LogReader", "Initializing Controls"));
            StartupCreateWindows();
            View.StatusUpdate(StatusModel.StartStopWatch);
            View.StatusUpdate(StatusModel.Update(null, "Loading Layout"));
            _mDeserializeDockContent = StartupGetContentFromPersistString;
            var configFile = DataPath.GetConfigFilePath();

            try
            {
                if (File.Exists(configFile))
                {
                    View.LoadLayout(configFile, _mDeserializeDockContent);
                }
            }
            catch (Exception)
            {
                var msg =
                    $"\"{configFile}\" has become corrupted.  \nTo resolve the system will automatically reset the file to default settings.";
                Log.WriteTrace(msg, typeof(MainForm).FullName, MethodBase.GetCurrentMethod().Name);
                MessageBox.Show(msg, "System Error");
                File.Delete(configFile);
            }

            Log.WriteTrace($"Main UI Thread Id: {MainUIThreadId}", typeof(MainForm).FullName, MethodBase.GetCurrentMethod().Name);

            View.StatusUpdate(StatusModel.StartStopWatch);
            PerformanceService.StopEvent(PerformanceService.CONST_LoadingLayout);
            #endregion

            PerformanceService.StartEvent(PerformanceService.CONST_LoadingOther);
            View.StatusUpdate(StatusModel.Update(null, "Rendering..."));
            CurrentLineChangedEvent += View.ActiveDocumentLineChanged;

            view.Render(null);

            #region Options
            View.SetOptions(Options);
            ApplyHideOptions(false);
            #endregion Options

            Application.DoEvents();

            StartupOpenFile(fileOnStartupPath);

            // Note: The majority of the cpu cycles will occur on the MainUI thread.
            // This is why we are not running this in Parallel or on it's own Thread.
            // This means that if you have 10 documents to open and each takes 2 seconds your will be waiting for 10+ seconds. - Sara
            if (Options.RestoreOpenDocuments)
            {
                View.StatusUpdate(StatusModel.Update("Restoring Open Documents..."));
                var i     = 0;
                var count = Options.RestoreOpenDocumentsList.Count;
                foreach (var path in Options.RestoreOpenDocumentsList)
                {
                    i++;
                    OpenDocument(path);
                    View.StatusUpdate(StatusModel.UpdateDetail($"{i} of {count}"));
                }
            }

            ReadyViews();

            // Render the Filter window any time a Category changes - Sara
            XmlDal.DataModel.CategoryCacheDataController.InvalidateNotificationEvent += _mFilterViewModel.RenderDocument;

            StartupComplete = true;

            // Render Focused Document
            var _current = Documents.FirstOrDefault(model => model.View.DockHandler.IsActiveContentHandler);
            if (_current != null)
            {
                SetCurrent(_current);
            }

            DocumentFont = ColorService.ColorScheme.Current.GeneralFontObject;

            View.StatusUpdate(StatusModel.Completed);
            PerformanceService.StopEvent(PerformanceService.CONST_LoadingOther);
        }