Пример #1
0
        public static void BuildDocumentMap(FileData file)
        {
            lock (file.DocumentMap)
            {
                PerformanceService.StartEvent($"{PerformanceService.CONST_BuildDocumentMap}{file.Path}");
                try
                {
                    #region LazyLoad
                    if (file.IsCached_Lazy_DocumentMap)
                    {
                        Log.Write("Pulling DocumentMap from Cache", typeof(DocumentMapService).FullName, MethodBase.GetCurrentMethod().Name,
                                  LogEntryType.Warning);
                        return;
                    }
                    #endregion

                    file.DocumentMap.Clear();
                    List <iLineMatch> events = new List <iLineMatch>();
                    var performanceResults   = new List <EventPerformanceResult>();
                    var results = new List <DocumentEntry>();
                    int totalEvents;
                    events           = GetLines(file, performanceResults, out totalEvents);
                    file.DocumentMap = ProcessLines(file, events);
                    BuildDocumentMapValues(file);
                    file.DocumentMap.AddRange(new BuildDocumentMapGapService().Execute(file));
                    file.DocumentMap = BuildDocumentMapGapService.PostProcess(file.DocumentMap.OrderBy(n => n.iLine).ThenBy(n => n.Sort).ToList());
                }
                finally
                {
                    file.IsCached_Lazy_DocumentMap = true;
                }
                PerformanceService.StopEvent($"{PerformanceService.CONST_BuildDocumentMap}{file.Path}");
            }
        }
Пример #2
0
        public void Render(string model)
        {
            _renderComplete.Reset();
            var r = new ReleaseUI($"Render ReleaseUI for {ViewModel.Model.File.Path}", true);

            ViewModel.RenderStarted();
            SuspendLayout();
            try
            {
                if (model == null)
                {
                    Log.WriteError("Model is NULL, this should not happen!", typeof(DocumentWindow).FullName, MethodBase.GetCurrentMethod().Name);
                    return;
                }


                if (InvokeRequired)
                {
                    Invoke(new Action <string>(Render), model);
                    return;
                }

                PerformanceService.StartEvent($"{PerformanceService.CONST_RenderDocument}{ViewModel.Model.File.Path}");
                OutputService.Log($"Document Render for {ViewModel.Model.File.Path}");
                Log.WriteEnter(typeof(DocumentWindow).FullName, MethodBase.GetCurrentMethod().Name);

                // Setting SelectionChangedDelayedEnabled for the first time
                if (!fctbDocument.SelectionChangedDelayedEnabled)
                {
                    fctbDocument.SelectionChangedDelayedEnabled = true;
                }
                scBase.Panel1Collapsed = !XmlDal.DataModel.Options.DocumentSourceInfo;
                PreCachePropertyLineData();
                r.DoEvents();
                sourceInfo.Render(ViewModel.Model.File);
                fctbDocument.ClearCache();
                r.DoEvents();
                fctbDocument.Text = model;
                r.DoEvents();
                ApplyFolding();
                // Force the control to paint itself now

                fctbDocument.Invalidate();
                StatusUpdate(StatusModel.Completed);
                Log.WriteTrace("Document Render Complete...", typeof(DocumentWindow).FullName, MethodBase.GetCurrentMethod().Name);
                PerformanceService.StopEvent($"Rebuild Active Document for {ViewModel.Model.File.Path}", true);
                PerformanceService.StopEvent($"{PerformanceService.CONST_RenderDocument}{ViewModel.Model.File.Path}", true);
                r.Stop();
            }
            finally
            {
                ResumeLayout();
                ViewModel.DocumentRenderComplete();
                _renderComplete.Set();
            }
        }
Пример #3
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            DataPath.ExecutablePath = Application.ExecutablePath;
            mainMenu.Enabled        = false;
            mainMenu.Visible        = false;

            Text = string.Format("Sara.LogReader {0}", Application.ProductVersion);
            PerformanceService.StartEvent(PerformanceService.CONST_Startup);
            MainViewModel.StartUp(this, _openFileOnStartupPath);
            PerformanceService.StopEvent(PerformanceService.CONST_Startup);
        }
