Пример #1
0
        void RefreshInternal(bool assumeSomethingChanging = false, ILogSource assumeSourceChanged = null)
        {
            bool somethingChanged = assumeSomethingChanging;

            foreach (LogSourceRecordInternal rec in knownLogSources.Values)
            {
                rec.logSourceIsAlive = false;
            }
            foreach (var src in EnumLogSourcesOfKnownTypes())
            {
                LogSourceRecordInternal rec;
                if (!knownLogSources.TryGetValue(src.Key, out rec))
                {
                    rec              = new LogSourceRecordInternal();
                    rec.logSource    = src.Key;
                    rec.metadata     = src.Value;
                    rec.logFileName  = src.Key.Provider.ConnectionParams[ConnectionParamsUtils.PathConnectionParam];
                    rec.cancellation = new CancellationTokenSource();
                    foreach (var postprocessorType in rec.metadata.SupportedPostprocessors)
                    {
                        rec.PostprocessorsOutputs.Add(new PostprocessorOutputRecordInternal()
                        {
                            Metadata = postprocessorType
                        });
                    }

                    knownLogSources.Add(src.Key, rec);
                    somethingChanged = true;
                }
                rec.logSourceIsAlive = true;

                foreach (var parserOutput in rec.PostprocessorsOutputs)
                {
                    RefreshPostprocessorOutput(rec, parserOutput, ref somethingChanged, rec.logSource == assumeSourceChanged);
                }
            }
            foreach (LogSourceRecordInternal rec in new List <LogSourceRecordInternal>(knownLogSources.Values))
            {
                if (rec.logSource.IsDisposed)
                {
                    rec.logSourceIsAlive = false;
                }
                if (!rec.logSourceIsAlive)
                {
                    if (!rec.cancellation.IsCancellationRequested)
                    {
                        rec.cancellation.Cancel();
                    }
                    knownLogSources.Remove(rec.logSource);
                    somethingChanged = true;
                }
            }
            if (somethingChanged)
            {
                if (Changed != null)
                {
                    Changed(this, EventArgs.Empty);
                }
            }
        }
Пример #2
0
        private void RefreshPostprocessorOutput(
            LogSourceRecordInternal logSourceRecord,
            PostprocessorOutputRecordInternal postprocessorOutputRecord,
            ref bool somethingChanged,
            bool assumeChanged)
        {
            LogSourcePostprocessorOutput.Status oldStatus  = postprocessorOutputRecord.status;
            IPostprocessorRunSummary            oldSummary = postprocessorOutputRecord.lastRunSummary;

            bool postprocessorOutputNeedsLoading =
                assumeChanged ||
                postprocessorOutputRecord.status != LogSourcePostprocessorOutput.Status.Finished;

            if (postprocessorOutputRecord.postprocessorTask != null)
            {
                if (postprocessorOutputRecord.postprocessorTask.IsCompleted)
                {
                    if (postprocessorOutputRecord.postprocessorTask.GetTaskException() != null)
                    {
                        postprocessorOutputRecord.lastRunSummary = new FailedRunSummary(postprocessorOutputRecord.postprocessorTask.GetTaskException());
                    }
                    else
                    {
                        var runSummary            = postprocessorOutputRecord.postprocessorTask.Result;
                        var logSpecificRunSummary = runSummary?.GetLogSpecificSummary(logSourceRecord.logSource) ?? runSummary;
                        postprocessorOutputRecord.lastRunSummary = logSpecificRunSummary;
                    }
                    postprocessorOutputRecord.ClearPostprocessorTask();
                    postprocessorOutputNeedsLoading = true;
                }
                else
                {
                    postprocessorOutputRecord.status = LogSourcePostprocessorOutput.Status.InProgress;
                    postprocessorOutputNeedsLoading  = false;
                }
            }

            if (postprocessorOutputNeedsLoading)
            {
                TryLoadParserOutputAndUpdateStatus(logSourceRecord, postprocessorOutputRecord);
            }

            somethingChanged = somethingChanged ||
                               (postprocessorOutputRecord.status != oldStatus) ||
                               (postprocessorOutputRecord.lastRunSummary != oldSummary);
        }
