public PresentationModel( ILogSourcesManager logSources, IInvokeSynchronization modelInvoke, IModelThreads modelThreads, IFiltersList hlFilters, IBookmarks bookmarks, Settings.IGlobalSettingsAccessor settings ) { this.logSources = logSources; this.modelThreads = modelThreads; this.hlFilters = hlFilters; this.bookmarks = bookmarks; this.settings = settings; updateSourcesInvoker = new AsyncInvokeHelper(modelInvoke, UpdateSources); logSources.OnLogSourceColorChanged += (s, e) => { if (OnLogSourceColorChanged != null) { OnLogSourceColorChanged(s, e); } }; logSources.OnLogSourceAdded += (s, e) => { updateSourcesInvoker.Invoke(); }; logSources.OnLogSourceRemoved += (s, e) => { updateSourcesInvoker.Invoke(); }; logSources.OnLogSourceStatsChanged += (s, e) => { if ((e.Flags & LogProviderStatsFlag.PositionsRange) != 0) { if ((e.Flags & LogProviderStatsFlag.AvailableTimeUpdatedIncrementallyFlag) == 0) { updateSourcesInvoker.Invoke(); } else if (OnSourceMessagesChanged != null) { OnSourceMessagesChanged(this, EventArgs.Empty); } } }; }
public PresentationModel( ILogSourcesManager logSources, ISynchronizationContext sync ) { this.logSources = logSources; this.synchronizationContext = sync; updateSourcesInvoker = new AsyncInvokeHelper(sync, UpdateSources); logSources.OnLogSourceColorChanged += (s, e) => { OnLogSourceColorChanged?.Invoke(s, e); }; logSources.OnLogSourceAdded += (s, e) => { updateSourcesInvoker.Invoke(); }; logSources.OnLogSourceRemoved += (s, e) => { updateSourcesInvoker.Invoke(); }; logSources.OnLogSourceStatsChanged += (s, e) => { if ((e.Flags & LogProviderStatsFlag.PositionsRange) != 0) { if ((e.Flags & LogProviderStatsFlag.AvailableTimeUpdatedIncrementallyFlag) != 0) { FireMessagesChanged(s, isIncrementalChange: true); } else if (IsExposableLogSource(e.Value) && !IsExposableLogSource(e.OldValue)) { updateSourcesInvoker.Invoke(); } else { FireMessagesChanged(s, isIncrementalChange: false); } } }; }
void Update() { updateFlag.Validate(); ignoredLogSources.RemoveWhere(x => x.IsDisposed); logSourcesRequiringReordering.RemoveWhere(x => x.IsDisposed); if (currentReport != null) { currentReport.Dispose(); currentReport = null; } var messageParts = new List <StatusReports.MessagePart>(); messageParts.Add( new StatusReports.MessagePart( string.Format("{0} {1} problem with timestamps. {2}", logSourcesRequiringReordering.Count, logSourcesRequiringReordering.Count > 1 ? "logs have" : "log has", Environment.NewLine ) ) ); int shownLogSourcesCount = 0; foreach (var logSource in logSourcesRequiringReordering) { if (ignoredLogSources.Contains(logSource)) { continue; } ++shownLogSourcesCount; var logName = logSource.GetShortDisplayNameWithAnnotation(); if (string.IsNullOrEmpty(logName)) { logName = "log"; } Func <bool> checkSourceIsOk = () => { if (logSource.IsDisposed) { updateInvokeHelper.Invoke(); return(false); } return(true); }; if (shownLogSourcesCount > 1) { messageParts.Add(new StatusReports.MessagePart(Environment.NewLine)); } messageParts.AddRange(new[] { new StatusReports.MessageLink(logName, () => { if (!checkSourceIsOk()) { return; } presentersFacade.ShowLogSource(logSource); }), new StatusReports.MessagePart(" "), new StatusReports.MessageLink("reorder log", () => { if (!checkSourceIsOk()) { return; } var cp = preprocessingManager.AppendReorderingStep( logSource.Provider.ConnectionParams, logSource.Provider.Factory); if (cp != null) { logSource.Dispose(); preprocessingManager.Preprocess( new MRU.RecentLogEntry(logSource.Provider.Factory, cp, "", null)); } }), new StatusReports.MessagePart(" "), new StatusReports.MessageLink("ignore", () => { ignoredLogSources.Add(logSource); updateInvokeHelper.Invoke(); }) }); } if (shownLogSourcesCount != 0) { currentReport = statusReports.CreateNewStatusReport(); currentReport.ShowStatusPopup( "Log source problem", messageParts, autoHide: false ); } }
public Presenter( ILogSourcesManager logSources, IView view, IManager logSourcesPreprocessings, SourcePropertiesWindow.IPresenter propertiesWindowPresenter, LogViewer.IPresenterInternal logViewerPresenter, IAlertPopup alerts, IFileDialogs fileDialogs, IClipboardAccess clipboard, IShellOpen shellOpen, SaveJointLogInteractionPresenter.IPresenter saveJointLogInteractionPresenter, IColorTheme theme, IChangeNotification changeNotification, ISynchronizationContext uiSynchronizationContext ) { this.logSources = logSources; this.view = view; this.propertiesWindowPresenter = propertiesWindowPresenter; this.logSourcesPreprocessings = logSourcesPreprocessings; this.alerts = alerts; this.fileDialogs = fileDialogs; this.clipboard = clipboard; this.shellOpen = shellOpen; this.saveJointLogInteractionPresenter = saveJointLogInteractionPresenter; this.changeNotification = changeNotification; void updateItems() { itemsRevision++; changeNotification.Post(); } var invokeUpdateHelper = new AsyncInvokeHelper(uiSynchronizationContext, updateItems); logSources.OnLogSourceVisiblityChanged += (s, e) => updateItems(); logSources.OnLogSourceAnnotationChanged += (s, e) => updateItems(); logSources.OnLogSourceColorChanged += (s, e) => updateItems(); logSourcesPreprocessings.PreprocessingChangedAsync += (s, e) => invokeUpdateHelper.Invoke(); logSources.OnLogSourceStatsChanged += (s, e) => { if ((e.Flags & (LogProviderStatsFlag.Error | LogProviderStatsFlag.CachedMessagesCount | LogProviderStatsFlag.State | LogProviderStatsFlag.BytesCount | LogProviderStatsFlag.BackgroundAcivityStatus)) != 0) { invokeUpdateHelper.Invoke(); } }; this.getRoot = Selectors.Create( () => logSources.Items, () => logSourcesPreprocessings.Items, () => theme.ThreadColors, () => expandedKeys, () => selectedKeys, () => itemsRevision, (sources, preprocessings, themeColors, expanded, selected, rev) => new RootViewItem { Items = ImmutableArray.CreateRange( EnumItemsData(sources, preprocessings, themeColors, expanded, selected, logSourcesPreprocessings)) } ); this.getSelectedSources = Selectors.Create( getRoot, root => ImmutableArray.CreateRange( ViewItem.Flatten(root).Where(i => i.IsSelected).SelectMany(i => { if (i is LogSourceViewItem singleSource) { return new[] { singleSource.LogSource } } ; if (i is SourcesContainerViewItem container) { return(container.LogSources.Select(x => x.LogSource)); } return(Enumerable.Empty <ILogSource>()); }) .Distinct() ) ); this.getSelectedPreprocessings = Selectors.Create( getRoot, root => ImmutableArray.CreateRange( ViewItem.Flatten(root).OfType <PreprocessingViewItem>().Select(p => p.Preprocessing) ) ); this.getFocusedMessageItem = Selectors.Create( () => logViewerPresenter.FocusedMessage, getRoot, (msg, root) => { var ls = msg?.GetLogSource(); return((IViewItem)ViewItem.Flatten(root).FirstOrDefault( i => (i as LogSourceViewItem)?.LogSource == ls )); } ); view.SetViewModel(this); }