Example #1
0
        private void Generatebtn_Click(object sender, RoutedEventArgs e)
        {
            this.listView2.UpdateLayout();
            //##################################################################################
            //Inatialize Result tab
            //##################################################################################

            //Get Parameter
            List <Microsoft.Test.VariationGeneration.Parameter> listP = new List <Microsoft.Test.VariationGeneration.Parameter>();

            foreach (VariationDataSource.Variation v in Variations)
            {
                string[] values = v.Value.Replace(",", ",").Split(',');

                var P = new Microsoft.Test.VariationGeneration.Parameter(v.Parameter.Trim())
                {
                };
                foreach (string value in values)
                {
                    Double isnumber;
                    if (value.Contains("(") && value.Contains(")") && Double.TryParse(substring(value, "(", ")"), out isnumber))
                    {
                        P.Add(new ParameterValue(value.Substring(0, value.IndexOf("(")))
                        {
                            Weight = Convert.ToDouble(substring(value, "(", ")"))
                        });
                    }
                    else
                    {
                        P.Add(value.Trim());
                    }
                }
                listP.Add(P);
            }

            //Get Model
            Model model = null;
            int   count = this.listBox3.Items.Count;

            if (count == 0)
            {
                model = new Model(listP);
            }
            else
            {
                //Get constraints
                var constraints = new List <Microsoft.Test.VariationGeneration.Constraint> {
                };
                for (int i = 0; i < count; i++)
                {
                    string constain        = this.listBox3.Items[i].ToString();
                    string if_constrain    = substring(constain, "If", "Then").Trim();
                    string ifparametername = substring(if_constrain, "[", "]");
                    string ifvaluename     = substring(if_constrain, "\"", "\"");
                    string if_express      = substring(if_constrain, "]", "\"");
                    Microsoft.Test.VariationGeneration.Parameter if_p = listP.Find(p => p.Name.Equals(ifparametername));
                    string then_constrain    = constain.Substring(constain.IndexOf("Then"));
                    string thenparametername = substring(then_constrain, "[", "]");
                    string thenvaluename     = substring(then_constrain, "\"", "\"");
                    string then_express      = substring(then_constrain, "]", "\"");
                    Microsoft.Test.VariationGeneration.Parameter then_p = listP.Find(p => p.Name.Equals(thenparametername));

                    //Judge if Parameters in listview1 contain ifparametername and thenparametername, if not , the constaint is not valid
                    StringBuilder builder = new StringBuilder();
                    foreach (VariationDataSource.Variation v in Variations)
                    {
                        builder.Append(v.Parameter + " ");
                    }
                    if (builder.ToString().Contains(ifparametername) && builder.ToString().Contains(thenparametername))
                    {
                        IfThenConstraint ifthen = new IfThenConstraint()
                        {
                        };
                        //############################################################################
                        //if_constrain
                        //############################################################################
                        if (if_constrain.Contains("And") || if_constrain.Contains("Or"))
                        {
                            string[]      if_constrains     = if_constrain.Replace("And", "_And").Replace("Or", "_Or").Split('_');
                            List <string> if_constrainslist = if_constrains.ToList <string>();

                            ConditionConstraint _if;

                            string ifparname_Fir = substring(if_constrainslist[0], "[", "]");
                            string ifvalname_Fir = substring(if_constrainslist[0], "\"", "\"");
                            string if_exp_Fir    = substring(if_constrainslist[0], "]", "\"");
                            Microsoft.Test.VariationGeneration.Parameter if_par_Fir = listP.Find(p => p.Name.Equals(ifparname_Fir));

                            if (if_exp_Fir == "is")
                            {
                                _if = if_par_Fir.Equal(ifvalname_Fir);
                            }
                            else
                            {
                                _if = if_par_Fir.NotEqual(ifvalname_Fir);
                            }
                            if_constrainslist.RemoveAt(0);
                            foreach (string if_constraint in if_constrainslist)
                            {
                                string ifparname = substring(if_constraint, "[", "]");
                                string ifvalname = substring(if_constraint, "\"", "\"");
                                string if_exp    = substring(if_constraint, "]", "\"");
                                Microsoft.Test.VariationGeneration.Parameter if_par = listP.Find(p => p.Name.Equals(ifparname));
                                if (if_constraint.Trim().StartsWith("And"))
                                {
                                    if (if_exp == "is")
                                    {
                                        _if = _if.And(if_par.Equal(ifvalname));
                                    }
                                    else
                                    {
                                        _if = _if.And(if_par.NotEqual(ifvalname));
                                    }
                                }
                                if (if_constraint.Trim().StartsWith("Or"))
                                {
                                    if (if_exp == "is")
                                    {
                                        _if = _if.Or(if_par.Equal(ifvalname));
                                    }
                                    else
                                    {
                                        _if = _if.Or(if_par.NotEqual(ifvalname));
                                    }
                                }
                            }

                            ifthen.If = _if;
                        }
                        else
                        {
                            if (if_express == "is")
                            {
                                ifthen.If = if_p.Equal(ifvaluename);
                            }
                            else
                            {
                                ifthen.If = if_p.NotEqual(ifvaluename);
                            }
                        }
                        //############################################################################
                        //############################################################################


                        //############################################################################
                        //Then_constrain
                        //############################################################################
                        if (then_constrain.Contains("And") || then_constrain.Contains("Or"))
                        {
                            string[]      then_constrains     = then_constrain.Replace("And", "_And").Replace("Or", "_Or").Split('_');
                            List <string> then_constrainslist = then_constrains.ToList <string>();

                            ConditionConstraint _then;

                            string thenparname_Fir = substring(then_constrainslist[0], "[", "]");
                            string thenvalname_Fir = substring(then_constrainslist[0], "\"", "\"");
                            string then_exp_Fir    = substring(then_constrainslist[0], "]", "\"");
                            Microsoft.Test.VariationGeneration.Parameter then_par_Fir = listP.Find(p => p.Name.Equals(thenparname_Fir));

                            if (then_exp_Fir == "is")
                            {
                                _then = then_par_Fir.Equal(thenvalname_Fir);
                            }
                            else
                            {
                                _then = then_par_Fir.NotEqual(thenvalname_Fir);
                            }
                            then_constrainslist.RemoveAt(0);
                            foreach (string then_constraint in then_constrainslist)
                            {
                                string thenparname = substring(then_constraint, "[", "]");
                                string thenvalname = substring(then_constraint, "\"", "\"");
                                string then_exp    = substring(then_constraint, "]", "\"");
                                Microsoft.Test.VariationGeneration.Parameter then_par = listP.Find(p => p.Name.Equals(thenparname));
                                if (then_constraint.Trim().StartsWith("And"))
                                {
                                    if (then_exp == "is")
                                    {
                                        _then = _then.And(then_par.Equal(thenvalname));
                                    }
                                    else
                                    {
                                        _then = _then.And(then_par.NotEqual(thenvalname));
                                    }
                                }
                                if (then_constraint.Trim().StartsWith("Or"))
                                {
                                    if (then_exp == "is")
                                    {
                                        _then = _then.Or(then_par.Equal(thenvalname));
                                    }
                                    else
                                    {
                                        _then = _then.Or(then_par.NotEqual(thenvalname));
                                    }
                                }
                            }
                            ifthen.Then = _then;
                        }
                        else
                        {
                            if (then_express == "is")
                            {
                                ifthen.Then = then_p.Equal(thenvaluename);
                            }
                            else
                            {
                                ifthen.Then = then_p.NotEqual(thenvaluename);
                            }
                        }
                        //############################################################################
                        //############################################################################

                        constraints.Add(ifthen);
                    }
                }
                model = new Model(listP, constraints);
            }


            System.Collections.ArrayList objects = new System.Collections.ArrayList();
            var variations = model.GenerateVariations(Convert.ToInt32(this.ComboBox1.SelectedValue), 12345);

            DataTable table = new DataTable();

            table.Columns.Add(new DataColumn("ID"));
            int t = 1;

            foreach (var v in variations)
            {
                //Add columns
                foreach (var value in v)
                {
                    if (!table.Columns.Contains(value.Key))
                    {
                        table.Columns.Add(new DataColumn(value.Key));
                    }
                }

                //Add the numbet of ID
                objects.Add(t);
                t++;

                //Add Rows
                foreach (var value in v)
                {
                    objects.Add(value.Value);
                }
                table.Rows.Add(objects.ToArray());
                objects.Clear();
            }

            viewmodel.QueryResult = table;

            this.listView2.UpdateLayout();
            this.Exportbutton.IsEnabled = this.listView2.HasItems;
        }
