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


C# CalculationEngine类代码示例

本文整理汇总了C#中CalculationEngine的典型用法代码示例。如果您正苦于以下问题:C# CalculationEngine类的具体用法?C# CalculationEngine怎么用?C# CalculationEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: BenchMarkCalculationEngineRandomFunctionBuild

        private static void BenchMarkCalculationEngineRandomFunctionBuild(CalculationEngine engine, List<string> functions, 
            int numberOfTests)
        {
            Random random = new Random();

            DateTime start = DateTime.Now;

            Parallel.ForEach(functions,(functionText)=>
                {
                    Func<int, int, int, double> function = (Func<int, int, int, double>)engine.Formula(functionText)
                        .Parameter("var1", DataType.Integer)
                        .Parameter("var2", DataType.Integer)
                        .Parameter("var3", DataType.Integer)
                        .Result(DataType.FloatingPoint)
                        .Build();

                    for (int i = 0; i < numberOfTests; i++)
                    {
                        function(random.Next(), random.Next(), random.Next());
                    }
                });

            DateTime end = DateTime.Now;

            Console.WriteLine("Total duration: {0}", end - start);
        }
开发者ID:kityandhero,项目名称:Jace,代码行数:26,代码来源:Program.cs

示例2: TestCalculateFormula1

        public void TestCalculateFormula1()
        {
            CalculationEngine engine = new CalculationEngine();
            double result = engine.Calculate("2+3");

            Assert.AreEqual(5.0, result);
        }
开发者ID:pcmichaels,项目名称:Jace,代码行数:7,代码来源:CalculationEngineTests.cs

示例3: Register

 public static void Register(CalculationEngine ce)
 {
     //ce.RegisterFunction("ASC	Changes full-width (double-byte) English letters or katakana within a character string to half-width (single-byte) characters
     //ce.RegisterFunction("BAHTTEXT	Converts a number to text, using the ß (baht) currency format
     ce.RegisterFunction("CHAR", 1, _Char); // Returns the character specified by the code number
     //ce.RegisterFunction("CLEAN	Removes all nonprintable characters from text
     ce.RegisterFunction("CODE", 1, Code); // Returns a numeric code for the first character in a text string
     ce.RegisterFunction("CONCATENATE", 1, int.MaxValue, Concat); //	Joins several text items into one text item
     //ce.RegisterFunction("DOLLAR	Converts a number to text, using the $ (dollar) currency format
     //ce.RegisterFunction("EXACT	Checks to see if two text values are identical
     ce.RegisterFunction("FIND", 2, 3, Find); //Finds one text value within another (case-sensitive)
     //ce.RegisterFunction("FIXED	Formats a number as text with a fixed number of decimals
     //ce.RegisterFunction("JIS	Changes half-width (single-byte) English letters or katakana within a character string to full-width (double-byte) characters
     ce.RegisterFunction("LEFT", 1, 2, Left); // LEFTB	Returns the leftmost characters from a text value
     ce.RegisterFunction("LEN", 1, Len); //, Returns the number of characters in a text string
     ce.RegisterFunction("LOWER", 1, Lower); //	Converts text to lowercase
     ce.RegisterFunction("MID", 3, Mid); // Returns a specific number of characters from a text string starting at the position you specify
     //ce.RegisterFunction("PHONETIC	Extracts the phonetic (furigana) characters from a text string
     ce.RegisterFunction("PROPER", 1, Proper); // Capitalizes the first letter in each word of a text value
     ce.RegisterFunction("REPLACE", 4, Replace); // Replaces characters within text
     ce.RegisterFunction("REPT", 2, Rept); // Repeats text a given number of times
     ce.RegisterFunction("RIGHT", 1, 2, Right); // Returns the rightmost characters from a text value
     ce.RegisterFunction("SEARCH", 2, Search); // Finds one text value within another (not case-sensitive)
     ce.RegisterFunction("SUBSTITUTE", 3, 4, Substitute); // Substitutes new text for old text in a text string
     ce.RegisterFunction("T", 1, T); // Converts its arguments to text
     ce.RegisterFunction("TEXT", 2, _Text); // Formats a number and converts it to text
     ce.RegisterFunction("TRIM", 1, Trim); // Removes spaces from text
     ce.RegisterFunction("UPPER", 1, Upper); // Converts text to uppercase
     ce.RegisterFunction("VALUE", 1, Value); // Converts a text argument to a number
 }
