예제 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="file"></param>
 public override int LoadProfile(string file)//这里发消息,桌面去加载
 {
     try
     {
         DictionaryEx dic = new DictionaryEx();
         foreach (ScriptEngine se in m_ScriptEngine)
         {
             se.DoFile(file);
         }
         System.Threading.Thread.Sleep(100);
         m_ItemTree = tmEnvironment.ParseProfile(this);
         if (m_ItemTree != null)
         {
             dic["items"] = m_ItemTree;
         }
         string Module = tmEnvironment.ParseModule(this);
         if (Module != null)
         {
             dic["Module"] = Module;
         }
         string Version = tmEnvironment.ParseVersion(this);
         if (Version != null)
         {
             dic["Version"] = Version;
         }
         NotificationCenter.DefaultCenter().PostNotification(tmMarcos.kOnLoadProfile, dic);
         return(0);
     }
     catch (System.Exception e)
     {
         System.Windows.Forms.MessageBox.Show(e.Source + e.Message, "Load Profile Failed",
                                              System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
     }
     return(-1);
 }
예제 #2
0
        void DoTest_LUA(tmTreeNode itemTree, object obj)
        {
            DictionaryEx dic    = obj as DictionaryEx;
            TestEngine   engine = dic["engine"] as TestEngine;
            int          id     = (int)dic["id"];

            ScriptEngine se = engine.GetScriptEngine(id) as ScriptEngine;

            se.DoString("return main()");   //goto main...
        }
예제 #3
0
        void DoTest(tmTreeNode itemTree, object obj)
        {
            DictionaryEx dic    = obj as DictionaryEx;
            TestEngine   engine = dic["engine"] as TestEngine;
            int          id     = (int)dic["id"];

            ScriptEngine se = engine.GetScriptEngine(id) as ScriptEngine;

            foreach (tmTreeNode c in itemTree.ChildNodes())
            {
                if (c.ChildNodes().Count > 0)   //key item
                {
                    DoTest(c, obj);
                    continue;
                }

                TestItem t = c.RepresentObject() as TestItem;
                m_SyncEvent[id].Set();
                UUT_SYNCH(0);
                Thread.Sleep(1000);
                object[] value = Execute_Item(se, t);
            }
        }
예제 #4
0
        int OnLoadProfile(Notification nf)
        {
            try
            {
                DictionaryEx dic      = nf.context as DictionaryEx;
                tmTreeNode   ItemTree = dic["items"] as tmTreeNode;
                lvTestItem.ShowGroups = false;

                List <tmTreeNode> Root = ItemTree.ChildNodes();
                int index   = 0;
                int casenum = 0;
                lvTestItem.Items.Clear();
                foreach (tmTreeNode t in Root)
                {
                    TestItem aItem = t.RepresentObject() as TestItem;
                    if (t.ChildNodes().Count > 0) //Group
                    {
                        //Create Group;
                        ListViewGroup     group = lvTestItem.Groups.Add(aItem["name"] as string, aItem["name"] as string);
                        List <tmTreeNode> child = t.ChildNodes();
                        foreach (tmTreeNode c in child)
                        {
                            TestItem subitem = c.RepresentObject() as TestItem;
                            string   testcase;
                            if (TestContext.testcaseList.Count > 0)
                            {
                                testcase = TestContext.testcaseList[casenum++];
                            }

                            if (subitem.ContainsKey("visible"))
                            {
                                int v = Convert.ToInt32(subitem["visible"]);
                                if (v == 0)
                                {
                                    continue;           //no need show
                                }
                            }

                            ListViewItem  lvItem = new ListViewItem(index++.ToString());
                            List <string> arrSub = new List <string>();

                            //后边再处理lxl
                            arrSub.Add(subitem["name"] as string);

                            if (subitem.ContainsKey("lower"))
                            {
                                arrSub.Add(subitem["lower"] as string);
                            }
                            else
                            {
                                arrSub.Add("");
                            }

                            if (subitem.ContainsKey("upper"))
                            {
                                arrSub.Add(subitem["upper"] as string);
                            }
                            else
                            {
                                arrSub.Add("");
                            }

                            arrSub.Add(""); //time
                            arrSub.Add(""); //UUT1
                            arrSub.Add(""); //UUT2
                            arrSub.Add(""); //UUT3
                            arrSub.Add(""); //UUT4
                            arrSub.Add(""); //UUT5
                            arrSub.Add(""); //UUT6

                            if (subitem.ContainsKey("unit"))
                            {
                                arrSub.Add(subitem["unit"] as string);
                            }
                            else
                            {
                                arrSub.Add("");
                            }
                            if (subitem.ContainsKey("remark"))
                            {
                                arrSub.Add(subitem["remark"] as string);
                            }
                            else
                            {
                                arrSub.Add("");
                            }
                            lvItem.SubItems.AddRange(arrSub.ToArray());
                            lvItem.Group = group;

                            lvTestItem.Items.Add(lvItem);
                        }
                    }
                }
                //lxl 根据具体的脚本加载不同的
                string module = dic["Module"] as string;
                if (module != null)
                {
                    lbTestName.Text = module;
                    if (module.CompareTo("Alsar Glass test") == 0)
                    {
                    }
                    else
                    {
                    }
                }
                string version = dic["Version"] as string;
                if (version != null)
                {
                    lbscriptver.Text = version;
                }
            }
            catch (System.Exception exp)
            {
                MessageBox.Show(exp.Message, exp.Source);
            }
            return(0);
        }
예제 #5
0
        public override int LoadTestCaseFromDb(string file)//这里发消息,桌面去加载
        {
            try
            {
                DictionaryEx dic = new DictionaryEx();
#if false
                m_ItemTree   = tmEnvironment.LoadProfile(file);
                dic["items"] = m_ItemTree;

                TestContext.testcaseList.Clear();//清除
                string        sqlstr   = "SELECT testcase ,testcasedescrip ,Unit,Lowlimit,NominalValue,Highlimit ,RetryTimes ,Visible,TestIndex ,StopOnError ,Timeout,Time,UserName,action FROM HRS_TESTCASE order by id asc";
                SqlDataReader myReader = TestContext.dbhelp.ExecuteReader(sqlstr, CommandType.Text);

                string        testcase, descrip, unit, low, high, visible, testindex, stoponerr, usernm, action;
                StringBuilder sb = new StringBuilder();

                sb.Append("local Test_Item_Sub={");

                string temp1, temp2, temp3;

                temp1 = "{name=\"testscription\",lower=\"\",upper=\"\",unit=nil,entry=function,visible=1,sub=nil},";//普通函数  testindex=0

                //temp1 = "{name=\"testscription\",lower=nil,upper=nil,unit=nil,entry=function,visible=1,sub=nil},";//普通函数  testindex=0

                temp2 = "{name=\"testscription\",lower=nil,upper=nil,unit=nil,entry=function,sub=nil,visible=1,parameter={index=1,remark=\"\"}},";                                                          //供电 unit=nil
                temp3 = "{name=\"testscription\",lower=nil,upper=nil,unit=\"mV\",entry=function,sub=nil,visible=1,parameter={index=1,Chnnel=\"Dev2/ai0\",rate=4000.0,  minnum=0,  maxmum=2.0,time=0.25}},"; //采集
                if (myReader.FieldCount > 3)
                {
                    System.Windows.Forms.MessageBox.Show("connect  sucessful");
                }
                while (myReader.Read())
                {
                    string result;
                    testcase = myReader["testcase"].ToString();
                    descrip  = myReader["testcasedescrip"].ToString();
                    unit     = myReader["Unit"].ToString();
                    low      = myReader["Lowlimit"].ToString();
                    high     = myReader["Highlimit"].ToString();
                    visible  = myReader["Visible"].ToString();

                    testindex = myReader["TestIndex"].ToString();
                    stoponerr = myReader["StopOnError"].ToString();
                    usernm    = myReader["UserName"].ToString();
                    action    = myReader["action"].ToString();
                    TestContext.testcaseList.Add(testcase); //添加到 tsetcase中
                    if (descrip.Substring(0, 5) == "Suply") //供电
                    {
                        Regex  regex1   = new Regex("testscription", RegexOptions.IgnoreCase);
                        Regex  regex2   = new Regex("function", RegexOptions.IgnoreCase);
                        Regex  regex3   = new Regex("visible=1", RegexOptions.IgnoreCase);
                        Regex  regex4   = new Regex("index=1", RegexOptions.IgnoreCase);
                        string indexexp = "index=";
                        indexexp = indexexp + testindex;

                        result = regex1.Replace(temp2, descrip); //1 次替换
                        result = regex2.Replace(result, action); //2次替换
                        string tempstr;
                        if (visible == "TRUE")
                        {
                            tempstr = "visible=1";
                        }
                        else
                        {
                            tempstr = "visible=0";
                        }

                        result = regex3.Replace(result, tempstr);
                        result = regex4.Replace(result, indexexp);
                    }

                    else if (unit != "")//表示读电压
                    {
                        string lowexp   = "lower=";
                        string upperexp = "upper=";

                        string indexexp = "index=";
                        indexexp = indexexp + testindex;

                        lowexp   = lowexp + low;
                        upperexp = upperexp + high;
                        Regex regex1 = new Regex("testscription", RegexOptions.IgnoreCase);
                        Regex regex2 = new Regex("function", RegexOptions.IgnoreCase);
                        Regex regex3 = new Regex("visible=1", RegexOptions.IgnoreCase);
                        Regex regex4 = new Regex("lower=nil", RegexOptions.IgnoreCase);
                        Regex regex5 = new Regex("upper=nil", RegexOptions.IgnoreCase);
                        Regex regex6 = new Regex("index=1", RegexOptions.IgnoreCase);

                        result = regex1.Replace(temp3, descrip); //1 次替换
                        result = regex2.Replace(result, action); //2次替换
                        string tempstr;
                        if (visible == "TRUE")
                        {
                            tempstr = "visible=1";
                        }
                        else
                        {
                            tempstr = "visible=0";
                        }

                        result = regex3.Replace(result, tempstr);
                        result = regex4.Replace(result, lowexp);
                        result = regex5.Replace(result, upperexp);
                        result = regex6.Replace(result, indexexp);
                    }
                    else
                    {
                        Regex regex1 = new Regex("testscription", RegexOptions.IgnoreCase);
                        Regex regex2 = new Regex("function", RegexOptions.IgnoreCase);
                        Regex regex3 = new Regex("visible=1", RegexOptions.IgnoreCase);

                        result = regex1.Replace(temp1, descrip); //1 次替换
                        result = regex2.Replace(result, action); //2次替换
                        string tempstr;
                        if (visible == "TRUE")
                        {
                            tempstr = "visible=1";
                        }
                        else
                        {
                            tempstr = "visible=0";
                        }
                        result = regex3.Replace(result, tempstr);
                    }
                    sb.Append(result);
                }

                sb.Remove(sb.ToString().LastIndexOf(','), 1);

                sb.Append("}");

                sb.Append("local Test_Item = {name=\"Initial\",lower=\"\",upper=\"\",entry=nil,parameter=nil,sub=Test_Item_Sub};");
                sb.Append("items = {Test_Item };");
                string luastr = sb.ToString();
                //SqlDbHelper dbhelp = new SqlDbHelper();
                foreach (ScriptEngine se in m_ScriptEngine)
                {
                    se.DoFile(file);
                    se.DoString(luastr);
                }
                m_ItemTree   = tmEnvironment.ParseProfile(this);
                dic["items"] = m_ItemTree;
                NotificationCenter.DefaultCenter().PostNotification(tmMarcos.kOnLoadProfile, dic);
#endif
                return(0);
            }
            catch (System.Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message, "Load Profile Failed",
                                                     System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            return(-1);
        }