Esempio n. 1
0
        public async Task <IEnumerable <string> > CollectAsync(CancellationToken cancellationToken)
        {
            var configSetName = _configSetNameProvider.GetConfigSetName();
            var collectorMode = _collectorModeProvider.GetCollectorMode();

            var mode = collectorMode.ToString().ToLowerInvariant();

            try
            {
                IEnumerable <string> result;

                _logger.LogInformation($"[{configSetName}] Started {mode}ing data collections.");

                var watch = System.Diagnostics.Stopwatch.StartNew();
                try
                {
                    result = await _collector.CollectAsync(cancellationToken);
                }
                finally
                {
                    watch.Stop();
                }

                var failedDataCollectionNames = result.Any() ? " (" + string.Join(",", result) + ")" : null;

                _logger.LogInformation($"[{configSetName}] {ResultPrefix(!result.Any())} {mode}ing data collections{failedDataCollectionNames}. Elapsed time: {watch.Elapsed}");

                return(result);
            }
            catch (Exception e)
            {
                _logger.LogCritical($"[{configSetName}] " + ResultPrefix(false) + " {mode}ing data collections: {errorMessage}", mode, e.GetAggregateMessages());
                throw;
            }
        }
Esempio n. 2
0
        public async Task <IEnumerable <string> > CollectAsync(CancellationToken cancellationToken)
        {
            var configSetName = _configSetNameProvider.GetConfigSetName();
            var collectorMode = _collectorModeProvider.GetCollectorMode();

            var dataCollectionsConfig = await _dataCollectionsConfigProvider.GetDataCollectionsConfigAsync(configSetName, cancellationToken);

            var dataGroups = dataCollectionsConfig.GroupBy(x => x.DataGroupName).Select(x => new { DataGroupName = x.Key, DataCollectionsConfig = x });

            var tasks = dataGroups.Select(x => CollectGroupAsync(x.DataGroupName, collectorMode, x.DataCollectionsConfig, cancellationToken)).ToList();

            await Task.WhenAll(tasks);

            return(tasks.SelectMany(x => x.Result).ToList());
        }