public static void ProcessAsync(ShellTask taskInfo) { var task = new Task((taskInfoObject) => { var shellTask = (ShellTask)taskInfoObject; ProcessAsyncShellTask(shellTask); return; }, taskInfo); task.Start(); }
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")); }
public void CanInjectAndExecuteTask() { // to enforce that shell task dll be copied to output directory. ShellTask tmpTask = new ShellTask("invalid"); Assert.NotNull(tmpTask); string tmp = Directory.GetCurrentDirectory(); Assert.NotNull(tmp); AvroConfigurationSerializer serializer = new AvroConfigurationSerializer(); AvroConfiguration avroConfiguration = serializer.AvroDeserializeFromFile("evaluator.conf"); Assert.NotNull(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.NotNull(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.True(result.Contains("evaluator.conf")); }
public static void ProcessAsync(this ShellTask taskInfo) { ConcurrentTaskService.ProcessAsync(taskInfo); }
private static void ProcessAsyncShellTask(ShellTask shellTask) { // Force reloading extensions if there were extensions installed // See http://orchard.codeplex.com/workitem/17465 //if (shellTask.MessageName == "IRecipeSchedulerEventHandler.ExecuteWork") //{ // var ctx = _orchardHost().GetShellContext(entry.ShellSettings); //} var shellContext = shellTask.ShellContextFactory.CreateDescribedContext(shellTask.ShellSettings, shellTask.ShellDescriptor); using (shellContext.LifetimeScope) { using (var standaloneEnvironment = shellContext.LifetimeScope.CreateWorkContextScope()) { ILogger logger = NullLogger.Instance; ITransactionManager transactionManager; if (!standaloneEnvironment.TryResolve(out transactionManager)) { transactionManager = null; } try { foreach (var interfaceType in shellTask.ShellAction.Method.DeclaringType.GetInterfaces()) { string methodKey = String.Format("{0}_{1}_{2}", shellTask.ShellAction.GetType().FullName, shellTask.ShellAction.Method.DeclaringType, shellTask.ShellAction.Method.Name); MethodInfo method; if (!_interfaceMethodsCache.TryGetValue(methodKey, out method)) { MethodInfo m = null; if (shellTask.ShellData != null) { m = (from o in interfaceType.GetMethods() where o.Name == shellTask.ShellAction.Method.Name && o.GetParameters().Length == 1 && shellTask.ShellData.GetType().IsAssignableFrom(o.GetParameters()[0].ParameterType) select o).First(); } else { m = (from o in interfaceType.GetMethods() where o.Name == shellTask.ShellAction.Method.Name && o.GetParameters().Length == 1 select o).First(); logger.Information("WARNING: Concurrent Service Began Without Assignment Check. Dangerous!"); } method = _interfaceMethodsCache.GetOrAdd(methodKey, m); } if (method != null) { //DynamicMethod dynamic = new DynamicMethod(string.Empty, //typeof(object), //new Type[0], //target.DeclaringType); //ILGenerator il = dynamic.GetILGenerator(); //il.DeclareLocal(target.DeclaringType); //il.Emit(OpCodes.Newobj, target); //il.Emit(OpCodes.Stloc_0); //il.Emit(OpCodes.Ldloc_0); //il.Emit(OpCodes.Ret); //var y = new { }.ActLike(interfaceType); //Works //IBlockModelService bms; //if (standaloneEnvironment.TryResolve(out bms)) // bms.ProcessModel(shellTask.ShellData); //dynamic x = new ExpandoObject(); //x.i = Activator.CreateInstance(InterfaceHelper.ClassBuilder.Build(interfaceType)); //dynamic o = x.i; object obj; if (Autofac.ResolutionExtensions.TryResolve(shellContext.LifetimeScope, interfaceType, out obj)) { method.Invoke(obj, new object[] { shellTask.ShellData }); } return; } } throw new NotSupportedException("Could not invoke (missing) long running concurrent method using IoC."); } catch { throw; } finally { try { // any database changes in this using(env) scope are invalidated if (transactionManager != null) { try { transactionManager.Cancel(); } catch { } } } catch { } } } } }
internal bool?Init(string[] args) // initalizes the shell { ShellCore = new ShellCore(); ShellUI = new ShellUI(); ShellModule = new ShellModule(); ShellCore.InitShellCore(); ShellCore.CheckCompatibility(); ShellCore.ElmInitExceptionManager(); ShellCore.ShlWriteLog("Test.txt", "test."); ShellUI.InitShellUI(); ShellModule.InitShellModule(ShellCore); ShellTask ShlTask = ShellCore.InitTask(new string[0], "task 1", 400, 150); ShlTask.Run(); ShellTask ShlTask2 = ShellCore.InitTask(new string[0], "task 3", 360, 200); ShlTask2.Run(); Console.Clear(); // so we can do stuff ShellCore.ShlHandleCmdArguments(args); // universal arguments (config - user name...) // SHELL MAIN ARGUMENTS string arg2 = ""; if (args.Length > 0) { for (int i = 0; i < args.Length; i++) { string thearg = args[i]; if (args.Length - i > 0) { arg2 = args[i + 1]; } switch (thearg) { default: ShellUI.ShXML.XmlParseScript(args[0]); Console.WriteLine("Script has completed. Press enter to exit."); Console.ReadKey(); ShellCore.Exit(0); return(null); case "installmodule": ShellModule.InstallModule(false, arg2); Console.WriteLine("Module successfully installed. Press any key to exit Shell."); Console.ReadKey(); return(true); } } } if (ShellCore == null || ShellUI == null) { return(null); } Console.WriteLine("Welcome to Shell\n"); Console.WriteLine("Shell Embedded GUI Platform, version 8.0 alpha\n"); Console.WriteLine("DLL Versions:"); FileVersionInfo shellcore_ver = ShellCore.GetVersion(); FileVersionInfo shellui_ver = ShellUI.GetVersion(); FileVersionInfo shellmodule_ver = ShellModule.GetVersion(); ShellCore.ShlSetWindowTitle($"Shell - core ver {shellcore_ver.FileMajorPart}.{shellcore_ver.FileMinorPart}.{shellcore_ver.FileBuildPart}.{shellcore_ver.FilePrivatePart}."); Console.WriteLine($"ShellCore Version: {shellcore_ver.FileMajorPart}.{shellcore_ver.FileMinorPart}.{shellcore_ver.FileBuildPart}.{shellcore_ver.FilePrivatePart}"); Console.WriteLine($"ShellUI Version: {shellui_ver.FileMajorPart}.{shellui_ver.FileMinorPart}.{shellui_ver.FileBuildPart}.{shellui_ver.FilePrivatePart}\n"); Console.WriteLine($"ShellModule Version: {shellmodule_ver.FileMajorPart}.{shellmodule_ver.FileMinorPart}.{shellmodule_ver.FileBuildPart}.{shellmodule_ver.FilePrivatePart}\n"); ShellUI.ShXML.XmlParseScript("Whatsyourname.xml"); Console.WriteLine("DEBUG: Variables created"); foreach (ShxmlVariable ShxmlVar in ShellUI.ShXML.Varlist) { switch (ShxmlVar.Type) { case 0: Console.WriteLine($"Variable: Name = {ShxmlVar.Name}. Value = {ShxmlVar.varint}. Type = Int."); continue; case 1: Console.WriteLine($"Variable: Name = {ShxmlVar.Name}. Value = {ShxmlVar.varstring}. Type = String."); continue; case 2: Console.WriteLine($"Variable: Name = {ShxmlVar.Name}. Value = {ShxmlVar.varchar}. Type = Char."); continue; case 3: Console.WriteLine($"Variable: Name = {ShxmlVar.Name}. Value = {ShxmlVar.vardouble}. Type = Double."); continue; case 4: Console.WriteLine($"Variable: Name = {ShxmlVar.Name}. Value = {ShxmlVar.varfloat}. Type = Float."); continue; case 5: Console.WriteLine($"Variable: Name = {ShxmlVar.Name}. Value = {ShxmlVar.varbool}. Type = Boolean."); continue; } } Console.ReadKey(); return(true); }