国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

一個記錄程序運行時間表的控件

2024-07-21 02:24:08
字體:
供稿:網(wǎng)友
using system;
using system.collections;
using system.data;

namespace mytools
{
    /// <summary>
    /// summary description for timetest.
    /// </summary>
    public class timetest
    {    
        private datatable manager = new datatable("manager");
        private datatable timelist = new datatable("timelist");
        
        public timetest()
        {
            #region initialize the managertable to save the test cases
            datacolumn  tempcolumn = new datacolumn("name",typeof(system.string));
            manager.columns.add(tempcolumn);
            tempcolumn = new datacolumn("description",typeof(system.string));
            manager.columns.add(tempcolumn);
            tempcolumn = new datacolumn("totaltime",typeof(system.timespan));
            manager.columns.add(tempcolumn);
            tempcolumn = new datacolumn("starttime",typeof(system.datetime));
            manager.columns.add(tempcolumn);
            tempcolumn = new datacolumn("testcount",typeof(system.int32));
            manager.columns.add(tempcolumn);
            manager.primarykey =  new datacolumn[]{manager.columns["name"]};
            #endregion

            #region initialize the timelisttable to save the list of time span
            tempcolumn = new datacolumn("name",typeof(system.string));
            timelist.columns.add(tempcolumn);
            tempcolumn = new datacolumn("time",typeof(system.timespan));
            timelist.columns.add(tempcolumn);
            tempcolumn = new datacolumn("description",typeof(system.string));
            timelist.columns.add(tempcolumn);
            #endregion

            #region initialize a test case
            this.addprocess("__maintest__","the default test is created by system!");
            #endregion
        }

        public timetest(string testname,string description)
        {
            #region initialize the managertable to save the test cases
            datacolumn  tempcolumn = new datacolumn("name",typeof(system.string));
            manager.columns.add(tempcolumn);
            tempcolumn = new datacolumn("description",typeof(system.string));
            manager.columns.add(tempcolumn);
            tempcolumn = new datacolumn("totaltime",typeof(system.timespan));
            manager.columns.add(tempcolumn);
            tempcolumn = new datacolumn("starttime",typeof(system.datetime));
            manager.columns.add(tempcolumn);
            tempcolumn = new datacolumn("testcount",typeof(system.int32));
            manager.columns.add(tempcolumn);
            manager.primarykey =  new datacolumn[]{manager.columns["name"]};
            #endregion

            #region initialize the timelisttable to save the list of time span
            tempcolumn = new datacolumn("name",typeof(system.string));
            timelist.columns.add(tempcolumn);
            tempcolumn = new datacolumn("time",typeof(system.timespan));
            timelist.columns.add(tempcolumn);
            tempcolumn = new datacolumn("description",typeof(system.string));
            timelist.columns.add(tempcolumn);
            #endregion

            #region initialize a test case
            this.addprocess(testname,description);
            #endregion
        }


        private void addprocess(string testname,string description)
        {
            datarow temprow = this.manager.newrow();
            temprow["name"] = testname;
            temprow["description"] = description;
            temprow["starttime"] = datetime.now;
            temprow["totaltime"] = timespan.zero;
            temprow["testcount"] = 0;
            this.manager.rows.add(temprow);
        }


        #region begin a test
        public void begintest(string testname,string description)
        {
            datarow temprow = this.manager.rows.find(testname);
            if(null != temprow)
            {
                temprow["starttime"] = datetime.now;
            }
            else
            {
                this.addprocess(testname,description);
            }
        }

        public void begintest(string testname)
        {
            this.begintest(testname,"");
        }

        public void begin()
        {
            this.begintest(this.manager.rows[0]["name"].tostring(),"");
        }
        #endregion

