Ejemplo n.º 1
0
        private async Task LoadLogsAsync(ILogStore logStore)
        {
            var hasPath = !string.IsNullOrEmpty(logStore.Path);

            if (hasPath)
            {
                SetOverlayState(OverlayState.Loading);
            }

            var aggregator  = new LogAggregator();
            var treeBuilder = new LogTreeBuilder();

            List <LogItem> logs = null;

            await Task.Run(async() => logs = await ReadLogsAsync(logStore).ConfigureAwait(false));

            while (logs == null)
            {
                Thread.Sleep(50);
            }

            var success = Validate(logs);

            if (!success)
            {
                logs.Clear();
            }

            _aggregatedLogs = aggregator.Aggregate(logs);
            _lastLogPath    = logStore.Path;

            // Generate a data table and bind the date-time client to it.
            dateTimeChartRangeControlClient1.DataProvider.DataSource = _aggregatedLogs;

            // Specify data members to bind the client.
            dateTimeChartRangeControlClient1.DataProvider.ArgumentDataMember = nameof(RangeDatasourceItem.TimeStampLocal);
            dateTimeChartRangeControlClient1.DataProvider.ValueDataMember    = nameof(RangeDatasourceItem.ItemCount);
            dateTimeChartRangeControlClient1.DataProvider.SeriesDataMember   = nameof(RangeDatasourceItem.State);
            dateTimeChartRangeControlClient1.DataProvider.TemplateView       = new BarChartRangeControlClientView()
            {
            };
            dateTimeChartRangeControlClient1.PaletteName = "Solstice";

            var allStates   = Enum.GetValues(typeof(LogItem.State)).OfType <LogItem.State>().ToArray();
            var timestamps  = logs.Select(l => l.TimeStampLocal).Distinct();
            var rangeSource = timestamps.SelectMany(localTime =>
            {
                return(allStates.Select(state => new RangeDatasourceItem
                {
                    TimeStampLocal = localTime,
                    State = state,
                    ItemCount = _aggregatedLogs.Count(l => l.TimeStampLocal == localTime && l.AccumulatedState >= state)
                }));
            });

            dateTimeChartRangeControlClient1.DataProvider.DataSource = rangeSource;

            SetControlVisiblityByContext();

            if (_aggregatedLogs.Any())
            {
                SetOverlayState(OverlayState.None);
            }
            else
            {
                SetOverlayState(OverlayState.Empty);
            }

            Text = $"{logStore.GetLogName(logStore.Path)} - {GetAppNameWithVersion()}";
        }