当前位置: 首页>>代码示例>>C#>>正文


C# Engine.Execute方法代码示例

本文整理汇总了C#中Engine.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Engine.Execute方法的具体用法?C# Engine.Execute怎么用?C# Engine.Execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Engine的用法示例。


在下文中一共展示了Engine.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var engine = new Engine(cfg => cfg.AllowClr())
                .SetValue("print", new Action<object>(Console.WriteLine))
            ;

            var filename = args.Length > 0 ? args[0] : "";
            if (!String.IsNullOrEmpty(filename))
            {
                if (!File.Exists(filename))
                {
                    Console.WriteLine("Could not find file: {0}", filename);
                }

                var script = File.ReadAllText(filename);
                var result = engine.GetValue(engine.Execute(script).GetCompletionValue());
                return;
            }

            Assembly assembly = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
            string version = fvi.FileVersion;

            Console.WriteLine("Welcome to Jint ({0})", version);
            Console.WriteLine("Type 'exit' to leave, 'print()' to write on the console.");
            Console.WriteLine();

            var defaultColor = Console.ForegroundColor;
            while (true)
            {
                Console.ForegroundColor = defaultColor;
                Console.Write("jint> ");
                var input = Console.ReadLine();
                if (input == "exit")
                {
                    return;
                }

                try
                {
                    var result = engine.GetValue(engine.Execute(input).GetCompletionValue());
                    if (result.Type != Types.None && result.Type != Types.Null && result.Type != Types.Undefined)
                    {
                        var str = TypeConverter.ToString(engine.Json.Stringify(engine.Json, Arguments.From(result, Undefined.Instance, "  ")));
                        Console.WriteLine("=> {0}", str);
                    }
                }
                catch (JavaScriptException je)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(je.ToString());
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(e.Message);
                }
                
            }
        }
开发者ID:BusinessActs,项目名称:jint,代码行数:60,代码来源:Program.cs

示例2: Engine

 public void 助詞によって引数の順番を切り替える()
 {
     // 副作用を有り。
     var engine = new Engine();
     string[] codes = {
         "「A」が「B」を「C」にテストする。" ,
         "「A」が「C」に「B」をテストする。" ,
         "「B」を「A」が「C」にテストする。" ,
         "「B」を「C」に「A」がテストする。" ,
         "「C」に「A」が「B」をテストする。" ,
         "「C」に「B」を「A」がテストする。"};
     engine.Global.SetVariable("テスト", new SuffixFunc<Func<object, object, object, object>>(
         (a, b, c) => ((string)a == "A" && (string)b == "B" && (string)c == "C"),
         "が", "を", "に"));
     foreach (var code in codes) {
         Assert.IsTrue((bool)engine.Execute(code, Statics.TestName));
     }
     var defun =
         "以下の定義でAがBをCにテストする。" +
         "	[A,B,C]を文字列連結する。" +
         "以上。";
     engine.Execute(defun, Statics.TestName);
     foreach (var code in codes) {
         Assert.AreEqual("ABC", (string)engine.Execute(code, Statics.TestName));
     }
 }
开发者ID:irxground,项目名称:kurogane,代码行数:26,代码来源:Behavior.cs

示例3: CanConvertEnumsToString

 public void CanConvertEnumsToString()
 {
     var engine1 = new Engine(o => o.AddObjectConverter(new EnumsToStringConverter()))
         .SetValue("assert", new Action<bool>(Assert.True));
     engine1.SetValue("p", new { Comparison = StringComparison.CurrentCulture });
     engine1.Execute("assert(p.Comparison === 'CurrentCulture');");
     engine1.Execute("var result = p.Comparison;");
     Assert.Equal("CurrentCulture", (string)engine1.GetValue("result").ToObject());
 }
开发者ID:honestegg,项目名称:jint,代码行数:9,代码来源:InteropTests.cs

