public static IDisposable AddRule <T>(Func <Type, MemberInfo, T> rule)
        {
            DependencyRule <T> dependencyRule = new DependencyRule <T>(rule);

            rules.Add(dependencyRule);
            return(dependencyRule);
        }
        private static T GetServiceImpl <T>(Type aspectType, MemberInfo targetElement) where T : class
        {
            // The rule implementation is naive but this is for testing purpose only.
            foreach (object rule in rules)
            {
                DependencyRule <T> typedRule = rule as DependencyRule <T>;
                if (typedRule == null)
                {
                    continue;
                }

                T service = typedRule.Rule(aspectType, targetElement);
                if (service != null)
                {
                    return(service);
                }
            }

            if (container == null)
            {
                throw new InvalidOperationException();
            }

            // Fallback to the container, which should be the default and production behavior.
            return(container.GetExport <T>().Value);
        }
        /// <summary>
        /// Add a new dependency rule.
        /// </summary>
        private static void AddNewRandomBenchmark()
        {
            ConsoleLayout.Header("Add a new dependency rule");

            try
            {
                Console.Write("The number of gateparts that are involved: ");
                int nbGateParts = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine();
                List <GatePart> gateParts = new List <GatePart>();
                for (int i = 0; i < nbGateParts; i++)
                {
                    Console.Write("Gatepart " + (i + 1) + ": ");
                    string gatePartName = Console.ReadLine();
                    gateParts.Add((GatePart)Enum.Parse(typeof(GatePart), gatePartName));
                    if (gatePartName == "None")
                    {
                        throw new ArgumentException();
                    }
                }
                DependencyRule rule = new DependencyRule(gateParts);
                AlgorithmParameters.AvailableDependencyRules.Add(rule);
                Console.WriteLine("\nThe dependency rule '{0}' has been added.", rule);
            } catch (Exception e) when(e is ArgumentOutOfRangeException || e is FormatException)
            {
                ConsoleLayout.Error("Failed to add a new dependency rule");
            } catch (ArgumentException)
            {
                ConsoleLayout.Error("This is no valid gatepart, the addition of a dependency rule is aborted.");
            }

            ConsoleLayout.Footer();
        }
Beispiel #4
0
            protected void AddRule(DependencyRule <T> rule)
            {
                rule.MustBeApplied = true;
                rule.Weight        = GlyphScheduler.DefaultWeight;

                GlyphScheduler.Scheduler.Rules.Add(rule);
                _lastRule = rule;
            }
Beispiel #5
0
        public void TestSimpleNamedCall()
        {
            ItemType     itemType = DotNetAssemblyDependencyReaderFactory.DOTNETITEM;
            var          gc       = new GlobalContext();
            WorkingGraph graph    = gc.CurrentGraph;
            Item         @using   = graph.CreateItem(itemType, "", "NamespacelessTestClassForNDepCheck", "NDepCheck.TestAssembly", "1.0.0.0", "", "");
            Item         used     = graph.CreateItem(itemType, "System", "Object", "mscorlib", "", "", "");
            var          d        = graph.CreateDependency(@using, used, null, "Test", ct: 1);

            DependencyRule r = CreateDependencyRule(itemType, "**", "Assembly.Name=mscorlib");

            Assert.IsTrue(r.IsMatch(d));
        }
 public bool Equals(DependencyRule other)
 {
     return !ReferenceEquals(null, other) && (ReferenceEquals(this, other) ||
         Equals(other.Dependency, Dependency) && Equals(other.Dependent, Dependent));
 }
Beispiel #7
0
 public bool Equals(DependencyRule other)
 {
     return(!ReferenceEquals(null, other) && (ReferenceEquals(this, other) ||
                                              Equals(other.Dependency, Dependency) && Equals(other.Dependent, Dependent)));
 }