Ejemplo n.º 1
0
        public ItemAction(string line, bool ignoreCase, string fullConfigFileName, int startLineNo)
        {
            Match match = Regex.Match(line ?? "", PATTERN_PATTERN);

            if (!match.Success)
            {
                throw new ArgumentException(
                          $"Invalid item-action '{line}' at {fullConfigFileName}/{startLineNo}");
            }
            else
            {
                GroupCollection groups = match.Groups;
                if (groups[1].Value != "")
                {
                    _atLeastOneIncomingDependencyPattern = new DependencyPattern(groups[1].Value, ignoreCase);
                }
                if (groups[2].Value != "")
                {
                    _itemMatch = new ItemMatch(groups[2].Value, ignoreCase, anyWhereMatcherOk: false);
                }
                if (groups[3].Value != "")
                {
                    _atLeastOneOutgoingDependencyPattern = new DependencyPattern(groups[3].Value, ignoreCase);
                }
                if (groups[4].Value != "-" && groups[4].Value != "delete")
                {
                    var effects       = new List <Action <Item> >();
                    var effectOptions =
                        groups[4].Value.Split(' ', ',').Select(s => s.Trim()).Where(s => !string.IsNullOrWhiteSpace(s));
                    foreach (var effect in effectOptions)
                    {
                        if (effect == "" || effect == "ignore" || effect == "keep")
                        {
                            effects.Add(d => { });
                        }
                        else if (effect.StartsWith("+"))
                        {
                            effects.Add(i => i.IncrementMarker(effect.Substring(1)));
                        }
                        else if (effect.StartsWith("-"))
                        {
                            effects.Add(i => i.RemoveMarkers(effect.Substring(1), ignoreCase));
                        }
                        else
                        {
                            throw new ArgumentException(
                                      $"Unexpected item directive '{effect}' at {fullConfigFileName}/{startLineNo}");
                        }
                    }
                    _effects = effects;
                }
                else
                {
                    _effects = null;
                }
            }
        }
Ejemplo n.º 2
0
 private void AddPattern()
 {
     if (Patterns == null)
     {
         Patterns = new ObservableCollection <DependencyPattern>();
     }
     else
     {
         Patterns.Add(DependencyPattern.Create());
     }
 }
Ejemplo n.º 3
0
 private void RemovePattern(DependencyPattern param)
 {
     if (Patterns == null)
     {
         return;
     }
     Patterns.Remove(param);
     if (Patterns.Count == 0)
     {
         Patterns = null;
     }
 }
Ejemplo n.º 4
0
        private void RecursivelyFlood(Item root, Item from, HashSet <Item> visited, Dictionary <FromTo, Dependency> checkPresence,
                                      DependencyPattern idempotentPattern, Dictionary <Item, Dependency[]> outgoing, IEnumerable <ItemMatch> toItemMatches,
                                      List <DependencyMatch> matches, List <DependencyMatch> excludes, Dictionary <string, int> markersToAddOrNull,
                                      List <Dependency> result, Dependency collectedEdge, [NotNull] Action checkAbort, WorkingGraph workingGraph, bool ignoreCase)
        {
            if (outgoing.ContainsKey(from))
            {
                checkAbort();
                foreach (var d in outgoing[from].Where(d => d.IsMarkerMatch(matches, excludes)))
                {
                    Item target = d.UsedItem;
                    if (visited.Add(target))
                    {
                        Dependency rootToTarget = collectedEdge == null
                            ? d
                            : workingGraph.CreateDependency(root, target, d.Source,
                                                            new MutableMarkerSet(ignoreCase,
                                                                                 markersToAddOrNull
                                                                                 ?? MutableMarkerSet.ConcatOrUnionWithMarkers(collectedEdge.AbstractMarkerSet,
                                                                                                                              d.AbstractMarkerSet, ignoreCase)),
                                                            collectedEdge.Ct + d.Ct, collectedEdge.QuestionableCt + d.QuestionableCt,
                                                            collectedEdge.BadCt + d.BadCt, collectedEdge.NotOkReason ?? d.NotOkReason, d.ExampleInfo);

                        if (IsMatch(toItemMatches, target))
                        {
                            Dependency alreadyThere;
                            var        rootTargetKey = new FromTo(root, target);
                            if (checkPresence.TryGetValue(rootTargetKey, out alreadyThere) && idempotentPattern.IsMatch(alreadyThere))
                            {
                                // we do not add a dependency
                            }
                            else
                            {
                                checkPresence[rootTargetKey] = rootToTarget;
                                result.Add(rootToTarget);
                            }
                        }

                        // Continue search
                        RecursivelyFlood(root, target, visited, checkPresence, idempotentPattern, outgoing,
                                         toItemMatches, matches, excludes, markersToAddOrNull, result, rootToTarget,
                                         checkAbort, workingGraph, ignoreCase);
                    }
                }
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        private static void PatternsListAdd(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var uc = d as DependencyPatternsUserControl;

            if (uc == null)
            {
                return;
            }
            var firstItem = (e.NewValue as ObservableCollection <DependencyPattern>)?.FirstOrDefault();

            if (firstItem == null && e.NewValue != null)
            {
                firstItem = DependencyPattern.Create();

                {
                    uc.Patterns.Add(firstItem);
                    uc.SelectedPattern = firstItem;
                }
            }
            else
            {
                uc.SelectedPattern = firstItem;
            }
        }