Пример #3
0
 private void TryLoadParserOutputAndUpdateStatus(LogSourceRecordInternal logSourceRecord, PostprocessorOutputRecordInternal r)
 {
     if (string.IsNullOrEmpty(logSourceRecord.logFileName) ||
         (r.lastRunSummary != null && r.lastRunSummary.HasErrors))
     {
         r.status = LogSourcePostprocessorOutput.Status.Failed;
         return;
     }
     using (var existingSection = logSourceRecord.logSource.LogSourceSpecificStorageEntry.OpenXMLSection(
                MakePostprocessorOutputFileName(r.Metadata), Persistence.StorageSectionOpenFlag.ReadOnly))
     {
         if (existingSection.Data.Root == null)
         {
             r.status = LogSourcePostprocessorOutput.Status.NeverRun;
             return;
         }
         try
         {
             object tmpOutput = r.Metadata.DeserializeOutputData(existingSection.Data, logSourceRecord.logSource);
             r.outputData = tmpOutput;
             if (IsOutputOutdated(logSourceRecord.logSource, existingSection))
             {
                 r.status = LogSourcePostprocessorOutput.Status.Outdated;
             }
             else
             {
                 r.status = LogSourcePostprocessorOutput.Status.Finished;
             }
         }
         catch (Exception)
         {
             // If reading a file throws exception assume that cached format is old and unsupported.
             r.status = LogSourcePostprocessorOutput.Status.NeverRun;
             return;
         }
     }
 }
Пример #4
0
        void RefreshInternal(bool assumeSomethingChanging = false, ILogSource assumeSourceChanged = null)
        {
            bool somethingChanged = assumeSomethingChanging;

            foreach (LogSourceRecordInternal rec in knownLogSources.Values)
            {
                rec.logSourceIsAlive = false;
            }
            foreach (var src in EnumLogSourcesOfKnownTypes())
            {
                LogSourceRecordInternal rec;
                if (!knownLogSources.TryGetValue(src.Key, out rec))
                {
                    rec              = new LogSourceRecordInternal();
                    rec.logSource    = src.Key;
                    rec.metadata     = src.Value;
                    rec.logFileName  = src.Key.Provider.ConnectionParams[ConnectionParamsUtils.PathConnectionParam];
                    rec.cancellation = new CancellationTokenSource();
                    foreach (var postprocessorType in rec.metadata.SupportedPostprocessors)
                    {
                        rec.PostprocessorsOutputs.Add(new PostprocessorOutputRecordInternal()
                        {
                            Metadata = postprocessorType
                        });
                    }

                    knownLogSources.Add(src.Key, rec);
                    somethingChanged = true;
                }
                rec.logSourceIsAlive = true;

                foreach (var parserOutput in rec.PostprocessorsOutputs)
                {
                    RefreshPostprocessorOutput(rec, parserOutput, ref somethingChanged, rec.logSource == assumeSourceChanged);
                }
            }
            foreach (LogSourceRecordInternal rec in new List <LogSourceRecordInternal>(knownLogSources.Values))
            {
                if (rec.logSource.IsDisposed)
                {
                    rec.logSourceIsAlive = false;
                }
                if (!rec.logSourceIsAlive)
                {
                    if (!rec.cancellation.IsCancellationRequested)
                    {
                        rec.cancellation.Cancel();
                    }
                    knownLogSources.Remove(rec.logSource);
                    somethingChanged = true;
                }
            }
            if (somethingChanged)
            {
                Changed?.Invoke(this, EventArgs.Empty);
            }

            if (somethingChanged && settingsAccessor.EnableAutoPostprocessing)
            {
                var outputs = this.GetAutoPostprocessingCapableOutputs()
                              .Where(x => x.PostprocessorMetadata.TypeID != PostprocessorIds.Correlator)
                              .Select(output => new KeyValuePair <ILogSourcePostprocessor, ILogSource>(output.PostprocessorMetadata, output.LogSource))
                              .ToArray();
                if (outputs.Length > 0)
                {
                    ((IPostprocessorsManager)this).RunPostprocessor(outputs, forceSourcesSelection: false);
                }
            }
        }