        #region end a test
        public void endtest(string testname,string description)
        {
            datarow temprow = this.manager.rows.find(testname);
            if(null == temprow)
            {
                return;
            }
            datetime temptime = (datetime)temprow["starttime"];
//            temprow = this.timelist.newrow();
//            temprow["time"] = datetime.now - temptime;
//            temprow["name"] = testname;
//            temprow["description"] = description;
//            this.timelist.rows.add(temprow);
            this.manager.rows.find(testname)["starttime"] = datetime.now;
            this.manager.rows.find(testname)["totaltime"] = (timespan)(this.manager.rows.find(testname)["totaltime"]) + (datetime.now - temptime);
            this.manager.rows.find(testname)["testcount"] = (int)this.manager.rows.find(testname)["testcount"] + 1;
        }

        public void endtest(string testname)
        {
            this.endtest(testname,"");
        }

        public void end()
        {
            this.endtest(this.manager.rows[0]["name"].tostring(),"");
        }

        public void end(string description)
        {
            this.endtest(this.manager.rows[0]["name"].tostring(),description);
        }
        #endregion

        public datatable gettestlistbyname(string testname)
        {
            datatable rtntable = this.timelist.clone();
            rtntable.columns["time"].datatype = typeof(system.double);
            datarow row;
            foreach(datarow temprow in this.timelist.select("name = '" + testname +"'"))
            {
                row = rtntable.newrow();
                if(temprow["name"].tostring().trim().equals("__maintest__"))
                {
                    row["name"] = "[system default]";
                }
                else
                {
                    row["name"] = temprow["name"];
                }
                row["description"] = temprow["description"];
                row["time"] = ((timespan)temprow["time"]).totalmilliseconds;
                rtntable.rows.add(row);
            }
            return rtntable;
        }

        public datatable gettestlistbyname()
        {
            return gettestlistbyname(this.manager.rows[0]["name"].tostring());
        }

        public double gettesttimebyname(string testname)
        {
            return ((timespan)this.manager.rows.find(testname)["totaltime"]).totalmilliseconds;
        }

        public double gettesttimebyname()
        {
            return gettesttimebyname(this.manager.rows[0]["name"].tostring());
        }

        public datatable getalltesttime()
        {
            datatable rtntable = this.manager.clone();
            rtntable.columns["totaltime"].datatype = typeof(system.double);
            rtntable.columns.remove("starttime");
            datarow row;
            foreach(datarow temprow in this.manager.rows)
            {
                row = rtntable.newrow();
                if(temprow["name"].tostring().trim().equals("__maintest__"))
                {
                    row["name"] = "[system default]";
                }
                else
                {
                    row["name"] = temprow["name"];
                }
                row["description"] = temprow["description"];
                row["totaltime"] = ((timespan)temprow["totaltime"]).totalmilliseconds;
                row["testcount"] = temprow["testcount"];
                rtntable.rows.add(row);
            }
            return rtntable;
        }
        

        public datatable getalltestlist()
        {
            datatable rtntable = this.timelist.clone();
            rtntable.columns["time"].datatype = typeof(system.double);
            datarow row;
            foreach(datarow temprow in this.timelist.rows)
            {
                row = rtntable.newrow();
                if(temprow["name"].tostring().trim().equals("__maintest__"))
                {
                    row["name"] = "[system default]";
                }
                else
                {
                    row["name"] = temprow["name"];
                }
                row["description"] = temprow["description"];
                row["time"] = ((timespan)temprow["time"]).totalmilliseconds;
                rtntable.rows.add(row);
            }
            return rtntable;
        }
    }
}



發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 临江市| 德格县| 叙永县| 松江区| 乌鲁木齐县| 来宾市| 南丰县| 长岛县| 南平市| 达孜县| 繁峙县| 南汇区| 昌邑市| 邵阳县| 玉门市| 清水县| 米泉市| 喀什市| 吐鲁番市| 忻城县| 平远县| 龙游县| 高平市| 峨山| 大石桥市| 城步| 九江市| 万载县| 缙云县| 诸暨市| 双辽市| 乌兰察布市| 横山县| 顺平县| 廊坊市| 商洛市| 绍兴市| 祁连县| 东阿县| 墨竹工卡县| 噶尔县|