Example #1
0
        public void OnNext(IActiveContext activeContext)
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            cb.AddConfiguration(TaskConfiguration.ConfigurationModule
                                .Set(TaskConfiguration.Identifier, "bridgeCLRShellTask_" + DateTime.Now.Ticks)
                                .Set(TaskConfiguration.Task, GenericType <ShellTask> .Class)
                                .Build());
            cb.BindNamedParameter <ShellTask.Command, string>(GenericType <ShellTask.Command> .Class, "echo");

            IConfiguration taskConfiguration = cb.Build();

            activeContext.SubmitTask(taskConfiguration);
        }
Example #2
0
        public void CanInjectAndExecuteTask()
        {
            //To enforce that shell task dll be copied to output directory.
            ShellTask tmpTask = new ShellTask("invalid");

            Assert.IsNotNull(tmpTask);

            string tmp = Directory.GetCurrentDirectory();

            Assert.IsNotNull(tmp);

            AvroConfigurationSerializer serializer        = new AvroConfigurationSerializer();
            AvroConfiguration           avroConfiguration = serializer.AvroDeseriaizeFromFile("evaluator.conf");

            Assert.IsNotNull(avroConfiguration);

            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            cb.AddConfiguration(TaskConfiguration.ConfigurationModule
                                .Set(TaskConfiguration.Identifier, "Test_CLRContext_task")
                                .Set(TaskConfiguration.Task, GenericType <ShellTask> .Class)
                                .Build());
            cb.BindNamedParameter <ShellTask.Command, string>(GenericType <ShellTask.Command> .Class, "dir");

            IConfiguration taskConfiguration = cb.Build();

            string taskConfig = serializer.ToString(taskConfiguration);

            ITask             task   = null;
            TaskConfiguration config = new TaskConfiguration(taskConfig);

            Assert.IsNotNull(config);
            try
            {
                IInjector injector = TangFactory.GetTang().NewInjector(config.TangConfig);
                task = (ITask)injector.GetInstance(typeof(ITask));
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("unable to inject task with configuration: " + taskConfig, e);
            }

            byte[] bytes  = task.Call(null);
            string result = System.Text.Encoding.Default.GetString(bytes);

            //a dir command is executed in the container directory, which includes the file "evaluator.conf"
            Assert.IsTrue(result.Contains("evaluator.conf"));
        }
Example #3
0
 private ConfigurationModuleBuilder(ConfigurationModuleBuilder c)
 {
     try
     {
         B.AddConfiguration(c.B.Build());
     }
     catch (BindException e)
     {
         Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
         var ex = new ClassHierarchyException("Build error in ConfigurationModuleBuilder: " + e);
         Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
     }
     ReqDecl.UnionWith(c.ReqDecl);
     OptDecl.UnionWith(c.OptDecl);
     reqUsed.UnionWith(c.reqUsed);
     optUsed.UnionWith(c.optUsed);
     SetOpts.UnionWith(c.SetOpts);
     Map.AddAll(c.Map);
     FreeImpls.AddAll(c.FreeImpls);
     FreeParams.AddAll(c.FreeParams);
     lateBindClazz.AddAll(c.lateBindClazz);
 }