开发者ID:AtwooTM,项目名称:ZCalcEngine,代码行数:30,代码来源:Text.cs

示例4: TestBatchLoad

        public void TestBatchLoad()
        {
            // Test that we can add expressions in any order
            CalculationEngine engine = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();

            int interest = 2;
            context.Variables.Add("interest", interest);

            BatchLoader loader = engine.CreateBatchLoader();

            loader.Add("c", "a + b", context);
            loader.Add("a", "100 + interest", context);
            loader.Add("b", "a + 1 + a", context);
            // Test an expression with a reference in a string
            loader.Add("d", "\"str \\\" str\" + a + \"b\"", context);

            engine.BatchLoad(loader);

            int result = engine.GetResult<int>("b");
            Assert.AreEqual((100 + interest) + 1 + (100 + interest), result);

            interest = 300;
            context.Variables["interest"] = interest;
            engine.Recalculate("a");

            result = engine.GetResult<int>("b");
            Assert.AreEqual((100 + interest) + 1 + (100 + interest), result);

            result = engine.GetResult<int>("c");
            Assert.AreEqual((100 + interest) + 1 + (100 + interest) + (100 + interest), result);

            Assert.AreEqual("str \" str400b", engine.GetResult<string>("d"));
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:34,代码来源:CalcEngineTestFixture.cs

示例5: TestCalculateCosineFunctionInterpreted

        public void TestCalculateCosineFunctionInterpreted()
        {
            CalculationEngine engine = new CalculationEngine(CultureInfo.InvariantCulture, ExecutionMode.Interpreted);
            double result = engine.Calculate("cos(41)");

            Assert.AreEqual(Math.Cos(41.0), result);
        }
开发者ID:pcmichaels,项目名称:Jace,代码行数:7,代码来源:CalculationEngineTests.cs

示例6: Main

        /// <summary>
        /// The main entry point for the application
        /// </summary>
        static void Main(string[] args)
        {
            try
            {
                Settings settings;
                if (!TryInitialize(out settings))
                {
                    Usage();
                    return;
                }

                var engine = new CalculationEngine(settings);
                engine.Run();

                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();

                Console.WriteLine("\n{0} | Exiting...", DateTime.Now);
                engine.Stop();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                Usage();
            }
        }
开发者ID:NearIntegration,项目名称:PI-AF-SDK-large-asset-count-Project,代码行数:30,代码来源:Program.cs

示例7: TestCalculateFormulaVariableNotDefinedInterpreted

        public void TestCalculateFormulaVariableNotDefinedInterpreted()
        {
            Dictionary<string, double> variables = new Dictionary<string, double>();
            variables.Add("var1", 2.5);

            CalculationEngine engine = new CalculationEngine(CultureInfo.InvariantCulture, ExecutionMode.Interpreted);
            double result = engine.Calculate("var1*var2", variables);
        }
开发者ID:plurby,项目名称:Jace,代码行数:8,代码来源:CalculationEngineTests.cs

示例8: Register

 public static void Register(CalculationEngine ce)
 {
     ce.RegisterFunction("AND" , 1 , int.MaxValue , And);
     ce.RegisterFunction("OR"  , 1 , int.MaxValue , Or);
     ce.RegisterFunction("NOT"   , 1 , Not);
     ce.RegisterFunction("IF"    , 3 , If);
     ce.RegisterFunction("TRUE"  , 0 , True);
     ce.RegisterFunction("FALSE" , 0 , False);
 }
开发者ID:AtwooTM,项目名称:ZCalcEngine,代码行数:9,代码来源:Logical.cs

示例9: TestCalculateFormulaVariableNotDefinedCompiled

        public void TestCalculateFormulaVariableNotDefinedCompiled()
        {
            Dictionary<string, double> variables = new Dictionary<string, double>();
            variables.Add("var1", 2.5);

            AssertExtensions.ThrowsException<VariableNotDefinedException>(() =>
                {
                    CalculationEngine engine = new CalculationEngine(CultureInfo.InvariantCulture, ExecutionMode.Compiled);
                    double result = engine.Calculate("var1*var2", variables);
                });
        }
开发者ID:pcmichaels,项目名称:Jace,代码行数:11,代码来源:CalculationEngineTests.cs

示例10: TestBuild

        public void TestBuild()
        {
            CalculationEngine engine = new CalculationEngine();
            Func<Dictionary<string, double>, double> function = engine.Build("var1+2*(3*age)");

            Dictionary<string, double> variables = new Dictionary<string, double>();
            variables.Add("var1", 2);
            variables.Add("age", 4);

            double result = function(variables);
            Assert.AreEqual(26.0, result);
        }
开发者ID:pcmichaels,项目名称:Jace,代码行数:12,代码来源:CalculationEngineTests.cs

示例11: BenchMarkCalculationEngine

        private static void BenchMarkCalculationEngine(CalculationEngine engine, string functionText)
        {
            DateTime start = DateTime.Now;

            for (int i = 0; i < NumberOfTests; i++)
            {
                engine.Calculate(functionText);
            }

            DateTime end = DateTime.Now;

            Console.WriteLine("Total duration: {0}", end - start);
        }
开发者ID:plurby,项目名称:Jace,代码行数:13,代码来源:Program.cs

示例12: TestCalcEngineAtom

        public void TestCalcEngineAtom()
        {
            // Test that calc engine atom reference work properly
            CalculationEngine engine = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();

            engine.Add("a", "\"abc\"", context);
            engine.Add("b", "a.length", context);
            engine.Add("c", "a.startswith(\"a\")", context);

            int result = engine.GetResult<int>("b");
            Assert.AreEqual("abc".Length, result);

            Assert.AreEqual(true, engine.GetResult<bool>("c"));
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:15,代码来源:CalcEngineTestFixture.cs

示例13: BenchMarkCalculationEngineFunctionBuild

        private static void BenchMarkCalculationEngineFunctionBuild(CalculationEngine engine, string functionText)
        {
            DateTime start = DateTime.Now;

            Func<int, int, int, double> function = (Func<int, int, int, double>)engine.Formula(functionText)
                .Parameter("var1", DataType.Integer)
                .Parameter("var2", DataType.Integer)
                .Parameter("something", DataType.Integer)
                .Result(DataType.FloatingPoint)
                .Build();

            Random random = new Random();

            for (int i = 0; i < NumberOfTests; i++)
            {
                function(random.Next(), random.Next(), random.Next());
            }

            DateTime end = DateTime.Now;

            Console.WriteLine("Total duration: {0}", end - start);
        }
开发者ID:plurby,项目名称:Jace,代码行数:22,代码来源:Program.cs

示例14: TestBasic

        public void TestBasic()
        {
            CalculationEngine ce = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();
            VariableCollection variables = context.Variables;

            variables.Add("x", 100);
            ce.Add("a", "x * 2", context);

            variables.Add("y", 1);
            ce.Add("b", "a + y", context);

            ce.Add("c", "b * 2", context);

            ce.Recalculate("a");
            int result = ce.GetResult<int>("c");
            Assert.AreEqual(result, ((100 * 2) + 1) * 2);

            variables["x"] = 345;
            ce.Recalculate("a");
            result = ce.GetResult<int>("c");
            Assert.AreEqual(((345 * 2) + 1) * 2, result);
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:23,代码来源:CalcEngineTestFixture.cs

示例15: BenchMarkCalculationEngineRandomFunctionBuild

        private static void BenchMarkCalculationEngineRandomFunctionBuild(CalculationEngine engine, List<string> functions, 
            int numberOfTests)
        {
            Random random = new Random();

            DateTime start = DateTime.Now;

            List<Task> tasks = new List<Task>();

            foreach (string functionText in functions)
            {
                Task task = new Task(() =>
                {
                    Func<int, int, int, double> function = (Func<int, int, int, double>)engine.Formula(functionText)
                        .Parameter("var1", DataType.Integer)
                        .Parameter("var2", DataType.Integer)
                        .Parameter("var3", DataType.Integer)
                        .Result(DataType.FloatingPoint)
                        .Build();

                    for (int i = 0; i < numberOfTests; i++)
                    {
                        function(random.Next(), random.Next(), random.Next());
                    }
                });

                tasks.Add(task);
                task.Start();
            }

            Task.WaitAll(tasks.ToArray());

            DateTime end = DateTime.Now;

            Console.WriteLine("Total duration: {0}", end - start);
        }
开发者ID:plurby,项目名称:Jace,代码行数:36,代码来源:Program.cs


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