示例4: OrderByOrdersDescendingThenByInDescendingOrder

        public void OrderByOrdersDescendingThenByInDescendingOrder()
        {
            // Given
            List<string> content = new List<string>();
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            CountModule count = new CountModule("A")
            {
                AdditionalOutputs = 4
            };
            CountModule count2 = new CountModule("B")
            {
                AdditionalOutputs = 1
            };
            OrderBy orderBy = new OrderBy((d, c) => d.Get<int>("A"))
                .Descending()
                .ThenBy((d, c) => d.Get<int>("B"))
                .Descending();
            Execute gatherData = new Execute((d, c) =>
            {
                content.Add(d.Content);
                return null;
            });
            engine.Pipelines.Add(count, count2, orderBy, gatherData);

            // When
            engine.Execute();

            // Then
            Assert.AreEqual(10, content.Count); // (4+1) * (21+1)
            CollectionAssert.AreEqual(new[] { "510", "59", "48", "47", "36", "35", "24", "23", "12", "11" }, content);
        }
开发者ID:st1pps,项目名称:Wyam,代码行数:32,代码来源:OrderByFixture.cs

示例5: ContentAndMetadataReturnsCorrectDocuments

        public void ContentAndMetadataReturnsCorrectDocuments()
        {
            // Given
            List<string> content = new List<string>();
            List<object> values = new List<object>();
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            Core.Modules.Documents documents = new Core.Modules.Documents(
                Tuple.Create("A", new Dictionary<string, object> { { "Foo", "a" } }.AsEnumerable()),
                Tuple.Create("B", new Dictionary<string, object> { { "Foo", "b" } }.AsEnumerable()),
                Tuple.Create("C", new Dictionary<string, object> { { "Foo", "c" } }.AsEnumerable()));
            Execute gatherData = new Execute((d, c) =>
            {
                content.Add(d.Content);
                values.Add(d["Foo"]);
                return null;
            });
            engine.Pipelines.Add(documents, gatherData);

            // When
            engine.Execute();

            // Then
            Assert.AreEqual(3, content.Count);
            Assert.AreEqual(3, values.Count);
            CollectionAssert.AreEqual(new[] { "A", "B", "C" }, content);
            CollectionAssert.AreEqual(new[] { "a", "b", "c" }, values);
        }
开发者ID:JasonKoopmans,项目名称:Wyam,代码行数:28,代码来源:DocumentsFixture.cs

示例6: SetsDocumentsInMetadata

            public void SetsDocumentsInMetadata()
            {
                // Given
                List<IList<string>> content = new List<IList<string>>();
                Engine engine = new Engine();
                engine.CleanOutputPathOnExecute = false;
                CountModule count = new CountModule("A")
                {
                    AdditionalOutputs = 7
                };
                GroupBy groupBy = new GroupBy((d, c) => d.Get<int>("A")%3, count);
                OrderBy orderBy = new OrderBy((d, c) => d.Get<int>(Keys.GroupKey));
                Execute gatherData = new Execute((d, c) =>
                {
                    content.Add(d.Get<IList<IDocument>>(Keys.GroupDocuments).Select(x => x.Content).ToList());
                    return null;
                });
                engine.Pipelines.Add(groupBy, orderBy, gatherData);

                // When
                engine.Execute();

                // Then
                Assert.AreEqual(3, content.Count);
                CollectionAssert.AreEquivalent(new[] {"3", "6"}, content[0]);
                CollectionAssert.AreEquivalent(new[] {"1", "4", "7"}, content[1]);
                CollectionAssert.AreEquivalent(new[] {"2", "5", "8"}, content[2]);
            }
开发者ID:ryanrousseau,项目名称:Wyam,代码行数:28,代码来源:GroupByTests.cs

示例7: ResultsInCorrectCountsWithPredicate

            public void ResultsInCorrectCountsWithPredicate()
            {
                // Given
                Engine engine = new Engine();
                engine.CleanOutputPathOnExecute = false;
                CountModule a = new CountModule("A")
                {
                    AdditionalOutputs = 1
                };
                CountModule b = new CountModule("B")
                {
                    AdditionalOutputs = 2
                };
                CountModule c = new CountModule("C")
                {
                    AdditionalOutputs = 3
                };
                engine.Pipelines.Add(a, new Branch(b).Where((x, y) => x.Content == "1"), c);

                // When
                engine.Execute();

                // Then
                Assert.AreEqual(1, a.ExecuteCount);
                Assert.AreEqual(1, b.ExecuteCount);
                Assert.AreEqual(1, c.ExecuteCount);
                Assert.AreEqual(1, a.InputCount);
                Assert.AreEqual(1, b.InputCount);
                Assert.AreEqual(2, c.InputCount);
                Assert.AreEqual(2, a.OutputCount);
                Assert.AreEqual(3, b.OutputCount);
                Assert.AreEqual(8, c.OutputCount);
            }
