public override void LogListLog(VBALogLevelFlag level, string message)
 {
     if (MessageEvent != null)
     {
         MessageEvent(level, message);
     }
     WaitOne();
 }
 public virtual void LogListLog(VBALogLevelFlag level, string message)
 {
     if (m_loglevelstartard <= level)
     {
         LogList l = new LogList();
         l.errtime    = DateTime.Now;
         l.errlevel   = level;
         l.errmessage = message;
         m_loglist.Add(l);
     }
 }
        public static void MessageHandler(VBALogLevelFlag vflag, string message)
        {
            if (ms_dgv.InvokeRequired)
            {
                MessageHandlerInvokor m1 = new MessageHandlerInvokor(MessageHandler);
                ms_dgv.BeginInvoke(m1, new object[] { vflag, message });
            }
            else
            {
                //加入dataview
                ms_dgv.Rows.Insert(0, new object[] { ms_levelpics[vflag], vflag, message });

                lock (TestProccessStatusLocker)
                {
                    if (ms_tps == TestProcessStatus.Singlestep_Running)
                    {
                        //改变tps
                        ms_tps = TestProcessStatus.Singlestep_Pause;
                        RefreshTestToolButtons();
                    }
                }
            }
        }
 public override void LogListLog(VBALogLevelFlag level, string message)
 {
     if (MessageEvent != null)
         MessageEvent(level, message);
     WaitOne();
 }
 /// <summary>
 /// 用来反序列化的构造函数
 /// </summary>
 protected VBALog(System.Runtime.Serialization.SerializationInfo s, System.Runtime.Serialization.StreamingContext c)
 {
     m_loglist          = s.GetValue("Log", m_loglist.GetType()) as List <LogList>;
     m_loglevelstartard = (VBALogLevelFlag)s.GetValue("LogLevel", m_loglevelstartard.GetType());
 }
 public VBALog(VBALogLevelFlag loglevel)
 {
     m_loglevelstartard = loglevel;
 }
 public static void DataGridViewLoadLog(Domain d, string TaskGUID, System.Windows.Forms.DataGridView dgv, Dictionary<VBALogLevelFlag, Image> levelpics, VBALogLevelFlag dflags, int logloadlimit)
 {
     LoadLogBase(d, TaskGUID, dgv, levelpics, dflags ,logloadlimit);
 }
 public static void DataGridViewLoadLog(Domain d, string TaskGUID, System.Windows.Forms.DataGridView dgv, Dictionary <VBALogLevelFlag, Image> levelpics, VBALogLevelFlag dflags, int logloadlimit)
 {
     LoadLogBase(d, TaskGUID, dgv, levelpics, dflags, logloadlimit);
 }
 public VBALog(VBALogLevelFlag loglevel)
 {
     m_loglevelstartard = loglevel;
 }
        public static void MessageHandler(VBALogLevelFlag vflag, string message)
        {
            if (ms_dgv.InvokeRequired)
            {
                MessageHandlerInvokor m1 = new MessageHandlerInvokor(MessageHandler);
                ms_dgv.BeginInvoke(m1, new object[] { vflag, message });
            }
            else
            {
                //加入dataview
                ms_dgv.Rows.Insert(0, new object[] { ms_levelpics[vflag], vflag, message });

                lock (TestProccessStatusLocker)
                {
                    if (ms_tps == TestProcessStatus.Singlestep_Running)
                    {
                        //改变tps
                        ms_tps = TestProcessStatus.Singlestep_Pause;
                        RefreshTestToolButtons();
                    }
                }
            }
        }
 public void LevelFlagsToButtonStatus(VBALogLevelFlag dflags)
 {
     //Debug
     if ((VBALogLevelFlag.Debug & dflags) != 0)
         debug_toolStripButton.Checked = true;
     else
         debug_toolStripButton.Checked = false;
     //Info
     if ((VBALogLevelFlag.Info & dflags) != 0)
         info_toolStripButton.Checked = true;
     else
         info_toolStripButton.Checked = false;
     //Warn
     if ((VBALogLevelFlag.Warn & dflags) != 0)
         warn_toolStripButton.Checked = true;
     else
         warn_toolStripButton.Checked = false;
     //Error
     if ((VBALogLevelFlag.Error & dflags) != 0)
         error_toolStripButton.Checked = true;
     else
         error_toolStripButton.Checked = false;
     //Fatal
     if ((VBALogLevelFlag.Fatal & dflags) != 0)
         fatal_toolStripButton.Checked = true;
     else
         fatal_toolStripButton.Checked = false;
 }
 private int LevelFlagToInt(VBALogLevelFlag dflag)
 {
     int i = 0;
     //Debug
     if ((VBALogLevelFlag.Debug & dflag) != 0)
         i = 0;
     //Info
     if ((VBALogLevelFlag.Info & dflag) != 0)
         i = 1;            
     //Warn
     if ((VBALogLevelFlag.Warn & dflag) != 0)
         i = 2;            
     //Error
     if ((VBALogLevelFlag.Error & dflag) != 0)
         i = 3;
     //Fatal
     if ((VBALogLevelFlag.Fatal & dflag) != 0)
         i = 4;
     return i;
 }
 public void LogListLog(VBALogLevelFlag level, string message)
 {
     m_vbalog.LogListLog(level, message);
 }
 public override void LogListLog(VBALogLevelFlag level, string message)
 {
     throw new Exception("VBAEngine Stopping Exception!");
 }
 public void LogListLog(VBALogLevelFlag level, string message)
 {
     m_vbalog.LogListLog(level, message);
 }
 public override void LogListLog(VBALogLevelFlag level, string message)
 {
     throw new Exception("VBAEngine Stopping Exception!");
 }
        //public static void DataGridViewLoadLog(Domain d, System.Windows.Forms.DataGridView dgv, Dictionary<string, Image> levelpics)
        //{
        //    using (OleDbConnection logdbcon = new OleDbConnection(ms_connstring))
        //    {
        //        string cmdstr = null;
        //        OleDbDataReader dr = null;
        //        Image levelpic = null;
        //        string levelstring = null;
        //        try
        //        {
        //            logdbcon.Open();
        //            cmdstr = "SELECT TOP 1000 TaskChainGUID,LogTime,LogLevel,LogMessage FROM Log WHERE DomainGUID = '" + d.DomainGUID + "' ORDER BY LogTime DESC";
        //            OleDbCommand cmd = new OleDbCommand(cmdstr, logdbcon);
        //            dr = cmd.ExecuteReader();

        //            while (dr.Read())
        //            {
        //                //得到level图片
        //                switch (((string)dr["LogLevel"]).ToLower())
        //                {
        //                    case "debug":
        //                        levelpic = levelpics["Debug"];
        //                        levelstring = "调试";
        //                        break;
        //                    case "info":
        //                        levelpic = levelpics["Info"];
        //                        levelstring = "信息";
        //                        break;
        //                    case "warn":
        //                        levelpic = levelpics["Warn"];
        //                        levelstring = "警告";
        //                        break;
        //                    case "error":
        //                        levelpic = levelpics["Error"];
        //                        levelstring = "错误";
        //                        break;
        //                    case "fatal":
        //                        levelpic = levelpics["Fatal"];
        //                        levelstring = "致命错误";
        //                        break;
        //                }

        //                DataGridViewRow r = new DataGridViewRow();
        //                dgv.Rows.Add(new object[] { levelpic, levelstring, dr["LogTime"], dr["TaskChainGUID"], dr["LogMessage"] });
        //            }
        //        }
        //        catch (OleDbException e)
        //        {
        //            log.Error("读取Log数据库错误:" + cmdstr, e);
        //        }
        //        catch (Exception e)
        //        {
        //            log.Error(e);
        //        }

        //    }
        //}

        private static void LoadLogBase(Domain d, string TaskGUID, System.Windows.Forms.DataGridView dgv, Dictionary <VBALogLevelFlag, Image> levelpics, VBALogLevelFlag dflags, int logloadlimit)
        {
            using (OleDbConnection logdbcon = new OleDbConnection(ms_connstring))
            {
                string          cmdstr          = null;
                OleDbDataReader dr              = null;
                Image           levelpic        = null;
                string          levelstring     = null;
                string          wherestring     = null;
                List <string>   levelflagstring = new List <string>();

                //一个都没的情况
                if (dflags == 0)
                {
                    return;
                }
                else
                {
                    //全有的情况
                    if (dflags == (VBALogLevelFlag.Debug | VBALogLevelFlag.Error | VBALogLevelFlag.Fatal |
                                   VBALogLevelFlag.Info | VBALogLevelFlag.Warn))
                    {
                        if (TaskGUID == null)
                        {
                            wherestring = "WHERE DomainGUID = '" + d.DomainGUID + "'";
                        }
                        else
                        {
                            wherestring = "WHERE DomainGUID = '" + d.DomainGUID + "' AND TaskChainGUID = '" + TaskGUID + "'";
                        }
                    }
                    else
                    {
                        //Debug
                        if ((VBALogLevelFlag.Debug & dflags) != 0)
                        {
                            levelflagstring.Add("LogLevel = 'Debug'");
                        }
                        //Info
                        if ((VBALogLevelFlag.Info & dflags) != 0)
                        {
                            levelflagstring.Add("LogLevel = 'Info'");
                        }
                        //Warn
                        if ((VBALogLevelFlag.Warn & dflags) != 0)
                        {
                            levelflagstring.Add("LogLevel = 'Warn'");
                        }
                        //Error
                        if ((VBALogLevelFlag.Error & dflags) != 0)
                        {
                            levelflagstring.Add("LogLevel = 'Error'");
                        }
                        //Fatal
                        if ((VBALogLevelFlag.Fatal & dflags) != 0)
                        {
                            levelflagstring.Add("LogLevel = 'Fatal'");
                        }

                        //构造查询WHERE字段
                        int i = 1;

                        if (TaskGUID == null)
                        {
                            wherestring = "WHERE DomainGUID = '" + d.DomainGUID + "' AND (";
                        }
                        else
                        {
                            wherestring = "WHERE DomainGUID = '" + d.DomainGUID + "' AND TaskChainGUID = '" + TaskGUID + "' AND (";
                        }

                        foreach (string s in levelflagstring)
                        {
                            wherestring = wherestring + s;
                            if (i != levelflagstring.Count)
                            {
                                wherestring = wherestring + " OR ";
                            }
                            i++;
                        }
                        wherestring = wherestring + ")";
                    }
                }

                try
                {
                    //关闭复杂排版
                    dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
                    dgv.Columns["DomainLogLevel"].AutoSizeMode    = DataGridViewAutoSizeColumnMode.None;
                    dgv.Columns["DomainLogDateTime"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;

                    //读取Log数据
                    logdbcon.Open();
                    cmdstr = "SELECT TOP " + logloadlimit.ToString() + " TaskChainGUID,LogTime,LogLevel,LogMessage FROM Log " + wherestring + " ORDER BY logtime DESC;";
                    OleDbCommand cmd = new OleDbCommand(cmdstr, logdbcon);
                    dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        //得到level图片
                        switch (((string)dr["LogLevel"]).ToLower())
                        {
                        case "debug":
                            levelpic    = levelpics[VBALogLevelFlag.Debug];
                            levelstring = "调试";
                            break;

                        case "info":
                            levelpic    = levelpics[VBALogLevelFlag.Info];
                            levelstring = "信息";
                            break;

                        case "warn":
                            levelpic    = levelpics[VBALogLevelFlag.Warn];
                            levelstring = "警告";
                            break;

                        case "error":
                            levelpic    = levelpics[VBALogLevelFlag.Error];
                            levelstring = "错误";
                            break;

                        case "fatal":
                            levelpic    = levelpics[VBALogLevelFlag.Fatal];
                            levelstring = "致命错误";
                            break;
                        }
                        dgv.Rows.Add(new object[] { levelpic, levelstring, dr["LogTime"], dr["TaskChainGUID"], dr["LogMessage"] });
                        Application.DoEvents();
                    }

                    //排版
                    dgv.Columns["DomainLogLevel"].AutoSizeMode    = DataGridViewAutoSizeColumnMode.AllCells;
                    dgv.Columns["DomainLogDateTime"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;
                    dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
                }
                catch (OleDbException e)
                {
                    log.Error("读取Log数据库错误:" + cmdstr, e);
                }
                catch (Exception e)
                {
                    log.Error(e);
                }
            }
        }
 /// <summary>
 /// 用来反序列化的构造函数
 /// </summary>
 protected VBALog(System.Runtime.Serialization.SerializationInfo s, System.Runtime.Serialization.StreamingContext c)
 {
     m_loglist = s.GetValue("Log", m_loglist.GetType()) as List<LogList>;
     m_loglevelstartard = (VBALogLevelFlag)s.GetValue("LogLevel", m_loglevelstartard.GetType());
 }
 public virtual void LogListLog(VBALogLevelFlag level, string message)
 {
     if (m_loglevelstartard <= level)
     {
         LogList l = new LogList();
         l.errtime = DateTime.Now;
         l.errlevel = level;
         l.errmessage = message;
         m_loglist.Add(l);
     }
 }
        //public static void DataGridViewLoadLog(Domain d, System.Windows.Forms.DataGridView dgv, Dictionary<string, Image> levelpics)
        //{
        //    using (OleDbConnection logdbcon = new OleDbConnection(ms_connstring))
        //    {
        //        string cmdstr = null;
        //        OleDbDataReader dr = null;
        //        Image levelpic = null;
        //        string levelstring = null;
        //        try
        //        {
        //            logdbcon.Open();
        //            cmdstr = "SELECT TOP 1000 TaskChainGUID,LogTime,LogLevel,LogMessage FROM Log WHERE DomainGUID = '" + d.DomainGUID + "' ORDER BY LogTime DESC";
        //            OleDbCommand cmd = new OleDbCommand(cmdstr, logdbcon);
        //            dr = cmd.ExecuteReader();
                    
        //            while (dr.Read())
        //            {
        //                //得到level图片
        //                switch (((string)dr["LogLevel"]).ToLower())
        //                {
        //                    case "debug":
        //                        levelpic = levelpics["Debug"];
        //                        levelstring = "调试";
        //                        break;
        //                    case "info":
        //                        levelpic = levelpics["Info"];
        //                        levelstring = "信息";
        //                        break;
        //                    case "warn":
        //                        levelpic = levelpics["Warn"];
        //                        levelstring = "警告";
        //                        break;
        //                    case "error":
        //                        levelpic = levelpics["Error"];
        //                        levelstring = "错误";
        //                        break;
        //                    case "fatal":
        //                        levelpic = levelpics["Fatal"];
        //                        levelstring = "致命错误";
        //                        break;
        //                }

        //                DataGridViewRow r = new DataGridViewRow();                        
        //                dgv.Rows.Add(new object[] { levelpic, levelstring, dr["LogTime"], dr["TaskChainGUID"], dr["LogMessage"] });
        //            }
        //        }
        //        catch (OleDbException e)
        //        {
        //            log.Error("读取Log数据库错误:" + cmdstr, e);
        //        }
        //        catch (Exception e)
        //        {
        //            log.Error(e);
        //        }

        //    }
        //}

        private static void LoadLogBase(Domain d, string TaskGUID, System.Windows.Forms.DataGridView dgv, Dictionary<VBALogLevelFlag, Image> levelpics, VBALogLevelFlag dflags, int logloadlimit)
        {

            using (OleDbConnection logdbcon = new OleDbConnection(ms_connstring))
            {
                string cmdstr = null;
                OleDbDataReader dr = null;
                Image levelpic = null;
                string levelstring = null;
                string wherestring = null;
                List<string> levelflagstring = new List<string>();

                //一个都没的情况
                if (dflags == 0)
                    return;
                else
                {
                    //全有的情况
                    if (dflags == (VBALogLevelFlag.Debug | VBALogLevelFlag.Error | VBALogLevelFlag.Fatal |
                                  VBALogLevelFlag.Info | VBALogLevelFlag.Warn))
                        if (TaskGUID == null)
                        {
                            wherestring = "WHERE DomainGUID = '" + d.DomainGUID + "'";
                        }
                        else
                        {
                            wherestring = "WHERE DomainGUID = '" + d.DomainGUID + "' AND TaskChainGUID = '" + TaskGUID + "'";
                        }
                    else
                    {
                        //Debug
                        if ((VBALogLevelFlag.Debug & dflags) != 0)
                            levelflagstring.Add("LogLevel = 'Debug'");
                        //Info
                        if ((VBALogLevelFlag.Info & dflags) != 0)
                            levelflagstring.Add("LogLevel = 'Info'");
                        //Warn
                        if ((VBALogLevelFlag.Warn & dflags) != 0)
                            levelflagstring.Add("LogLevel = 'Warn'");
                        //Error
                        if ((VBALogLevelFlag.Error & dflags) != 0)
                            levelflagstring.Add("LogLevel = 'Error'");
                        //Fatal
                        if ((VBALogLevelFlag.Fatal & dflags) != 0)
                            levelflagstring.Add("LogLevel = 'Fatal'");

                        //构造查询WHERE字段
                        int i = 1;

                        if (TaskGUID == null)
                        {
                            wherestring = "WHERE DomainGUID = '" + d.DomainGUID + "' AND (";
                        }
                        else
                        {
                            wherestring = "WHERE DomainGUID = '"+ d.DomainGUID+ "' AND TaskChainGUID = '" + TaskGUID + "' AND (";
                        }

                        foreach (string s in levelflagstring)
                        {
                            wherestring = wherestring + s;
                            if (i != levelflagstring.Count)
                                wherestring = wherestring + " OR ";
                            i++;
                        }
                        wherestring = wherestring + ")";
                    }
                }

                try
                {
                    //关闭复杂排版
                    dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
                    dgv.Columns["DomainLogLevel"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                    dgv.Columns["DomainLogDateTime"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;

                    //读取Log数据
                    logdbcon.Open();
                    cmdstr = "SELECT TOP " + logloadlimit.ToString() + " TaskChainGUID,LogTime,LogLevel,LogMessage FROM Log " + wherestring + " ORDER BY logtime DESC;";
                    OleDbCommand cmd = new OleDbCommand(cmdstr, logdbcon);
                    dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        //得到level图片
                        switch (((string)dr["LogLevel"]).ToLower())
                        {
                            case "debug":
                                levelpic = levelpics[VBALogLevelFlag.Debug];
                                levelstring = "调试";
                                break;
                            case "info":
                                levelpic = levelpics[VBALogLevelFlag.Info];
                                levelstring = "信息";
                                break;
                            case "warn":
                                levelpic = levelpics[VBALogLevelFlag.Warn];
                                levelstring = "警告";
                                break;
                            case "error":
                                levelpic = levelpics[VBALogLevelFlag.Error];
                                levelstring = "错误";
                                break;
                            case "fatal":
                                levelpic = levelpics[VBALogLevelFlag.Fatal];
                                levelstring = "致命错误";
                                break;
                        }
                        dgv.Rows.Add(new object[] { levelpic, levelstring, dr["LogTime"], dr["TaskChainGUID"], dr["LogMessage"] });
                        Application.DoEvents();

                    }

                    //排版
                    dgv.Columns["DomainLogLevel"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                    dgv.Columns["DomainLogDateTime"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;
                    dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
                }
                catch (OleDbException e)
                {
                    log.Error("读取Log数据库错误:" + cmdstr, e);
                }
                catch (Exception e)
                {
                    log.Error(e);
                }

            }
        }