Example #1
0
 public static List <KeyValuePair <object, string> > GetAllActions()
 {
     return(Enum.GetValues(typeof(ActionType))
            .Cast <ActionType> ()
            .Select(a => new KeyValuePair <object, string> (a, PriceRuleAction.TypeToString(a)))
            .ToList());
 }
Example #2
0
        public PriceRuleAction AddAction(ActionType actionType, params object [] values)
        {
            try {
                PriceRuleAction action = new PriceRuleAction(actionType, values);
                actions.Clear();
                actions.Add(action);

                return(action);
            } catch (ArgumentOutOfRangeException) {
                return(null);
            }
        }
Example #3
0
        private bool ParseFormula()
        {
            string [] conditionsAndActions = Formula.Split(new [] { " THEN " }, StringSplitOptions.RemoveEmptyEntries);
            if (conditionsAndActions.Length != 2)
            {
                return(false);
            }

            string prerequisitesString = conditionsAndActions [0];
            int    operationsStart     = prerequisitesString.IndexOf("(operation", StringComparison.Ordinal);
            string conditionsString    = prerequisitesString.Substring(0, operationsStart);
            string operationsString    = prerequisitesString.Substring(operationsStart);

            string actionsString = conditionsAndActions [1];

            return(PriceRuleCondition.Parse(conditionsString, conditions) &&
                   ParseOperations(operationsString) &&
                   PriceRuleAction.Parse(actionsString, actions));
        }
Example #4
0
        private void BuildFormula()
        {
            if (conditions.Count == 0)
            {
                throw new InvalidOperationException("A price rule must contain at least one condition.");
            }
            if (actions.Count == 0)
            {
                throw new InvalidOperationException("A price rule must contain at least one action.");
            }
            if (operations.Count == 0)
            {
                throw new InvalidOperationException("A price rule must apply to at least one operation.");
            }

            Formula = string.Format("IF {0} AND (operation = {1}) THEN {2}",
                                    PriceRuleCondition.GetFormula(conditions),
                                    string.Join(",", operations.Cast <int> ()),
                                    PriceRuleAction.GetFormula(actions));
        }
Example #5
0
        public override string ToString()
        {
            StringBuilder             ret  = new StringBuilder();
            List <PriceRuleCondition> cond = conditions.FindAll(c => !c.IsException);

            if (cond.Count > 0)
            {
                ret.AppendFormat("{0}:{1}{2}{1}",
                                 Translator.GetString("Conditions"),
                                 Environment.NewLine,
                                 string.Join(Environment.NewLine, cond));
            }

            List <PriceRuleCondition> exceptions = conditions.FindAll(c => c.IsException);

            if (exceptions.Count > 0)
            {
                if (ret.Length > 0)
                {
                    ret.Append(Environment.NewLine);
                }

                ret.AppendFormat("{0}:{1}{2}{1}",
                                 Translator.GetString("Exceptions"),
                                 Environment.NewLine,
                                 string.Join(Environment.NewLine, exceptions));
            }

            ret.AppendFormat("{1}{0}:{1}{2}{1}",
                             Translator.GetString("Actions"),
                             Environment.NewLine,
                             string.Join(Environment.NewLine, actions.Select(a => string.Format("{0}: {1}", PriceRuleAction.TypeToString(a.Type), a))));

            ret.AppendFormat("{1}{0}:{1}{2}",
                             Translator.GetString("Operations"),
                             Environment.NewLine,
                             string.Join(Environment.NewLine, operations.Select(Translator.GetOperationTypeGlobalName)));

            return(ret.ToString());
        }