Example #1
0
        public override int Transform([NotNull] GlobalContext globalContext, Ignore Ignore,
                                      [NotNull] TransformOptions transformOptions, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies,
                                      [NotNull] List <Dependency> transformedDependencies)
        {
            DependencyPattern idempotentPattern     = transformOptions.MarkerToAdd == null ? null : new DependencyPattern("'" + transformOptions.MarkerToAdd, globalContext.IgnoreCase);
            Dictionary <FromTo, Dependency> fromTos = transformOptions.Idempotent ? FromTo.AggregateAllDependencies(globalContext.CurrentGraph, dependencies) : null;

            int added   = 0;
            int removed = 0;

            foreach (var d in dependencies)
            {
                if (!transformOptions.RemoveOriginal)
                {
                    transformedDependencies.Add(d);
                }
                else
                {
                    removed++;
                }
                if (d.IsMarkerMatch(transformOptions.Matches, transformOptions.Excludes))
                {
                    if (fromTos == null ||
                        !FromTo.ContainsMatchingDependency(fromTos, d.UsedItem, d.UsingItem, idempotentPattern))
                    {
                        var newDependency = globalContext.CurrentGraph.CreateDependency(d.UsedItem, d.UsingItem, d.Source, d.MarkerSet, d.Ct,
                                                                                        d.QuestionableCt, d.BadCt, d.NotOkReason, d.ExampleInfo);
                        if (transformOptions.MarkerToAdd != null)
                        {
                            newDependency.IncrementMarker(transformOptions.MarkerToAdd);
                        }
                        transformedDependencies.Add(newDependency);
                        added++;
                    }
                }
            }
            Log.WriteInfo($"... added {added}{(removed > 0 ? " removed " + removed : "")} dependencies");
            return(Program.OK_RESULT);
        }
        public override int Transform([NotNull] GlobalContext globalContext, Ignore Ignore,
                                      [NotNull] TransformOptions transformOptions, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies,
                                      [NotNull] List <Dependency> transformedDependencies)
        {
            _transformRunCt++;
            MutableMarkerSet.AddComputedMarkerIfNoMarkers(transformOptions.MarkersToAdd,
                                                          transformOptions.FromItemMatches, transformOptions.ToItemMatches, "" + _transformRunCt);

            WorkingGraph currentWorkingGraph = globalContext.CurrentGraph;

            DependencyPattern idempotentPattern           = new DependencyPattern("'" + string.Join("+", transformOptions.MarkersToAdd), globalContext.IgnoreCase);
            Dictionary <FromTo, Dependency> checkPresence = transformOptions.Idempotent
                ? FromTo.AggregateAllDependencies(currentWorkingGraph, dependencies)
                : new Dictionary <FromTo, Dependency>();
            Dictionary <Item, Dependency[]> outgoing = Item.CollectOutgoingDependenciesMap(dependencies);
            IEnumerable <Item> matchingFroms         = outgoing.Keys.Where(i => IsMatch(transformOptions.FromItemMatches, i));

            Dictionary <string, int> markersToAddAsDictionary = transformOptions.MarkersToAdd.Distinct().ToDictionary(s => s, s => 1);

            var result = new List <Dependency>();

            foreach (var from in matchingFroms)
            {
                RecursivelyFlood(from, from, new HashSet <Item> {
                    from
                }, checkPresence, idempotentPattern, outgoing,
                                 transformOptions.ToItemMatches, transformOptions.Matches, transformOptions.Excludes,
                                 markersToAddAsDictionary, result, null, globalContext.CheckAbort,
                                 currentWorkingGraph, globalContext.IgnoreCase);
            }

            transformedDependencies.AddRange(dependencies);
            transformedDependencies.AddRange(result);
            Log.WriteInfo($"... added {result.Count} new dependencies");

            return(Program.OK_RESULT);
        }