Пример #4
0
        /// <summary>
        /// Used to quickly rebuild the active documents cache.  Used to speed up development and exercise code
        /// </summary>
        public static void RebuildActiveDocument()
        {
            ThreadPool.QueueUserWorkItem(delegate
            {
                OutputService.ClearOutputWindow?.Invoke();
                PerformanceService.StartEvent($"Rebuild Active Document for {Current.Model.File.Path}");
                Thread.CurrentThread.Name = "Rebuild.Active.Document";

                var file = Current.Model.File;
                file.Clear();
                FileService.Build(file, true);
                file.IsCached_Lazy_NetworkMessages = false;
                NetworkService.CheckNetworkMessages(file, View.StatusUpdate, "Source");

                // Invalidate will force dependent Components to Render
                file.DataController.Invalidate();
            });
        }
        public void Render(List <DocumentEntry> model)
        {
            var r = new ReleaseUI("DocumentMap.Render");

            PerformanceService.StartEvent($"{PerformanceService.CONST_RenderDocumentMap}{ViewModel.LastPath}");
            // Note: Invoke is handled through ViewModelbase - Sara
            if (_isRendering)
            {
                return;
            }

            if (!MainViewModel.StartupComplete)
            {
                StatusPanel.StatusUpdate(StatusModel.Completed);
                return;
            }

            if (model == null)
            {
                ShowWarning();
                StatusPanel.StatusUpdate(StatusModel.Completed);
                return;
            }

            _isRendering   = true;
            wpOpen.Visible = false;
            panel3.Visible = true;

            StatusPanel.StatusUpdate(StatusModel.StartStopWatch);
            StatusPanel.StatusUpdate(StatusModel.Update("Loading", ""));

            r.Stop();

            ThreadPool.QueueUserWorkItem(delegate
            {
                var sw = new Stopwatch("DocumentMap.Render.BuildTreeView");
                Thread.CurrentThread.Name = "Building.DocumentMap.TreeView";
                ViewModel.BuildTreeView(model, RenderCallback);
                sw.Stop(0);
            });
        }
Пример #6
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);
        }
Пример #7
0
        /// <summary>
        /// STARTING POINT for Open Document
        ///
        /// Order of Operations
        /// 1.) MainViewModel.OnOpenDocument
        /// 2.) DocumentWindow.OpenFile
        /// 3.) MainViewModel.AddDocument
        /// </summary>
        public static void OpenDocument(string path, Action callback = null)
        {
            #region InvokeRequired
            if (View.InvokeRequired)
            {
                View.Invoke(new Action <string, Action>(OpenDocument), path, callback);
                return;
            }
            #endregion

            PerformanceService.StartEvent($"{PerformanceService.CONST_OpenDocument}{path}");
            Log.WriteEnter(typeof(MainViewModel).FullName, MethodBase.GetCurrentMethod().Name);

            lock (_syncOpenDocument)
            {
                #region Check if already open
                if (!File.Exists(path))
                {
                    MessageBox.Show(string.Format("They system cannot find the file specified: \"{0}\"", path));
                    return;
                }
                var doc = FindDocument(path) as DocumentWindow;

                if (doc != null)
                {
                    doc.DockHandler.Show();

                    var model = doc as DocumentWindow;
                    if (model != null)
                    {
                        SetCurrent(model.ViewModel);
                    }

                    callback?.Invoke();
                    return;
                }
                #endregion

                #region Create DocumentWindow
                doc = new DocumentWindow {
                    Text = Path.GetFileName(path)
                };
                try
                {
                    var model = new DocumentModel
                    {
                        Control = doc.PrepareDocument(path),
                        File    = XmlDal.CacheModel.GetFile(path)
                    };

                    doc.ViewModel.View.StatusUpdate(StatusModel.Update("Loading"));
                    doc.ViewModel.Model      = model;
                    model.File.Options       = Options;
                    model.File.DocumentModel = model;
                    Documents.Add(doc.ViewModel);
                    DocumentService.BuildDocument(model);
                }
                catch (Exception exception) { doc.Close(); MessageBox.Show(exception.Message); }
                #endregion

                #region Show
                if (View.DockPanel.DocumentStyle == DocumentStyle.SystemMdi)
                {
                    doc.MdiParent = View as Form;
                    doc.Show();
                }
                else
                {
                    doc.Show(View.DockPanel);
                }
                #endregion

                if (StartupComplete)
                {
                    SetCurrent(doc.ViewModel);
                }

                callback?.Invoke();

                PerformanceService.StopEvent($"{PerformanceService.CONST_OpenDocument}{path}");
                Log.WriteExit(typeof(MainViewModel).FullName, MethodBase.GetCurrentMethod().Name);
            }
        }