Beispiel #1
0
        public IMonthlyParameter <R> GetResult()
        {
            var result = new MonthlyParameter <R>();

            if (J != null)
            {
                var expression = GetExpression();
                foreach (Month month in Enum.GetValues(typeof(Month)))
                {
                    var iResult = I.GetResult();
                    R   i       = iResult.Value.ContainsKey(month) ? iResult.Value[month] : default(R);
                    var jResult = J.GetResult();
                    R   j       = jResult.Value.ContainsKey(month) ? jResult.Value[month] : default(R);
                    result.Value[month] = expression.Compile()(i, j);
                }
            }
            else
            {
                foreach (Month month in Enum.GetValues(typeof(Month)))
                {
                    var iResult = I.GetResult();
                    R   i       = iResult.Value.ContainsKey(month) ? iResult.Value[month] : default(R);
                    result.Value[month] = i;
                }
            }
            return(result);
        }
Beispiel #2
0
        private void Parse(string rule)
        {
            rule = rule.Trim();
            var tokens    = SplitWithParameters(rule);
            var parameter = new Regex(@"{(.*)}", RegexOptions.Compiled);
            var operation = new Regex(@"^\s*(<=|>=|==|!=|[=+\-*/^()!<>])", RegexOptions.Compiled);

            foreach (var token in tokens)
            {
                if (parameter.IsMatch(token))
                {
                    var name = token.TrimStart('{').TrimEnd('}');

                    if (Operation == null)
                    {
                        I = new MonthlyParameter <T> {
                            Name = name
                        }
                    }
                    ;
                    else
                    {
                        J = new MonthlyParameter <T> {
                            Name = name
                        }
                    };
                }
                else
                {
                    if (operation.IsMatch(token))
                    {
                        Operation = new Operation(token);
                    }
                    else
                    {
                        if (Operation == null)
                        {
                            I = new MonthlyParameter <T>();
                            I.SetConstant((T)Convert.ChangeType(token, typeof(T)));
                        }
                        else
                        {
                            J = new MonthlyParameter <T>();
                            J.SetConstant((T)Convert.ChangeType(token, typeof(T)));
                        }
                    }
                }
            }
            if (I == null || Operation == null || J == null)
            {
                throw new FormatException("Invalid operation format.");
            }
        }
Beispiel #3
0
        public IMonthlyParameter <R> GetResult()
        {
            var result     = new MonthlyParameter <R>();
            var expression = GetExpression();

            foreach (Month month in Enum.GetValues(typeof(Month)))
            {
                T i = Parameter1.Value.ContainsKey(month) ? Parameter1.Value[month] : default(T);
                T j = Parameter2.Value.ContainsKey(month) ? Parameter2.Value[month] : default(T);
                result.Value[month] = expression.Compile()(i, j);
            }
            return(result);
        }
Beispiel #4
0
        private void Parse(string rule)
        {
            rule = rule.Trim();
            var tokens    = rule.Split(' ');
            var parameter = new Regex(@"{(.*)}", RegexOptions.Compiled);
            var operation = new Regex(@"^\s*(<=|>=|==|!=|[=+\-*/^()!<>])", RegexOptions.Compiled);

            foreach (var token in tokens)
            {
                if (parameter.IsMatch(token))
                {
                    var name = token.TrimStart('{').TrimEnd('}');

                    if (Operation == null)
                    {
                        Parameter1 = new MonthlyParameter <T> {
                            Name = name
                        }
                    }
                    ;
                    else
                    {
                        Parameter2 = new MonthlyParameter <T> {
                            Name = name
                        }
                    };
                }
                else
                {
                    if (operation.IsMatch(token))
                    {
                        Operation = new Operation(token);
                    }
                    else
                    {
                        if (Operation == null)
                        {
                            Parameter1 = new MonthlyParameter <T> {
                                Value = SetDictionaryFromValue((T)Convert.ChangeType(token, typeof(T)))
                            };
                        }
                        else
                        {
                            Parameter2 = new MonthlyParameter <T> {
                                Value = SetDictionaryFromValue((T)Convert.ChangeType(token, typeof(T)))
                            };
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public IMonthlyParameter <R> GetResult()
        {
            var expression = GetExpression();
            var result     = new MonthlyParameter <R>();

            foreach (Month month in Enum.GetValues(typeof(Month)))
            {
                T i, j;
                if (I.Value != null && J.Value != null)
                {
                    i = I.Value.ContainsKey(month) ? I.Value[month] : default(T);
                    j = J.Value.ContainsKey(month) ? J.Value[month] : default(T);
                    result.Value[month] = expression.Compile()(i, j);
                }
            }
            return(result);
        }