Example #1
0
        public void TestTimerConfigurationWithClassHierarchy()
        {
            Type timerType = typeof(Timer);
            ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(FileNames.Examples);

            ITang          tang = TangFactory.GetTang();
            IConfiguration conf = tang.NewConfigurationBuilder(classHierarchyImpl)
                                  .BindNamedParameter <Timer.Seconds, int>(GenericType <Timer.Seconds> .Class, "1")
                                  .Build();

            ConfigurationFile.WriteConfigurationFile(conf, "timerConfH.txt");
            IDictionary <string, string> p = ConfigurationFile.FromFile("timerConfH.txt");

            ITang tang1 = TangFactory.GetTang();
            ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { FileNames.Examples });

            ConfigurationFile.AddConfigurationFromFile(cb1, "timerConfH.txt");
            IConfiguration conf1 = cb1.Build();

            IInjector injector = tang1.NewInjector(conf1);
            var       timer    = (Timer)injector.GetInstance(timerType);

            Assert.NotNull(timer);
            timer.sleep();
        }
Example #2
0
        public void TestTimerConfigurationWithClassHierarchy()
        {
            Type timerType      = typeof(Com.Microsoft.Tang.Examples.Timer);
            Type namedParameter = asm.GetType(@"Com.Microsoft.Tang.Examples.Timer+Seconds");

            ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(file);

            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(classHierarchyImpl);

            cb.BindNamedParameter(namedParameter, "1");
            IConfiguration conf = cb.Build();

            ConfigurationFile.WriteConfigurationFile(conf, "timerConfH.txt");
            IDictionary <string, string> p = ReadFromFile("timerConfH.txt");

            ITang tang1 = TangFactory.GetTang();
            ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { file });

            ConfigurationFile.AddConfiguration(cb1, "timerConfH.txt");
            IConfiguration conf1 = cb1.Build();

            IInjector injector = tang1.NewInjector(conf1);
            var       timer    = (Com.Microsoft.Tang.Examples.Timer)injector.GetInstance(timerType);

            Assert.IsNotNull(timer);
            timer.sleep();
        }
Example #3
0
        public ICsClassHierarchy GetDefaultClassHierarchy(string[] assemblies, Type[] parameterParsers)
        {
            SetValuedKey key = new SetValuedKey(assemblies, parameterParsers);

            ICsClassHierarchy ret = null;

            defaultClassHierarchy.TryGetValue(key, out ret);
            if (ret == null)
            {
                ret = new ClassHierarchyImpl(assemblies, parameterParsers);
                defaultClassHierarchy.Add(key, ret);
            }
            return(ret);
        }
Example #4
0
        public void TestTimerWithClassHierarchy()
        {
            Type timerType = typeof(Timer);

            ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(FileNames.Examples);

            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder((ICsClassHierarchy)classHierarchyImpl);

            cb.BindNamedParameter <Timer.Seconds, int>(GenericType <Timer.Seconds> .Class, "2");
            IConfiguration conf = cb.Build();

            IInjector injector = tang.NewInjector(conf);
            var       timer    = (Timer)injector.GetInstance(timerType);

            Assert.IsNotNull(timer);

            timer.sleep();
        }
Example #5
0
        public void TestTimerWithClassHierarchy()
        {
            Type timerType      = typeof(Com.Microsoft.Tang.Examples.Timer);
            Type namedParameter = asm.GetType(@"Com.Microsoft.Tang.Examples.Timer+Seconds");

            ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(file);

            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder((ICsClassHierarchy)classHierarchyImpl);

            cb.BindNamedParameter(namedParameter, "2");
            IConfiguration conf = cb.Build();

            IInjector injector = tang.NewInjector(conf);
            var       timer    = (Com.Microsoft.Tang.Examples.Timer)injector.GetInstance(timerType);

            Assert.IsNotNull(timer);

            System.Console.WriteLine("Tick...");
            timer.sleep();
            System.Console.WriteLine("Tock...");
        }
Example #6
0
        public static void GetNodeFromHierarchy(ClassHierarchyImpl classHierarchyImpl)
        {
            IClassNode timerClassNode = (IClassNode)classHierarchyImpl.GetNode("Com.Microsoft.Tang.Examples.Timer");
            INode      secondNode     = classHierarchyImpl.GetNode("Com.Microsoft.Tang.Examples.Timer+Seconds");

            string classNmae = timerClassNode.GetFullName();
            //Type clazz = classHierarchyImpl.loader.GetType(classNmae);

            IList <IConstructorDef> constuctorDefs = timerClassNode.GetAllConstructors();

            foreach (IConstructorDef consDef in constuctorDefs)
            {
                IList <IConstructorArg> consArgs = consDef.GetArgs();
                foreach (IConstructorArg arg in consArgs)
                {
                    string argName     = arg.GetName();
                    string argTypeName = arg.Gettype();
                    Type   nt          = Type.GetType(argName);
                    INode  argNode     = classHierarchyImpl.GetNode(nt);
                }
            }
        }
Example #7
0
        public static void CreateClassHierarchy()
        {
            ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(file);

            GetNodeFromHierarchy(classHierarchyImpl);
        }