locked
Problem defining Subscription.UserCondition RRS feed

  • Question

  • Hi there,

    I'm having trouble to build a subscription user condition thru code. I'm making a Notification Services(NS) application to produce alerts on stock levels off some products. That's were the problem starts!

    I have a web site were e choose the product id I want to monitorize and stock value. But I want to have more complex conditions like for example:

    Product_ID = 'xpto' or Produtct_ID='asdf' and Stock >= 1200 and Stock <= 1300

    Here's the problem, I want to have AndConditions and OrConditions in the same UserCondition, but programatically it only lets me have one type.

    Here's some code i developed:

     public Subscription AddConditions(int index, Subscription s, string subscriber,
                ArrayList tipos, ArrayList campos, ArrayList condicoes, ArrayList valores)
            {
                s = new Subscription(subscriber);           

                ConditionTree c = new AndCondition();                  

                string op;                    

                for (int i = 0; i < campos.Count; i++)
                {
                    op = condicoes[ i ].ToString();
                    AndCondition and = new AndCondition();
                    OrCondition or = new OrCondition();

                    if (tipos[ i ].ToString() == "AND")
                    {                   
                      
                        switch (op)
                        {
                            case "=": and.Children.Add(new SimpleLeafCondition(
    new FieldValue(campos[ i ].ToString()), SimpleOperator.Equals, valores[ i ].ToString()
                                ));
                                c.Children.Add(and);
                                break;
                            case "<>": and.Children.Add(new SimpleLeafCondition(
                                new FieldValue(campos[ i ].ToString()),
    SimpleOperator.NotEquals, valores[ i ].ToString()
                                ));
                                c.Children.Add(and);
                                break;

                            case "<": and.Children.Add(new SimpleLeafCondition(
                               new FieldValue(campos[ i ].ToString()),
     SimpleOperator.LessThan, valores[ i ].ToString()
                               ));
                                c.Children.Add(and);
                                break;

                            case "<=": and.Children.Add(new nsr.SimpleLeafCondition(
                            new FieldValue(campos[ i ].ToString()), SimpleOperator.LessThanOrEqualTo, valores[ i ].ToString()
                            ));
                                c.Children.Add(and);
                                break;

                            case ">": and.Children.Add(new SimpleLeafCondition(
                            new FieldValue(campos[ i ].ToString()), SimpleOperator.GreaterThan, valores[ i ].ToString()
                            ));
                                c.Children.Add(and);
                                break;

                            case ">=": and.Children.Add(new SimpleLeafCondition(
                            new FieldValue(campos[ i ].ToString()), SimpleOperator.GreaterThanOrEqualTo, valores[ i ].ToString()
                            ));
                                c.Children.Add(and);
                                break;
                            default:
                                break;
                        }
                    }
                    else
                    {   

                        switch (op)
                        {
                            case "=": or.Children.Add(new SimpleLeafCondition(
                                new FieldValue(campos[ i ].ToString()), SimpleOperator.Equals, valores[ i ].ToString()
                                ));
                                c.Children.Add(or);
                                break;
                            case "<>": or.Children.Add(new SimpleLeafCondition(
                                new FieldValue(campos[ i ].ToString()), SimpleOperator.NotEquals, valores[ i ].ToString()
                                ));
                                c.Children.Add(or);
                                break;

                            case "<": or.Children.Add(new SimpleLeafCondition(
                               new FieldValue(campos[ i ].ToString()),
    SimpleOperator.LessThan, valores[ i ].ToString()
                               ));
                                c.Children.Add(or);
                                break;

                            case "<=": or.Children.Add(new nsr.SimpleLeafCondition(
                            new nsr.FieldValue(campos[ i ].ToString()), SimpleOperator.LessThanOrEqualTo, valores[ i ].ToString()
                            ));
                                c.Children.Add(or);
                                break;

                            case ">": or.Children.Add(new SimpleLeafCondition(
                            new FieldValue(campos[ i ].ToString()),
    SimpleOperator.GreaterThan, valores[ i ].ToString()
                            ));
                                c.Children.Add(or);
                                break;

                            case ">=": or.Children.Add(new SimpleLeafCondition(
                            new FieldValue(campos[ i ].ToString()), SimpleOperator.GreaterThanOrEqualTo, valores[ i ].ToString()
                            ));
                                c.Children.Add(or);
                                break;
                            default:
                                break;
                        }
                    }
                }

                s.UserCondition = c;

                return s;
    }


    The result of this code is a UserCondition with all And conditions. I'm using the
    ConditionTree c = new AndCondition();  I know i'm initialyzing as a AndCondition but if I don't I get a runtime error.


    Can someone help with this? I can't find the solution!


    Thanks in advance
    Monday, June 30, 2008 8:39 AM