Exemplo n.º 1
0
        private async void ExcuteButton_Click(object sender, RoutedEventArgs e)
        {
            MainWindow.progressDialog.Show();
            try
            {
                ScriptParser  parser = new ScriptParser(Item);
                StringBuilder logs   = new StringBuilder();
                parser.Output += (p1, p2) =>
                {
                    logs.AppendLine(p2);
                };
                await parser.ParseAsync();

                MainWindow.progressDialog.Close();
                await MainWindow.dialog.ShowInfomationAsync(logs.ToString(), FindResource("info_excuteSucceed") as string);;
            }
            catch (Exception ex)
            {
                MainWindow.progressDialog.Close();
                MainWindow.progressDialog.Close();
                await MainWindow.dialog.ShowErrorAsync(ex.ToString(), FindResource("info_excuteSucceed") as string);
            }
        }
Exemplo n.º 2
0
        public async Task ForcedParameterCustomTypeDeepDeserialization()
        {
            IScriptParser parser = new ScriptParser();

            parser.Types.AddType <RecursiveType>();

            Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>();

            compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.Parse(code));
            compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.ParseAsync(code));

            StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters {
                Parameters = new[] {
                    new ParameterDeclaration {
                        Name = "input",
                        Type = "recursivetype",
                    }
                }
            }, compiler.Object);

            Dictionary <string, object> variables = new Dictionary <string, object> {
                ["input"] = new Dictionary <string, object> {
                    ["Type"] = new Dictionary <string, object> {
                        ["Name"]  = "Peter",
                        ["Array"] = new[] {
                            new Dictionary <string, object> {
                                ["Name"] = "Bärbel"
                            }
                        }
                    }
                }
            };
            await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None);

            RecursiveType input = variables["input"] as RecursiveType;

            Assert.NotNull(input);
            Assert.NotNull(input.Type);
            Assert.NotNull(input.Type.Array);
            Assert.AreEqual("Peter", input.Type.Name);
            Assert.AreEqual(1, input.Type.Array.Length);
            Assert.AreEqual("Bärbel", input.Type.Array[0].Name);
        }
Exemplo n.º 3
0
        public async Task ForcedParameterComplexType()
        {
            IScriptParser parser = new ScriptParser();

            parser.Types.AddType <Campaign>();

            Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>();

            compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.Parse(code));
            compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.ParseAsync(code));

            StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters {
                Parameters = new[] {
                    new ParameterDeclaration {
                        Name = "input",
                        Type = "campaign",
                    }
                }
            }, compiler.Object);

            Dictionary <string, object> variables = new Dictionary <string, object> {
                ["input"] = await Json.ReadAsync(typeof(StartNodeTests).Assembly.GetManifestResourceStream("ScriptService.Tests.Data.2020-10-22_campaign.json"))
            };
            await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None);

            Campaign campaign = variables["input"] as Campaign;

            Assert.NotNull(campaign);
        }
Exemplo n.º 4
0
        public async Task ForcedParameterCustomType()
        {
            IScriptParser parser = new ScriptParser();

            parser.Types.AddType <Transition>();

            Mock <IScriptCompiler> compiler = new Mock <IScriptCompiler>();

            compiler.Setup(s => s.CompileCode(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.Parse(code));
            compiler.Setup(s => s.CompileCodeAsync(It.IsAny <string>(), ScriptLanguage.NCScript)).Returns <string, ScriptLanguage>((code, language) => parser.ParseAsync(code));

            StartNode node = new StartNode(Guid.NewGuid(), "Start", new StartParameters {
                Parameters = new[] {
                    new ParameterDeclaration {
                        Name    = "input",
                        Type    = "transition[]",
                        Default = "[{\"Log\": \"\\\"Hello there\\\"\"}]"
                    }
                }
            }, compiler.Object);

            Dictionary <string, object> variables = new Dictionary <string, object>();
            await node.Execute(new WorkflowInstanceState(new WorkflowIdentifier(), null, new StateVariableProvider(variables), s => null, null, null, false), CancellationToken.None);

            Transition[] input = variables["input"] as Transition[];
            Assert.NotNull(input);
            Assert.AreEqual(1, input.Length);
            Assert.AreEqual("\"Hello there\"", input[0].Log);
        }