Beispiel #1
0
        public static Rule Insert(IDbConnection dbConn
                                  , String variableName
                                  , Rule.Compare operation
                                  , String variableValue
                                  , int ruleOrder
                                  , Step step
                                  , Step nextStep
                                  )

        {
            try
            {
                // arg checks here in try block, so the building of message can only be
                // done 1x:
                if (ruleOrder < 0)
                {
                    throw new ArgumentException("ruleOrder is unsigned.  Use >= 0");
                }
                if (step == null)
                {
                    throw new ArgumentNullException("step");
                }
                if (nextStep == null)
                {
                    throw new ArgumentNullException("nextStep");
                }

                IDbCommand command = dbConn.CreateCommand();
                command.CommandText = INSERT + " ; " + DbUtil.GET_KEY;

                DbUtil.AddParameter(command, "@rule_order", ruleOrder);
                DbUtil.AddParameter(command, "@variable_name", variableName);
                DbUtil.AddParameter(command, "@variable_value", variableValue);
                DbUtil.AddParameter(command, "@comparison", (int)(operation));
                DbUtil.AddParameter(command, "@step_id", step.Id);
                DbUtil.AddParameter(command, "@next_step_id", nextStep.Id);

                int id = Convert.ToInt32(command.ExecuteScalar());
                return(new Rule(id
                                , step.Id
                                , variableName
                                , operation
                                , variableValue
                                , ruleOrder
                                , nextStep.Id
                                ));
            }
            catch (Exception ex)
            {
                var msg = new StringBuilder();
                msg.Append("error adding rule [");
                msg.Append(variableName);
                msg.Append(Pretty(operation));
                msg.Append(variableValue);
                msg.Append("], order ");
                msg.Append(ruleOrder);
                msg.Append(" from step [");
                msg.Append(step);
                msg.Append("] to [");
                msg.Append(nextStep);
                msg.Append("]: ");
                msg.Append(ex.Message);
                //Console.WriteLine(msg);
                //Console.WriteLine(INSERT);
                throw new Exception(msg.ToString(), ex);
            }
        }