예제 #1
0
        public UserDefinedSearchesManager(
            Persistence.IStorageManager storage,
            IFiltersFactory filtersFactory,
            ISynchronizationContext modelThreadSynchronization
            )
        {
            this.filtersFactory       = filtersFactory;
            this.storageEntry         = new Lazy <Persistence.IStorageEntry>(() => storage.GetEntry("UserDefinedSearches"));
            this.changeHandlerInvoker = new AsyncInvokeHelper(modelThreadSynchronization, HandleChange);

            LoadItems();
        }
예제 #2
0
        internal SearchManager(
            ILogSourcesManager sources,
            ISynchronizationContext modelSynchronization,
            IHeartBeatTimer heartBeat,
            ISearchObjectsFactory factory,
            IChangeNotification changeNotification
            )
        {
            this.sources            = sources;
            this.factory            = factory;
            this.changeNotification = changeNotification;

            this.combinedSearchResult        = factory.CreateCombinedSearchResult(this);
            this.combinedResultUpdateInvoker = new AsyncInvokeHelper(
                modelSynchronization, UpdateCombinedResult);
            this.combinedResultNeedsLazyUpdateFlag = new LazyUpdateFlag();

            sources.OnLogSourceAdded += (s, e) =>
            {
                results.ForEach(r => r.FireChangeEventIfContainsSourceResults(s as ILogSource));
            };
            sources.OnLogSourceRemoved += (s, e) =>
            {
                results.ForEach(r => r.FireChangeEventIfContainsSourceResults(s as ILogSource));

                // Search result is fully disposed if it contains messages
                // only from disposed log sources.
                // Fully disposed results are automatically dropped.
                var toBeDropped = results.Where(
                    r => r.Results.All(sr => sr.Source.IsDisposed)).ToHashSet();
                var nrOfFullyDisposedResults = DisposeResults(toBeDropped);
                if (nrOfFullyDisposedResults > 0 && SearchResultsChanged != null)
                {
                    SearchResultsChanged(this, EventArgs.Empty);
                }
                if (nrOfFullyDisposedResults > 0)
                {
                    changeNotification.Post();
                    combinedResultNeedsLazyUpdateFlag.Invalidate();
                }
            };
            heartBeat.OnTimer += (s, e) =>
            {
                if (e.IsNormalUpdate && combinedResultNeedsLazyUpdateFlag.Validate())
                {
                    combinedResultUpdateInvoker.Invoke();
                }
            };
        }
예제 #3
0
        public SearchResult(
            ISearchManagerInternal owner,
            SearchAllOptions options,
            IFilter optionsFilter,
            IList <ILogSourceSearchWorkerInternal> workers,
            Progress.IProgressAggregatorFactory progressAggregatorFactory,
            ISynchronizationContext modelSynchronization,
            Settings.IGlobalSettingsAccessor settings,
            int id,
            ISearchObjectsFactory factory,
            ITraceSourceFactory traceSourceFactory
            )
        {
            this.owner                = owner;
            this.options              = options;
            this.optionsFilter        = optionsFilter;
            this.factory              = factory;
            this.modelSynchronization = modelSynchronization;
            this.id                     = id;
            this.cancellation           = new CancellationTokenSource();
            this.results                = new List <ISourceSearchResultInternal>();
            this.progressAggregator     = progressAggregatorFactory.CreateProgressAggregator();
            this.updateInvokationHelper = new AsyncInvokeHelper(modelSynchronization, UpdateStatus);
            this.hitsLimit              = settings.MaxNumberOfHitsInSearchResultsView;
            this.visible                = true;
            this.trace                  = traceSourceFactory.CreateTraceSource("SearchManager", "sr." + id.ToString());
            this.timeGapsDetector       = new TimeGapsDetector(trace, modelSynchronization, this, traceSourceFactory);

            this.timeGapsDetector.OnTimeGapsChanged += (s, e) =>
            {
                owner.OnResultChanged(this, SearchResultChangeFlag.TimeGapsChanged);
            };

            this.progressAggregator.ProgressChanged += HandleProgressChanged;

            this.searchTime = Stopwatch.StartNew();
            this.results.AddRange(workers.Select(w => factory.CreateSourceSearchResults(w, this, cancellation.Token, progressAggregator)));
            if (results.Count == 0)
            {
                status = SearchResultStatus.Finished;
                HandleFinalStateTransition();
            }
        }
예제 #4
0
 public BookmarkController(
     IBookmarks bookmarks,
     IModelThreads threads,
     IHeartBeatTimer heartbeat,
     ISynchronizationContext synchronization
     )
 {
     tracer         = LJTraceSource.EmptyTracer;
     bookmarksPurge = new AsyncInvokeHelper(synchronization, bookmarks.PurgeBookmarksForDisposedThreads);
     threads.OnThreadListChanged += (s, e) =>
     {
         bookmarksPurge.Invoke();
     };
     bookmarks.OnBookmarksChanged += (sender, e) =>
     {
         if (e.Type == BookmarksChangedEventArgs.ChangeType.Added || e.Type == BookmarksChangedEventArgs.ChangeType.Removed ||
             e.Type == BookmarksChangedEventArgs.ChangeType.RemovedAll || e.Type == BookmarksChangedEventArgs.ChangeType.Purged)
         {
             foreach (var affectedSource in
                      e.AffectedBookmarks
                      .Select(b => b.GetLogSource())
                      .Where(s => s.LogSourceStateIsOkToChangePersistentState())
                      .Distinct())
             {
                 try
                 {
                     affectedSource.StoreBookmarks();
                 }
                 catch (Persistence.StorageException storageException)
                 {
                     tracer.Error(storageException, "Failed to store bookmarks for log {0}",
                                  affectedSource.GetSafeConnectionId());
                 }
             }
         }
     };
 }