Example #2
0
        private void Generatebtn_Click(object sender, RoutedEventArgs e)
        {
            this.listView2.UpdateLayout();
            //##################################################################################
            //Inatialize Result tab
            //##################################################################################

            //Get Parameter
            List<Microsoft.Test.VariationGeneration.Parameter> listP = new List<Microsoft.Test.VariationGeneration.Parameter>();
            foreach (VariationDataSource.Variation v in Variations)
            {
                string[] values = v.Value.Replace(",", ",").Split(',');

                var P = new Microsoft.Test.VariationGeneration.Parameter(v.Parameter.Trim()) { };
                foreach (string value in values)
                {
                    Double isnumber;
                    if (value.Contains("(") && value.Contains(")") && Double.TryParse(substring(value,"(",")"),out isnumber))
                    {
                        P.Add(new ParameterValue(value.Substring(0, value.IndexOf("("))) { Weight = Convert.ToDouble(substring(value,"(",")")) });
                    }
                    else
                    {
                        P.Add(value.Trim());
                    }

                }
                listP.Add(P);
            }

            //Get Model
            Model model = null;
            int count = this.listBox3.Items.Count;
            if (count == 0)
            {
                model = new Model(listP);
            }
            else
            {
                //Get constraints
                var constraints = new List<Microsoft.Test.VariationGeneration.Constraint> { };
                for (int i = 0; i < count; i++)
                {
                    string constain = this.listBox3.Items[i].ToString();
                    string if_constrain = substring(constain, "If","Then").Trim();
                    string ifparametername = substring(if_constrain, "[", "]");
                    string ifvaluename = substring(if_constrain, "\"", "\"");
                    string if_express = substring(if_constrain, "]", "\"");
                    Microsoft.Test.VariationGeneration.Parameter if_p = listP.Find(p => p.Name.Equals(ifparametername));
                    string then_constrain = constain.Substring(constain.IndexOf("Then"));
                    string thenparametername = substring(then_constrain, "[", "]");
                    string thenvaluename = substring(then_constrain, "\"", "\"");
                    string then_express = substring(then_constrain, "]", "\"");
                    Microsoft.Test.VariationGeneration.Parameter then_p = listP.Find(p => p.Name.Equals(thenparametername));

                    //Judge if Parameters in listview1 contain ifparametername and thenparametername, if not , the constaint is not valid
                    StringBuilder builder = new StringBuilder();
                    foreach (VariationDataSource.Variation v in Variations)
                    {
                        builder.Append(v.Parameter + " ");
                    }
                    if (builder.ToString().Contains(ifparametername) && builder.ToString().Contains(thenparametername))
                    {
                        IfThenConstraint ifthen = new IfThenConstraint(){};
                        //############################################################################
                        //if_constrain
                        //############################################################################
                        if (if_constrain.Contains("And") || if_constrain.Contains("Or"))
                        {
                            string[] if_constrains = if_constrain.Replace("And", "_And").Replace("Or","_Or").Split('_');
                            List<string> if_constrainslist = if_constrains.ToList<string>();

                            ConditionConstraint _if;

                            string ifparname_Fir = substring(if_constrainslist[0], "[", "]");
                            string ifvalname_Fir = substring(if_constrainslist[0], "\"", "\"");
                            string if_exp_Fir = substring(if_constrainslist[0], "]", "\"");
                            Microsoft.Test.VariationGeneration.Parameter if_par_Fir = listP.Find(p => p.Name.Equals(ifparname_Fir));

                            if (if_exp_Fir == "is")
                            {
                                _if = if_par_Fir.Equal(ifvalname_Fir);

                            }
                            else
                            {
                                _if = if_par_Fir.NotEqual(ifvalname_Fir);
                            }
                            if_constrainslist.RemoveAt(0);
                            foreach (string if_constraint in if_constrainslist)
                            {
                               string ifparname = substring(if_constraint, "[", "]");
                               string ifvalname = substring(if_constraint, "\"", "\"");
                               string if_exp = substring(if_constraint, "]", "\"");
                               Microsoft.Test.VariationGeneration.Parameter if_par = listP.Find(p => p.Name.Equals(ifparname));
                               if(if_constraint.Trim().StartsWith("And"))
                               {

                                    if (if_exp == "is")
                                    {
                                        _if = _if.And(if_par.Equal(ifvalname));

                                    }
                                    else
                                    {
                                          _if = _if.And(if_par.NotEqual(ifvalname));
                                    }

                               }
                               if(if_constraint.Trim().StartsWith("Or"))
                               {

                                    if (if_exp == "is")
                                    {
                                        _if = _if.Or(if_par.Equal(ifvalname));

                                    }
                                    else
                                    {
                                        _if = _if.Or(if_par.NotEqual(ifvalname));
                                    }

                               }

                            }

                            ifthen.If = _if;

                        }
                        else
                        {
                            if (if_express == "is")
                            {
                                ifthen.If = if_p.Equal(ifvaluename);

                            }
                            else
                            {
                                ifthen.If = if_p.NotEqual(ifvaluename);
                            }

                        }
                        //############################################################################
                        //############################################################################

                        //############################################################################
                        //Then_constrain
                        //############################################################################
                        if (then_constrain.Contains("And") || then_constrain.Contains("Or"))
                        {
                            string[] then_constrains = then_constrain.Replace("And", "_And").Replace("Or", "_Or").Split('_');
                            List<string> then_constrainslist = then_constrains.ToList<string>();

                            ConditionConstraint _then;

                            string thenparname_Fir = substring(then_constrainslist[0], "[", "]");
                            string thenvalname_Fir = substring(then_constrainslist[0], "\"", "\"");
                            string then_exp_Fir = substring(then_constrainslist[0], "]", "\"");
                            Microsoft.Test.VariationGeneration.Parameter then_par_Fir = listP.Find(p => p.Name.Equals(thenparname_Fir));

                            if (then_exp_Fir == "is")
                            {
                                _then = then_par_Fir.Equal(thenvalname_Fir);

                            }
                            else
                            {
                                _then = then_par_Fir.NotEqual(thenvalname_Fir);
                            }
                            then_constrainslist.RemoveAt(0);
                            foreach (string then_constraint in then_constrainslist)
                            {
                                string thenparname = substring(then_constraint, "[", "]");
                                string thenvalname = substring(then_constraint, "\"", "\"");
                                string then_exp = substring(then_constraint, "]", "\"");
                                Microsoft.Test.VariationGeneration.Parameter then_par = listP.Find(p => p.Name.Equals(thenparname));
                                if (then_constraint.Trim().StartsWith("And"))
                                {

                                    if (then_exp == "is")
                                    {
                                        _then = _then.And(then_par.Equal(thenvalname));

                                    }
                                    else
                                    {
                                        _then = _then.And(then_par.NotEqual(thenvalname));
                                    }

                                }
                                if (then_constraint.Trim().StartsWith("Or"))
                                {

                                    if (then_exp == "is")
                                    {
                                        _then = _then.Or(then_par.Equal(thenvalname));

                                    }
                                    else
                                    {
                                        _then = _then.Or(then_par.NotEqual(thenvalname));
                                    }
                                }
                            }
                            ifthen.Then = _then;
                        }
                        else
                        {
                            if (then_express == "is")
                            {
                                ifthen.Then = then_p.Equal(thenvaluename);
                            }
                            else
                            {
                                ifthen.Then = then_p.NotEqual(thenvaluename);
                            }
                        }
                        //############################################################################
                        //############################################################################

                        constraints.Add(ifthen);
                    }

                }
                model = new Model(listP, constraints);
            }

            System.Collections.ArrayList objects = new System.Collections.ArrayList();
            var variations = model.GenerateVariations(Convert.ToInt32(this.ComboBox1.SelectedValue), 12345);

            DataTable table = new DataTable();
            table.Columns.Add(new DataColumn("ID"));
            int t = 1;
            foreach (var v in variations)
            {
                //Add columns
                foreach (var value in v)
                {

                    if (!table.Columns.Contains(value.Key))
                    {
                        table.Columns.Add(new DataColumn(value.Key));
                    }

                }

                //Add the numbet of ID
                objects.Add(t);
                t++;

                //Add Rows
                foreach (var value in v)
                {
                    objects.Add(value.Value);

                }
                table.Rows.Add(objects.ToArray());
                objects.Clear();

            }

            viewmodel.QueryResult = table;

            this.listView2.UpdateLayout();
            this.Exportbutton.IsEnabled = this.listView2.HasItems;
        }