开发者ID:ryanrousseau,项目名称:Wyam,代码行数:33,代码来源:BranchTests.cs

示例8: ShouldInterpretLiterals

        public void ShouldInterpretLiterals(object expected, string source)
        {
            var engine = new Engine();
            var result = engine.Execute(source).GetCompletionValue().ToObject();

            Assert.Equal(expected, result);
        }
开发者ID:RobKellett,项目名称:2Soon,代码行数:7,代码来源:EngineTests.cs

示例9: PaginateSetsCorrectMetadata

        public void PaginateSetsCorrectMetadata()
        {
            // Given
            List<int> currentPage = new List<int>();
            List<int> totalPages = new List<int>();
            List<bool> hasNextPage = new List<bool>();
            List<bool> hasPreviousPage = new List<bool>();
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            CountModule count = new CountModule("A")
            {
                AdditionalOutputs = 7
            };
            Paginate paginate = new Paginate(3, count);
            Execute gatherData = new Execute((d, c) =>
            {
                currentPage.Add(d.Get<int>(Keys.CurrentPage));
                totalPages.Add(d.Get<int>(Keys.TotalPages));
                hasNextPage.Add(d.Get<bool>(Keys.HasNextPage));
                hasPreviousPage.Add(d.Get<bool>(Keys.HasPreviousPage));
                return null;
            });
            engine.Pipelines.Add(paginate, gatherData);

            // When
            engine.Execute();

            // Then
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, currentPage);
            CollectionAssert.AreEqual(new[] { 3, 3, 3 }, totalPages);
            CollectionAssert.AreEqual(new[] { true, true, false }, hasNextPage);
            CollectionAssert.AreEqual(new[] { false, true, true }, hasPreviousPage);
        }
开发者ID:martinvobr,项目名称:Wyam,代码行数:33,代码来源:PaginateFixture.cs

示例10: MetadataReturnsCorrectDocuments

        public void MetadataReturnsCorrectDocuments()
        {
            // Given
            List<object> values = new List<object>();
            Engine engine = new Engine();
            engine.CleanOutputFolderOnExecute = false;
            engine.Trace.AddListener(new TestTraceListener());
            Core.Modules.Control.Documents documents = new Core.Modules.Control.Documents(
                new Dictionary<string, object> { { "Foo", "a" } },
                new Dictionary<string, object> { { "Foo", "b" } },
                new Dictionary<string, object> { { "Foo", "c" } });
            Execute gatherData = new Execute((d, c) =>
            {
                values.Add(d["Foo"]);
                return null;
            });
            engine.Pipelines.Add(documents, gatherData);

            // When
            engine.Execute();

            // Then
            Assert.AreEqual(3, values.Count);
            CollectionAssert.AreEqual(new[] { "a", "b", "c" }, values);
        }
开发者ID:Chandu,项目名称:Wyam,代码行数:25,代码来源:DocumentsFixture.cs

示例11: PaginateSetsDocumentsInMetadata

        public void PaginateSetsDocumentsInMetadata()
        {
            // Given
            List<IList<string>> content = new List<IList<string>>();
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            CountModule count = new CountModule("A")
            {
                AdditionalOutputs = 7
            };
            Paginate paginate = new Paginate(3, count);
            Execute gatherData = new Execute((d, c) =>
            {
                content.Add(d.Get<IList<IDocument>>(Keys.PageDocuments).Select(x => x.Content).ToList());
                return null;
            });
            engine.Pipelines.Add(paginate, gatherData);

            // When
            engine.Execute();

            // Then
            Assert.AreEqual(3, content.Count);
            CollectionAssert.AreEqual(new[] { "1", "2", "3" }, content[0]);
            CollectionAssert.AreEqual(new[] { "4", "5", "6" }, content[1]);
            CollectionAssert.AreEqual(new[] { "7", "8" }, content[2]);
        }
