public Task <ProcessContext> CreateTask(IModule module, Dictionary <IModule, Task <ProcessContext> > antecedentTasks) { if (!_antecedentsPerModule.ContainsKey(module)) { _antecedentsPerModule[module] = _edges.Where(e => e.Subsequent.Equals(module)).Select(e => e.Antecedent); } IEnumerable <Task> dependents = dependents = _antecedentsPerModule[module].Select(m => antecedentTasks[m]); long numDependents = dependents.Count(); if (numDependents > 0) { var context = GetProcessContext(module, m => antecedentTasks[m].Result); return(Task.Factory.ContinueWhenAll(dependents.ToArray(), t => { module.Execute(context); return context; })); } { var context = GetProcessContext(module, m => antecedentTasks[m].Result); return(Task.Factory.StartNew(() => { module.Execute(context); return context; })); } }
public void Execute(IJobExecutionContext context) { int index = context.JobDetail.JobDataMap.GetIntValue("index"); try { IModule mod = Modules[index].Module; mod.Execute(ServiceContext.Recorder); } catch (KeyNotFoundException) { log.Error($"Работа с индексом {index} не найдена в списке"); } catch (Exception) { log.Error($"При выполнении задания произошла ошибка"); } }
public static void Execute(string typeName, string[] args) { if (string.IsNullOrWhiteSpace(typeName)) { Console.WriteLine("请输入类型名"); return; } var assembly = Assembly.GetExecutingAssembly(); string assemblyName = assembly.GetName().Name; IModule obj = assembly.CreateInstance(string.Format("{0}.Module.{1}", assemblyName, typeName)) as IModule; if (null == obj) { Console.WriteLine("无法找到对应类型:{0}", typeName); return; } obj.Execute(args); }
protected override bool Pulse() { Module.Execute(Arguments); return(false); // Do not keep executing. }
public static void RunCommand(string command) { string[] args = CommandInterpreter.ParseCommand(command); if (args.Length > 0) { switch (args[0].ToLower()) { case "exit": Application.Exit(); break; case "mmrl": ModuleManager.UnloadModules(); ModuleManager.LoadModules(Settings.ModulePath, false); break; case "settings": string[] setargs = new string[args.Length - 1]; Array.Copy(args, 1, setargs, 0, setargs.Length); Settings.Execute(setargs); break; case "task": // Will create a task on a separate thread to run the input following "task" // as a module command. string[] modargs = new string[args.Length - 1]; Array.Copy(args, 1, modargs, 0, modargs.Length); Scheduler.AddTask(modargs); break; default: // Default command line action is to interpret the input as a module command // and execute the module on the same thread. Modules must already be loaded to be received. // Will execute all modules registered with that command in the order of loading. if (args.Length > 0) { string cmd = args[0]; // See if the second argument is a module command. if (ModuleManager.CommandRegistry.ContainsKey(cmd)) { IModule mod = ModuleManager.GetExistingModule(ModuleManager.CommandRegistry[cmd]); mod.OnLoad(); if (args.Length > 1) { string[] extraargs = new string[args.Length - 1]; Array.Copy(args, 1, extraargs, 0, extraargs.Length); mod.Execute(extraargs); } else { mod.Execute(new string[] { }); } mod.OnExit(); } else { Core.Output("Command not recognized. No module loaded with registered command '" + cmd + "'."); } } break; } } }
public void TestTransform() { // Given string xsltInput = string.Empty + "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">" + "<xsl:template match=\"bookstore\">" + " <HTML>" + " <BODY>" + " <TABLE BORDER=\"2\">" + " <TR>" + " <TD>ISBN</TD>" + " <TD>Title</TD>" + " <TD>Price</TD>" + " </TR>" + " <xsl:apply-templates select=\"book\"/>" + " </TABLE>" + " </BODY>" + " </HTML>" + "</xsl:template>" + "<xsl:template match=\"book\">" + " <TR>" + " <TD><xsl:value-of select=\"@ISBN\"/></TD>" + " <TD><xsl:value-of select=\"title\"/></TD>" + " <TD><xsl:value-of select=\"price\"/></TD>" + " </TR>" + "</xsl:template>" + "</xsl:stylesheet>"; string input = string.Empty + "<?xml version='1.0'?>" + "<!-- This file represents a fragment of a book store inventory database -->" + "<bookstore>" + " <book genre=\"autobiography\" publicationdate=\"1981\" ISBN=\"1-861003-11-0\">" + " <title>The Autobiography of Benjamin Franklin</title>" + " <author>" + " <first-name>Benjamin</first-name>" + " <last-name>Franklin</last-name>" + " </author>" + " <price>8.99</price>" + " </book>" + " <book genre=\"novel\" publicationdate=\"1967\" ISBN=\"0-201-63361-2\">" + " <title>The Confidence Man</title>" + " <author>" + " <first-name>Herman</first-name>" + " <last-name>Melville</last-name>" + " </author>" + " <price>11.99</price>" + " </book>" + " <book genre=\"philosophy\" publicationdate=\"1991\" ISBN=\"1-861001-57-6\">" + " <title>The Gorgias</title>" + " <author>" + " <name>Plato</name>" + " </author>" + " <price>9.99</price>" + " </book>" + "</bookstore>"; string output = "<HTML>" + "\n" + " <BODY>" + "\n" + " <TABLE BORDER=\"2\">" + "\n" + " <TR>" + "\n" + " <TD>ISBN</TD>" + "\n" + " <TD>Title</TD>" + "\n" + " <TD>Price</TD>" + "\n" + " </TR>" + "\n" + " <TR>" + "\n" + " <TD>1-861003-11-0</TD>" + "\n" + " <TD>The Autobiography of Benjamin Franklin</TD>" + "\n" + " <TD>8.99</TD>" + "\n" + " </TR>" + "\n" + " <TR>" + "\n" + " <TD>0-201-63361-2</TD>" + "\n" + " <TD>The Confidence Man</TD>" + "\n" + " <TD>11.99</TD>" + "\n" + " </TR>" + "\n" + " <TR>" + "\n" + " <TD>1-861001-57-6</TD>" + "\n" + " <TD>The Gorgias</TD>" + "\n" + " <TD>9.99</TD>" + "\n" + " </TR>" + "\n" + " </TABLE>" + "\n" + " </BODY>" + "\n" + "</HTML>"; TestExecutionContext context = new TestExecutionContext(); TestDocument document = new TestDocument(input); TestDocument xsltDocument = new TestDocument(xsltInput); IModule module = Substitute.For <IModule>(); module.Execute(Arg.Any <IReadOnlyList <IDocument> >(), Arg.Any <IExecutionContext>()).Returns(new IDocument[] { xsltDocument }); Xslt2 xslt2 = new Xslt2(module); // When IList <IDocument> results = xslt2.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then Assert.That(results.Select(x => x.Content), Is.EquivalentTo(new[] { output })); }
public void TestTransform2() { // Given string xsltInput = string.Empty + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" + "<xsl:stylesheet version=\"2.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >" + "\n" + "<xsl:output method=\"xml\" indent=\"yes\" />" + "\n" + string.Empty + "\n" + "<xsl:template match=\"world\">" + "\n" + " <div>" + "\n" + " <xsl:for-each-group select=\"country\" group-by=\"@continent\">" + "\n" + " <div>" + "\n" + " <h1><xsl:value-of select=\"@continent\" /></h1>" + "\n" + " <xsl:for-each select=\"current-group()\">" + "\n" + " <p>" + "\n" + " <xsl:value-of select=\"@name\" />" + "\n" + " </p>" + "\n" + " </xsl:for-each>" + "\n" + " </div>" + "\n" + " </xsl:for-each-group>" + "\n" + " </div>" + "\n" + "</xsl:template>" + "\n" + "</xsl:stylesheet>"; string input = string.Empty + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<world>" + "<country name=\"Canada\" continent=\"North America\" />" + "<country name=\"Jamaica\" continent=\"North America\" />" + "<country name=\"United States\" continent=\"North America\" />" + "<country name=\"United Kingdom\" continent=\"Europe\" />" + "<country name=\"France\" continent=\"Europe\" />" + "<country name=\"Japan\" continent=\"Asia\" />" + "</world>"; string output = string.Empty + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" + "<div>" + "\n" + " <div>" + "\n" + " <h1>North America</h1>" + "\n" + " <p>Canada</p>" + "\n" + " <p>Jamaica</p>" + "\n" + " <p>United States</p>" + "\n" + " </div>" + "\n" + " <div>" + "\n" + " <h1>Europe</h1>" + "\n" + " <p>United Kingdom</p>" + "\n" + " <p>France</p>" + "\n" + " </div>" + "\n" + " <div>" + "\n" + " <h1>Asia</h1>" + "\n" + " <p>Japan</p>" + "\n" + " </div>" + "\n" + "</div>" + "\n"; TestExecutionContext context = new TestExecutionContext(); TestDocument document = new TestDocument(input); TestDocument xsltDocument = new TestDocument(xsltInput); IModule module = Substitute.For <IModule>(); module.Execute(Arg.Any <IReadOnlyList <IDocument> >(), Arg.Any <IExecutionContext>()).Returns(new IDocument[] { xsltDocument }); Xslt2 xslt2 = new Xslt2(module); // When IList <IDocument> results = xslt2.Execute(new[] { document }, context).ToList(); // Make sure to materialize the result list // Then Assert.That(results.Select(x => x.Content), Is.EquivalentTo(new[] { output })); }
public List <Profile> ExectueModule() { return(_module.Execute(this)); }