Esempio n. 1
0
        public void TestActivityConfiguration()
        {
            Type activityInterfaceType = typeof(com.microsoft.reef.activity.IActivity);
            var  a            = Assembly.Load(@"com.microsoft.reef.activity");
            var  a1           = Assembly.Load(@"com.microsoft.reef.activityInterface");
            Type activityType = a.GetType("com.microsoft.reef.activity.HelloActivity");
            //Type activityType = typeof(com.microsoft.reef.activity.HelloActivity);

            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file2, file3 });

            cb.BindImplementation(activityInterfaceType, activityType);
            Type namedParameter = a1.GetType(@"com.microsoft.reef.driver.activity.ActivityConfigurationOptions+Identifier");

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

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


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

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

            IInjector injector    = tang1.NewInjector(conf1);
            var       activityRef = (com.microsoft.reef.activity.IActivity)injector.GetInstance(activityInterfaceType);

            Assert.IsNotNull(activityRef);

            //byte[] b = new byte[10];
            //activityRef.Call(b);
        }
Esempio n. 2
0
        public void TestDocumentLoadNamedParameterConfiguration()
        {
            Type documentedLocalNamedParameterType = typeof(Com.Microsoft.Tang.Examples.DocumentedLocalNamedParameter);
            Type namedParameter = asm.GetType(@"Com.Microsoft.Tang.Examples.DocumentedLocalNamedParameter+Foo");

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

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

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

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

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

            IInjector injector = tang1.NewInjector(conf1);
            var       doc      = (Com.Microsoft.Tang.Examples.DocumentedLocalNamedParameter)injector.GetInstance(documentedLocalNamedParameterType);

            Assert.IsNotNull(doc);
            var s = doc.ToString();
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        public void TestTweetConfiguration()
        {
            Type  tweeterType          = typeof(Com.Microsoft.Tang.Examples.Tweeter);
            Type  namedParameter       = asm.GetType(@"Com.Microsoft.Tang.Examples.Tweeter+PhoneNumber");
            ITang tang                 = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file });

            cb.BindImplementation(typeof(TweetFactory), typeof(MockTweetFactory));
            cb.BindImplementation(typeof(SMS), typeof(MockSMS));
            cb.BindNamedParameter(namedParameter, "8675309");
            IConfiguration conf = cb.Build();

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

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

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

            IInjector injector = tang1.NewInjector(conf1);
            var       tweeter  = (Com.Microsoft.Tang.Examples.Tweeter)injector.GetInstance(tweeterType);

            tweeter.sendMessage();
        }
Esempio n. 5
0
        public IInjector NewInjector(string[] assemblies, IDictionary <string, string> configurations)
        {
            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb1 = tang.NewConfigurationBuilder(assemblies);

            ConfigurationFile.AddConfiguration(cb1, configurations);
            IConfiguration conf = cb1.Build();

            IInjector injector = tang.NewInjector(conf);

            return(injector);
        }