private static void CompileWorkflow( String fileName, String assemblyName) { WorkflowCompiler compiler = new WorkflowCompiler(); WorkflowCompilerParameters parameters = new WorkflowCompilerParameters(); parameters.OutputAssembly = assemblyName; parameters.ReferencedAssemblies.Add("SharedWorkflows.dll"); #if COMPILE_RULES_WORKFLOW //add the .rules file for this workflow as a resource parameters.EmbeddedResources.Add("ProWF.MyNewWorkflowClass.rules"); #endif WorkflowCompilerResults results = compiler.Compile(parameters, fileName); if (results.Errors.Count > 0) { foreach (System.CodeDom.Compiler.CompilerError error in results.Errors) { Console.WriteLine("Compiler error: Line{0}: {1}", error.Line, error.ErrorText); } } }
private static void Main(string[] args) { if ((args == null) || (args.Length != 2)) { throw new ArgumentException(WrapperSR.GetString("InvalidArgumentsToMain"), "args"); } CompilerInput input = ReadCompilerInput(args[0]); WorkflowCompilerResults results = new WorkflowCompiler().Compile(MultiTargetingInfo.MultiTargetingUtilities.RenormalizeReferencedAssemblies(input.Parameters), input.Files); WriteCompilerOutput(args[1], results); }
static void Main(string[] args) { using (WorkflowRuntime workflowRuntime = new WorkflowRuntime()) { AutoResetEvent waitHandle = new AutoResetEvent(false); WorkflowCompiler compiler = new WorkflowCompiler(); WorkflowCompilerParameters compilerParameters = new WorkflowCompilerParameters(); compilerParameters.GenerateInMemory = true; String[] workflowFilenames = GetWorkflowFilenames(); WorkflowCompilerResults results = compiler.Compile(compilerParameters, workflowFilenames); if (results.Errors.Count > 0) { Console.WriteLine("Errors occurred while building the workflow:"); foreach (WorkflowCompilerError compilerError in results.Errors) { Console.WriteLine(compilerError.Line.ToString() + "," + compilerError.Column.ToString() + " : " + compilerError.ErrorText); } return; } Type workflowType = results.CompiledAssembly.GetType("Microsoft.Samples.Workflow.SimpleInMemorySample.SequentialWorkflow"); workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { string orderStatus = e.OutputParameters["Status"].ToString(); Console.WriteLine("Order was " + orderStatus); waitHandle.Set(); }; workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine(e.Exception.Message); waitHandle.Set(); }; Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("Amount", 300); WorkflowInstance instance = workflowRuntime.CreateWorkflow(workflowType, parameters); instance.Start(); waitHandle.WaitOne(); workflowRuntime.StopRuntime(); } }
private void CompileWorkflowButton(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.xamlFile)) { return; } if (!File.Exists(this.xamlFile)) { MessageBox.Show(this, "Cannot locate XAML file: " + Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.Location), xamlFile), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } compileWorkflowButton.Enabled = false; Cursor cursor = this.Cursor; this.Cursor = Cursors.WaitCursor; try { // Compile the workflow String[] assemblyNames = { "ReadEmailActivity.dll" }; WorkflowCompiler compiler = new WorkflowCompiler(); WorkflowCompilerParameters parameters = new WorkflowCompilerParameters(assemblyNames); parameters.LibraryPaths.Add(Path.GetDirectoryName(typeof(BaseMailbox).Assembly.Location)); parameters.OutputAssembly = "CustomOutlookWorkflow" + Guid.NewGuid().ToString() + ".dll"; results = compiler.Compile(parameters, this.xamlFile); StringBuilder errors = new StringBuilder(); foreach (CompilerError compilerError in results.Errors) { errors.Append(compilerError.ToString() + '\n'); } if (errors.Length != 0) { MessageBox.Show(this, errors.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); compileWorkflowButton.Enabled = true; } else { MessageBox.Show(this, "Workflow compiled successfully. Compiled assembly:\n" + results.CompiledAssembly.GetName(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); startWorkflowButton.Enabled = true; } } finally { this.Cursor = cursor; } }
public async Task ListRunningTask() { Mock <IScriptImportService> importservice = new Mock <IScriptImportService>(); importservice.Setup(s => s.Clone(It.IsAny <WorkableLogger>())).Returns(() => importservice.Object); IEntityManager database = TestSetup.CreateMemoryDatabase(); CacheService cache = new CacheService(new NullLogger <CacheService>()); IScriptCompiler compiler = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, new Mock <IArchiveService>().Object, importservice.Object, null, null); WorkflowCompiler workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, null, compiler); ITaskService taskservice = new DatabaseTaskService(database); WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), taskservice, null, null, workflowcompiler); WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure { Name = "JS Test", Nodes = new[] { new NodeData { Type = NodeType.Start }, new NodeData { Type = NodeType.Node, } }, Transitions = new[] { new IndexTransition { OriginIndex = 0, TargetIndex = 1 }, new IndexTransition { OriginIndex = 1, TargetIndex = 0, } } }), new Dictionary <string, object>(), false); Assert.AreEqual(TaskStatus.Running, task.Status); Page <WorkableTask> tasks = await taskservice.ListTasks(); Assert.AreEqual(1, tasks.Total); Assert.AreEqual(1, tasks.Result.Length); task.Token.Cancel(); await Task.WhenAny(task.Task, Task.Delay(1000)); Assert.AreEqual(TaskStatus.Canceled, task.Status); }
public async Task ExecuteJavascriptExpression() { Mock <IScriptImportService> importservice = new Mock <IScriptImportService>(); importservice.Setup(s => s.Clone(It.IsAny <WorkableLogger>())).Returns(() => importservice.Object); IEntityManager database = TestSetup.CreateMemoryDatabase(); CacheService cache = new CacheService(new NullLogger <CacheService>()); IScriptCompiler compiler = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, new Mock <IArchiveService>().Object, importservice.Object, null, null); WorkflowCompiler workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, null, compiler); WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, null, workflowcompiler); WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure { Name = "JS Test", Nodes = new[] { new NodeData { Type = NodeType.Start }, new NodeData { Type = NodeType.Expression, Parameters = new Dictionary <string, object> { ["Code"] = "return a+b", ["Language"] = ScriptLanguage.JavaScript } } }, Transitions = new[] { new IndexTransition { OriginIndex = 0, TargetIndex = 1 }, } }), new Dictionary <string, object> { ["a"] = 3, ["b"] = 4 }, false); await task.Task; Assert.AreEqual(TaskStatus.Success, task.Status); Assert.AreEqual(7, task.Result); }
public async Task ProfileLoopPerformance() { Mock <IScriptImportService> importservice = new Mock <IScriptImportService>(); importservice.Setup(s => s.Clone(It.IsAny <WorkableLogger>())).Returns(() => importservice.Object); IEntityManager database = TestSetup.CreateMemoryDatabase(); CacheService cache = new CacheService(new NullLogger <CacheService>()); IScriptCompiler compiler = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, new Mock <IArchiveService>().Object, importservice.Object, null, null); WorkflowCompiler workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, null, compiler); WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, null, workflowcompiler); WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure { Name = "JS Test", Nodes = new[] { new NodeData { Type = NodeType.Start }, new NodeData { Type = NodeType.Value, Parameters = new Dictionary <string, object> { ["Value"] = "0" }, Variable = "result" }, new NodeData { Type = NodeType.Iterator, Parameters = new Dictionary <string, object> { ["Collection"] = "[1,2,3,4,5]", ["Item"] = "number" }, }, new NodeData { Type = NodeType.BinaryOperation, Parameters = new Dictionary <string, object> { ["Lhs"] = "$result", ["Rhs"] = "$number", ["Op"] = BinaryOperation.Add }, Variable = "result" }, new NodeData { Type = NodeType.Value, Parameters = new Dictionary <string, object> { ["Value"] = "$result" } } }, Transitions = new[] { new IndexTransition { OriginIndex = 0, TargetIndex = 1 }, new IndexTransition { OriginIndex = 1, TargetIndex = 2, }, new IndexTransition { OriginIndex = 2, TargetIndex = 3, Type = TransitionType.Loop, Log = "$\"Adding number {$number}\"" }, new IndexTransition { OriginIndex = 3, TargetIndex = 2 }, new IndexTransition { OriginIndex = 2, TargetIndex = 4 }, } }), new Dictionary <string, object>(), true); await task.Task; Assert.AreEqual(TaskStatus.Success, task.Status); Assert.That(task.Log.Any(l => l.Contains("calls"))); Assert.AreEqual(15, task.Result); }
public async Task ExecuteSubWorkflowWithParametersInLoop() { Mock <IScriptImportService> importservice = new Mock <IScriptImportService>(); importservice.Setup(s => s.Clone(It.IsAny <WorkableLogger>())).Returns(() => importservice.Object); Mock <IArchiveService> archiveservice = new Mock <IArchiveService>(); IEntityManager database = TestSetup.CreateMemoryDatabase(); CacheService cache = new CacheService(new NullLogger <CacheService>()); IScriptCompiler compiler = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, archiveservice.Object, importservice.Object, null, null); IWorkflowService workflowservice = new DatabaseWorkflowService(database, archiveservice.Object); WorkflowCompiler workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, workflowservice, compiler); WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, workflowservice, workflowcompiler); await workflowservice.CreateWorkflow(new WorkflowStructure { Name = "Submarine", Nodes = new [] { new NodeData { Type = NodeType.Start }, new NodeData { Type = NodeType.Value, Parameters = new Dictionary <string, object> { ["Value"] = "$value" } } }, Transitions = new[] { new IndexTransition { OriginIndex = 0, TargetIndex = 1 }, } }); WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure { Name = "Subcall Test", Nodes = new[] { new NodeData { Type = NodeType.Start }, new NodeData { Type = NodeType.Value, Parameters = new Dictionary <string, object> { ["Value"] = "0", }, Variable = "result" }, new NodeData { Type = NodeType.Iterator, Parameters = new Dictionary <string, object> { ["Item"] = "value", ["Collection"] = "[1,2,3,4,5]" } }, new NodeData { Type = NodeType.Workflow, Parameters = new Dictionary <string, object> { ["Name"] = "Submarine", ["Arguments"] = new Dictionary <string, object> { ["value"] = "$value" } }, Variable = "subresult" }, new NodeData { Type = NodeType.BinaryOperation, Parameters = new Dictionary <string, object> { ["Lhs"] = "$result", ["Operation"] = BinaryOperation.Add, ["Rhs"] = "$subresult" }, Variable = "result" }, new NodeData { Type = NodeType.Value, Parameters = new Dictionary <string, object> { ["Value"] = "$result", } }, }, Transitions = new[] { new IndexTransition { OriginIndex = 0, TargetIndex = 1 }, new IndexTransition { OriginIndex = 1, TargetIndex = 2 }, new IndexTransition { OriginIndex = 2, TargetIndex = 3, Type = TransitionType.Loop }, new IndexTransition { OriginIndex = 2, TargetIndex = 5 }, new IndexTransition { OriginIndex = 3, TargetIndex = 4 }, new IndexTransition { OriginIndex = 4, TargetIndex = 2 }, } }), new Dictionary <string, object>(), false); await task.Task; Assert.AreEqual(TaskStatus.Success, task.Status); Assert.AreEqual(15, task.Result); }
public async Task SuspendAndContinueWithParameters() { IEntityManager database = TestSetup.CreateMemoryDatabase(); CacheService cache = new CacheService(new NullLogger <CacheService>()); IScriptCompiler compiler = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, new Mock <IArchiveService>().Object, null, null, null); WorkflowCompiler workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, null, compiler); WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, null, workflowcompiler); WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure { Name = "Test", Nodes = new[] { new NodeData { Type = NodeType.Start }, new NodeData { Type = NodeType.Suspend, Parameters = new Dictionary <string, object> { ["Variable"] = "x" } }, new NodeData { Type = NodeType.Value, Parameters = new Dictionary <string, object> { ["Value"] = 10 } }, new NodeData { Type = NodeType.Value, Parameters = new Dictionary <string, object> { ["Value"] = 5 } } }, Transitions = new[] { new IndexTransition { OriginIndex = 0, TargetIndex = 1, }, new IndexTransition { OriginIndex = 1, TargetIndex = 2, Condition = "$x>=3" }, new IndexTransition { OriginIndex = 1, TargetIndex = 3, } } }), new Dictionary <string, object>(), false); await task.Task; Assert.AreEqual(TaskStatus.Suspended, task.Status); task = await executionservice.Continue(task.Id, new Dictionary <string, object> { ["x"] = 5 }); await task.Task; Assert.AreEqual(TaskStatus.Success, task.Status); Assert.AreEqual(10, task.Result); }
public async Task ProfileSubWorkflow() { Mock <IScriptImportService> importservice = new Mock <IScriptImportService>(); importservice.Setup(s => s.Clone(It.IsAny <WorkableLogger>())).Returns(() => importservice.Object); Mock <IArchiveService> archiveservice = new Mock <IArchiveService>(); IEntityManager database = TestSetup.CreateMemoryDatabase(); CacheService cache = new CacheService(new NullLogger <CacheService>()); IScriptCompiler compiler = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, archiveservice.Object, importservice.Object, null, null); IWorkflowService workflowservice = new DatabaseWorkflowService(database, archiveservice.Object); WorkflowCompiler workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, workflowservice, compiler); WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, workflowservice, workflowcompiler); await workflowservice.CreateWorkflow(new WorkflowStructure { Name = "Submarine", Nodes = new [] { new NodeData { Type = NodeType.Start }, new NodeData { Type = NodeType.Value, Name = "Subvalue", Parameters = new Dictionary <string, object> { ["Value"] = "$job.id" } } }, Transitions = new[] { new IndexTransition { OriginIndex = 0, TargetIndex = 1 }, } }); WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure { Name = "Subcall Test", Nodes = new[] { new NodeData { Type = NodeType.Start }, new NodeData { Type = NodeType.Workflow, Name = "Call Submarine", Parameters = new Dictionary <string, object> { ["Name"] = "Submarine", ["Arguments"] = new Dictionary <string, object> { ["job"] = new Dictionary <string, object> { ["id"] = 1.0 } } } } }, Transitions = new[] { new IndexTransition { OriginIndex = 0, TargetIndex = 1 }, } }), new Dictionary <string, object>(), true); await task.Task; Assert.AreEqual(TaskStatus.Success, task.Status); Assert.That(task.Log.Any(l => l.Contains("calls"))); Assert.AreEqual(1.0, task.Result); }
/// <summary> /// Compile the workflow along with the code beside file and the rules file if they exist /// </summary> public void CompileWorkflow() { if (string.IsNullOrEmpty(this.loader.Xoml)) { return; } if (!File.Exists(this.loader.Xoml)) { MessageBox.Show(this, "Cannot locate XAML file: " + Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.Location), this.loader.Xoml), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // If everything is Ok then save the files before compiling this.Save(); Cursor cursor = this.Cursor; this.Cursor = Cursors.WaitCursor; try { // Check for code beside file and rules file WorkflowCompiler compiler = new WorkflowCompiler(); WorkflowCompilerParameters parameters = new WorkflowCompilerParameters(); string codeBesideFile = Path.Combine(Path.GetDirectoryName(this.loader.Xoml), Path.GetFileNameWithoutExtension(this.loader.Xoml) + ".cs"); string rulesFile = Path.Combine(Path.GetDirectoryName(this.loader.Xoml), Path.GetFileNameWithoutExtension(this.loader.Xoml) + ".rules"); ArrayList files = new ArrayList(); files.Add(this.loader.Xoml); if (File.Exists(codeBesideFile)) { files.Add(codeBesideFile); } if (File.Exists(rulesFile)) { // adding the rules file to the resources string resources = @"/resource:" + rulesFile + "," + this.NameSpace + "." + this.TypeName + "." + "rules"; parameters.CompilerOptions += resources; } object[] objArray = new object[] { }; objArray = files.ToArray(); string[] strArr = new string[objArray.Length]; Array.Copy(objArray, 0, strArr, 0, objArray.Length); // Compile the workflow parameters.ReferencedAssemblies.Add("Dude.dll"); parameters.OutputAssembly = "CustomWorkflow" + Guid.NewGuid().ToString() + ".dll"; WorkflowCompilerResults results = compiler.Compile(parameters, strArr); StringBuilder errors = new StringBuilder(); foreach (CompilerError compilerError in results.Errors) { errors.Append(compilerError.ToString() + '\n'); } if (errors.Length != 0) { MessageBox.Show(this, errors.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(this, "Workflow compiled successfully. Compiled assembly: \n" + results.CompiledAssembly.GetName(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } finally { this.Cursor = cursor; } }
public async Task SumConditionalLoop() { IEntityManager database = TestSetup.CreateMemoryDatabase(); CacheService cache = new CacheService(new NullLogger <CacheService>()); IScriptCompiler compiler = new ScriptCompiler(new NullLogger <ScriptCompiler>(), new ScriptParser(), cache, null, new Mock <IScriptService>().Object, new Mock <IArchiveService>().Object, null, new Mock <IPythonService>().Object, null); WorkflowCompiler workflowcompiler = new WorkflowCompiler(new NullLogger <WorkflowCompiler>(), cache, null, compiler); WorkflowExecutionService executionservice = new WorkflowExecutionService(new NullLogger <WorkflowExecutionService>(), new DatabaseTaskService(database), null, null, workflowcompiler); WorkableTask task = await executionservice.Execute(await workflowcompiler.BuildWorkflow(new WorkflowStructure { Name = "Test", Nodes = new[] { new NodeData { Type = NodeType.Start }, new NodeData { Type = NodeType.Value, Parameters = new Dictionary <string, object> { ["Value"] = 0 }, Variable = "result" }, new NodeData { Type = NodeType.Iterator, Parameters = new Dictionary <string, object> { ["Collection"] = "[1,5,2,2,8,7,4]" } }, new NodeData { Type = NodeType.BinaryOperation, Parameters = new Dictionary <string, object> { ["lhs"] = "$result", ["rhs"] = "$item", ["operation"] = "Add" }, Variable = "result" }, new NodeData { Type = NodeType.Value, Parameters = new Dictionary <string, object> { ["Value"] = "$result" } } }, Transitions = new[] { new IndexTransition { OriginIndex = 0, TargetIndex = 1, }, new IndexTransition { OriginIndex = 1, TargetIndex = 2, }, new IndexTransition { OriginIndex = 2, TargetIndex = 3, Type = TransitionType.Loop, Condition = "$item&1==0" }, new IndexTransition { OriginIndex = 2, TargetIndex = 4, }, new IndexTransition { OriginIndex = 3, TargetIndex = 2 } } }), new Dictionary <string, object>(), false); await task.Task; Assert.AreEqual(Dto.TaskStatus.Success, task.Status); Assert.AreEqual(16, task.Result); }