Exemple #1
0
        public void AggregateRunResults(List <SyncRunResult> syncRunResults, List <CleanupRunResult> cleanupRunResults)
        {
            foreach (var syncRunResult in syncRunResults)
            {
                TargetAffectedFileCount.Add(syncRunResult.SyncConfig, syncRunResult.TargetAffectedFileCount);

                var cleanupResult = cleanupRunResults.FirstOrDefault(x => x.SyncConfig == syncRunResult.SyncConfig);
                if (cleanupResult != null)
                {
                    TargetAffectedFileCount[syncRunResult.SyncConfig] += cleanupResult.TargetAffectedFileCount;
                }
            }

            foreach (var cleanupIngestResult in cleanupRunResults)
            {
                if (!TargetAffectedFileCount.ContainsKey(cleanupIngestResult.SyncConfig))
                {
                    TargetAffectedFileCount.Add(cleanupIngestResult.SyncConfig,
                                                cleanupIngestResult.TargetAffectedFileCount);
                }
            }

            if (Configs != null && Configs.Any())
            {
                foreach (var syncConfig in Configs)
                {
                    if (!TargetAffectedFileCount.ContainsKey(syncConfig))
                    {
                        TargetAffectedFileCount.Add(syncConfig, 0);
                    }
                }
            }
        }
        /// <inheritdoc />
        protected sealed override async Task <IEnumerable <IDocument> > ExecuteContextAsync(IExecutionContext context)
        {
            if (ForceDocumentExecution || Configs.Any(x => x.Value.RequiresDocument))
            {
                // Only need to evaluate the context config delegates once
                ImmutableDictionary <string, object> .Builder configValuesBuilder = ImmutableDictionary.CreateBuilder <string, object>(StringComparer.OrdinalIgnoreCase);
                foreach (KeyValuePair <string, IConfig> config in Configs.Where(x => !x.Value.RequiresDocument))
                {
                    configValuesBuilder[config.Key] = await config.Value.GetValueAsync(null, context);
                }
                ImmutableDictionary <string, object> configValues = configValuesBuilder.ToImmutable();

                // Iterate the inputs
                IEnumerable <IDocument> aggregateResults = null;
                foreach (IDocument input in context.Inputs)
                {
                    // If the config requires a document, evaluate it each time
                    ImmutableDictionary <string, object> .Builder valuesBuilder = configValues.ToBuilder();
                    foreach (KeyValuePair <string, IConfig> config in Configs.Where(x => x.Value.RequiresDocument))
                    {
                        valuesBuilder[config.Key] = await config.Value.GetValueAsync(input, context);
                    }

                    // Get the results for this input document
                    IMetadata values = new ReadOnlyConvertingDictionary(valuesBuilder.ToImmutable());
                    IEnumerable <IDocument> results = await ExecuteInputFuncAsync(input, context, (i, c) => ExecuteConfigAsync(i, c, values));

                    if (results != null)
                    {
                        aggregateResults = aggregateResults?.Concat(results) ?? results;
                    }
                }
                return(aggregateResults);
            }
            else
            {
                // Only context configs
                ImmutableDictionary <string, object> .Builder valuesBuilder = ImmutableDictionary.CreateBuilder <string, object>();
                foreach (KeyValuePair <string, IConfig> config in Configs)
                {
                    valuesBuilder[config.Key] = await config.Value.GetValueAsync(null, context);
                }
                IMetadata values = new ReadOnlyConvertingDictionary(valuesBuilder.ToImmutable());
                return(await ExecuteConfigAsync(null, context, values));
            }
        }