Beispiel #1
0
        /*
         * actual implementation of calculation, with delegates taking operators to be used
         */
        private static void RunMathExpression(Node pars, ExecuteFirstExpression first, ExecuteSecondExpression second)
        {
            Node ip = Ip(pars);
            Node dp = Dp(pars);

            decimal result = 0M;
            bool isFirst = true;
            foreach (Node idx in ip)
            {
                // Checking to see if name is not null
                if (!string.IsNullOrEmpty(idx.Name))
                {
                    pars["_ip"].Value = idx;
                    pars["_root-only-execution"].Value = true;
                    try
                    {
                        RaiseActiveEvent(
                            "magix.execute",
                            pars);
                    }
                    finally
                    {
                        pars["_root-only-execution"].UnTie();
                    }
                }

                // number
                if (isFirst)
                {
                    isFirst = false;
                    result = first(Expressions.GetExpressionValue<decimal>(idx.Get<string>(), dp, ip, false));
                }
                else
                    result = second(Expressions.GetExpressionValue<decimal>(idx.Get<string>(), dp, ip, false), result);
            }
            if (!string.IsNullOrEmpty(ip.Get<string>()) && ip.Get<string>().StartsWith("["))
            {
                Node resultNode = Expressions.GetExpressionValue<Node>(ip.Get<string>(), dp, ip, true);
                if (resultNode == null)
                    throw new ArgumentException("only node lists can be set as values of [" + ip.Name + "]");
                resultNode.Value = result;
            }
            else
                ip.Value = result;
        }
Beispiel #2
0
        /*
         * actual implementation of calculation, with delegates taking operators to be used
         */
        private static void RunMathExpression(Node pars, ExecuteFirstExpression first, ExecuteSecondExpression second)
        {
            Node ip = Ip(pars);
            Node dp = Dp(pars);

            decimal result  = 0M;
            bool    isFirst = true;

            foreach (Node idx in ip)
            {
                // Checking to see if name is not null
                if (!string.IsNullOrEmpty(idx.Name))
                {
                    pars["_ip"].Value = idx;
                    pars["_root-only-execution"].Value = true;
                    try
                    {
                        RaiseActiveEvent(
                            "magix.execute",
                            pars);
                    }
                    finally
                    {
                        pars["_root-only-execution"].UnTie();
                    }
                }

                // number
                if (isFirst)
                {
                    isFirst = false;
                    result  = first(Expressions.GetExpressionValue <decimal>(idx.Get <string>(), dp, ip, false));
                }
                else
                {
                    result = second(Expressions.GetExpressionValue <decimal>(idx.Get <string>(), dp, ip, false), result);
                }
            }
            if (!string.IsNullOrEmpty(ip.Get <string>()) && ip.Get <string>().StartsWith("["))
            {
                Node resultNode = Expressions.GetExpressionValue <Node>(ip.Get <string>(), dp, ip, true);
                if (resultNode == null)
                {
                    throw new ArgumentException("only node lists can be set as values of [" + ip.Name + "]");
                }
                resultNode.Value = result;
            }
            else
            {
                ip.Value = result;
            }
        }