开发者ID:martinvobr,项目名称:Wyam,代码行数:27,代码来源:PaginateFixture.cs

示例12: GroupBySetsCorrectMetadata

        public void GroupBySetsCorrectMetadata()
        {
            // Given
            List<int> groupKey = new List<int>();
            Engine engine = new Engine();
            engine.CleanOutputFolderOnExecute = false;
            engine.Trace.AddListener(new TestTraceListener());
            CountModule count = new CountModule("A")
            {
                AdditionalOutputs = 7
            };
            GroupBy groupBy = new GroupBy((d, c) => d.Get<int>("A") % 3, count);
            Execute gatherData = new Execute((d, c) =>
            {
                groupKey.Add(d.Get<int>(Keys.GroupKey));
                return null;
            });
            engine.Pipelines.Add(groupBy, gatherData);

            // When
            engine.Execute();

            // Then
            CollectionAssert.AreEquivalent(new[] { 0, 1, 2 }, groupKey);
        }
开发者ID:Chandu,项目名称:Wyam,代码行数:25,代码来源:GroupByFixture.cs

示例13: ChildModulesAreExecuted

            public void ChildModulesAreExecuted()
            {
                // Given
                Engine engine = new Engine();
                engine.CleanOutputPathOnExecute = false;
                CountModule a = new CountModule("A")
                {
                    AdditionalOutputs = 1
                };
                CountModule b = new CountModule("B")
                {
                    AdditionalOutputs = 2
                };
                CountModule c = new CountModule("C")
                {
                    AdditionalOutputs = 3
                };
                engine.Pipelines.Add(a, new Core.Modules.Control.ModuleCollection(b, c));

                // When
                engine.Execute();

                // Then
                Assert.AreEqual(1, a.ExecuteCount);
                Assert.AreEqual(1, b.ExecuteCount);
                Assert.AreEqual(1, c.ExecuteCount);
                Assert.AreEqual(1, a.InputCount);
                Assert.AreEqual(2, b.InputCount);
                Assert.AreEqual(6, c.InputCount);
                Assert.AreEqual(2, a.OutputCount);
                Assert.AreEqual(6, b.OutputCount);
                Assert.AreEqual(24, c.OutputCount);
            }
开发者ID:ryanrousseau,项目名称:Wyam,代码行数:33,代码来源:ModuleCollectionTests.cs

示例14: IfResultsInCorrectCounts

        public void IfResultsInCorrectCounts()
        {
            // Given
            Engine engine = new Engine();
            engine.Trace.AddListener(new TestTraceListener());
            CountModule a = new CountModule("A")
            {
                AdditionalOutputs = 2
            };
            CountModule b = new CountModule("B")
            {
                AdditionalOutputs = 2
            };
            CountModule c = new CountModule("C")
            {
                AdditionalOutputs = 3
            };
            engine.Pipelines.Add(a, new If((x, y) => x.Content == "1", b), c);

            // When
            engine.Execute();

            // Then
            Assert.AreEqual(1, a.ExecuteCount);
            Assert.AreEqual(1, b.ExecuteCount);
            Assert.AreEqual(1, c.ExecuteCount);
            Assert.AreEqual(1, a.InputCount);
            Assert.AreEqual(1, b.InputCount);
            Assert.AreEqual(5, c.InputCount);
            Assert.AreEqual(3, a.OutputCount);
            Assert.AreEqual(3, b.OutputCount);
            Assert.AreEqual(20, c.OutputCount);
        }
开发者ID:martinvobr,项目名称:Wyam,代码行数:33,代码来源:IfFixture.cs

示例15: RunBumpersTest

 public void RunBumpersTest()
 {
     Engine<string> engine = new Engine<string>(new RuleCollection<string>()) { RunBumperRules = true };
     var result = engine.Execute("blah");
     Assert.IsNotNull(result);
     Assert.AreEqual(2, result.Count);
 }
开发者ID:wbsimms,项目名称:LogicEngine,代码行数:7,代码来源:EngineTest.cs


注:本文中的Engine.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。