예제 #1
0
        public static void OutputBody(DataTable dt)
        {
            try
            {
                string StrBody      = "";
                int    RowsCount    = 0;
                int    ColumnsCount = 0;

                ColumnsCount = dt.Columns.Count;
                RowsCount    = dt.Rows.Count;
                if (RowsCount > 0)
                {
                    for (int i = 0; i < RowsCount; i++)
                    {
                        for (int j = 0; j < ColumnsCount; j++)
                        {
                            StrBody += dt.Columns[j].ToString() + ":" + dt.Rows[i][j].ToString() + "\n";
                        }
                    }
                }
                ConsoleManage.Write(ErrorLevel.Serious, "KNS>>CommClass>>OutputBody", StrBody);
            }
            catch (Exception ex)
            {
                ConsoleManage.Write(ErrorLevel.Serious, "KNS>>CommClass>>OutputBody", ex.Message);
            }
            finally
            {
                GC.Collect();
            }
        }
예제 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ServName"></param>
 /// <param name="ServPath"></param>
 public static void AddToServInfo(string ServName,
                                  string ServPath, string ID, string TYPE
                                  )
 {
     try
     {
         /// <summary>
         /// 添加信息至排麦列表_歌曲属性完整信息
         /// </summary>
         ///
         DataRow newRow;
         newRow             = dt.NewRow();
         newRow["ServName"] = ServName;
         newRow["ServPath"] = ServPath;
         newRow["ID"]       = ID;
         newRow["TYPE"]     = TYPE;
         dt.Rows.Add(newRow);
     }
     catch (Exception ex)
     {
         ConsoleManage.Write(ErrorLevel.Serious,
                             "IsSongServ>>CommonFunction>>AddToServInfo>>",
                             ex.Message);
     }
     finally
     {
         ////GC.Collect();
     }
 }
예제 #3
0
        /// <summary>
        /// 开启服务
        /// </summary>
        /// <param name="ID">服务器ID编号</param>
        /// <param name="TYPE">服务器类型</param>
        /// <param name="ServName">服务名称</param>
        /// <param name="ServPath">服务执行路径</param>
        public static void ServStart(string ID, string TYPE, string ServName, string ServPath)
        {
            ProcessStartInfo info = new ProcessStartInfo();

            info.FileName = ServPath;    // 要启动的程序
            if (CommClass.OStype != 0)
            {
                info.Arguments = CommClass.OStype.ToString();//传递给程序的参数
            }
            else
            {
                //info.UserName = "******";
            }
            info.WindowStyle = ProcessWindowStyle.Hidden;   //隐藏窗口
            //info.UseShellExecute = false;
            if (ExistServ(ServName))
            {
                try
                {
                    Process      pro          = Process.Start(info); //启动程序
                    ServOptState SerInfoState = new ServOptState();  //服务器状态信息
                    SerInfoState.ID       = ID;
                    SerInfoState.TYPE     = TYPE;
                    SerInfoState.OPTSTATE = "0";
                    SerInfoState.NAME     = ServName;
                    OptEvent(SerInfoState);

                    Common.RemoveServStartList(ServName);
                }
                catch (Exception ex)
                {
                    ConsoleManage.Write(ErrorLevel.Serious,
                                        "RobotByServMonitor>>do_Job1>>" + ServName,
                                        ServName + "  start faile!" + ex.Message);
                    //Console.WriteLine(ex.ToString());
                    return;
                }
            }
            else
            {
                ServOptState SerInfoState = new ServOptState();//服务器状态信息
                SerInfoState.ID       = ID;
                SerInfoState.TYPE     = TYPE;
                SerInfoState.OPTSTATE = "-1";
                SerInfoState.NAME     = ServName;
                OptEvent(SerInfoState);

                Common.RemoveServStartList(ServName);
            }

            ServInfoState SerAlareState = new ServInfoState();//服务器状态信息

            SerAlareState.ID    = ID;
            SerAlareState.TYPE  = TYPE;
            SerAlareState.STATE = "1";
            SerAlareState.NAME  = ServName + "[" + ID + "]";
            RobotByServList.AlarmEvent(SerAlareState);
        }
예제 #4
0
        private static void do_Job1(object source, ElapsedEventArgs e)
        {
            try
            {
                AddServStartList();
            }
            catch (Exception ex)
            {
                ConsoleManage.Write(ErrorLevel.Serious,
                                    "RobotByServList>>do_Job1>>", ex.Message);

                return;
            }
        }
예제 #5
0
 /// <summary>
 /// 创建监听服务列表
 /// </summary>
 public static void CreateServInfo()
 {
     try
     {
         DataColumn dc = null;
         dc = dt.Columns.Add("ServName", Type.GetType("System.String"));
         dc = dt.Columns.Add("ServPath", Type.GetType("System.String"));
         dc = dt.Columns.Add("ID", Type.GetType("System.String"));
         dc = dt.Columns.Add("TYPE", Type.GetType("System.String"));
         dc = dt.Columns.Add("APPTYPE", Type.GetType("System.String"));
     }
     catch (Exception ex)
     {
         ConsoleManage.Write(ErrorLevel.Serious,
                             "IsSongServ>>CommonFunction>>CreateSingListTable>>",
                             ex.Message);
     }
     finally
     {
         ////GC.Collect();
     }
 }
예제 #6
0
        private static bool IsInit = true;//
        //private  event ServMonitorAlarmHandlingEvent AlarmEvent;
        /// <summary>
        /// 添加启动服务
        /// </summary>
        /// <param name="ServName">服务名称</param>
        /// <param name="ServPath">服务路径</param>
        public static void AddServStartList()
        {
            string ServName = "";
            string ServPath = "";
            string _ID      = "";
            string _TYPE    = "";
            string _APPTYPE = "";

            try
            {
                if ((Common.DtServInfo.Columns["ID"] == null) ||
                    (Common.DtServInfo.Columns["TYPE"] == null) ||
                    (Common.DtServInfo.Columns["ServName"] == null) ||
                    (Common.DtServInfo.Columns["ServPath"] == null) ||
                    (Common.DtServInfo.Columns["APPTYPE"] == null))
                {
                    return;
                }
                for (int i = 0; i < Common.DtServInfo.Rows.Count; i++)
                {
                    ServName = Common.DtServInfo.Rows[i]["ServName"].ToString();
                    ServPath = Common.DtServInfo.Rows[i]["ServPath"].ToString();
                    _APPTYPE = Common.DtServInfo.Rows[i]["APPTYPE"].ToString();
                    if (Common.DtServInfo.Columns["ID"] != null)
                    {
                        _ID = Common.DtServInfo.Rows[i]["ID"].ToString();
                    }
                    if (Common.DtServInfo.Columns["TYPE"] != null)
                    {
                        _TYPE = Common.DtServInfo.Rows[i]["TYPE"].ToString();
                    }


                    if (_APPTYPE == "1")
                    {
                        ServiceController myController = new System.ServiceProcess.ServiceController(ServName);
                        if (myController.Status == ServiceControllerStatus.Stopped)
                        {
                            if (!Common.NoStartServList.ContainsKey(ServName))
                            {
                                Common.NoStartServList.Add(ServName, ServPath);
                                ServInfoState SerInfoState = new ServInfoState();//服务器状态信息
                                SerInfoState.ID    = _ID;
                                SerInfoState.TYPE  = _TYPE;
                                SerInfoState.STATE = "2";
                                SerInfoState.NAME  = ServName + "[" + _ID + "]";
                                AlarmEvent(SerInfoState);
                            }
                            else
                            {
                                Common.RemoveServStartList(ServName);
                                //if (IsInit)
                                //{
                                ServInfoState SerInfoState = new ServInfoState();//服务器状态信息
                                SerInfoState.ID    = _ID;
                                SerInfoState.TYPE  = _TYPE;
                                SerInfoState.STATE = "1";
                                SerInfoState.NAME  = ServName + "[" + SerInfoState.ID + "]";
                                AlarmEvent(SerInfoState);
                            }
                        }
                    }
                    else if (_APPTYPE == "0")
                    {
                        Process[] myProcess;
                        myProcess = System.Diagnostics.Process.GetProcessesByName(ServName);
                        if (myProcess.Length == 0)
                        {
                            if (!Common.NoStartServList.ContainsKey(ServName))
                            {
                                Common.NoStartServList.Add(ServName, ServPath);
                                ServInfoState SerInfoState = new ServInfoState();//服务器状态信息
                                SerInfoState.ID    = _ID;
                                SerInfoState.TYPE  = _TYPE;
                                SerInfoState.STATE = "2";
                                SerInfoState.NAME  = ServName + "[" + _ID + "]";
                                AlarmEvent(SerInfoState);
                            }
                        }
                        else
                        {
                            Common.RemoveServStartList(ServName);
                            //if (IsInit)
                            //{
                            ServInfoState SerInfoState = new ServInfoState();//服务器状态信息
                            SerInfoState.ID    = _ID;
                            SerInfoState.TYPE  = _TYPE;
                            SerInfoState.STATE = "1";
                            SerInfoState.NAME  = ServName + "[" + SerInfoState.ID + "]";
                            AlarmEvent(SerInfoState);
                            //}
                        }
                    }
                }
                IsInit = false;
            }
            catch (Exception ex)
            {
                ConsoleManage.Write(ErrorLevel.Serious, "ServMonitor>>RobotByServList>>AddServStartList>>", ex.Message);
                return;
            }
        }
예제 #7
0
        private void do_Job1(object source, ElapsedEventArgs e)
        {
            if (ExistServ(_ServName))
            {
                ServInfoState SerInfoState = new ServInfoState();//服务器状态信息
                if (APPTYPE == "1")
                {
                    ServiceController myController = new System.ServiceProcess.ServiceController(_ServName);
                    myController.Start();
                    //myController.Pause();
                    //myController.Continue();
                    //myController.Stop();
                    myController.Refresh();
                    IsMsgShow = true;
                    ConsoleManage.Write(ErrorLevel.Serious,
                                        "RobotByServMonitor>>do_Job1>>" + _ServName,
                                        _ServName + " start Sourcess!");
                    SerInfoState.ID    = _ID;
                    SerInfoState.TYPE  = _TYPE;
                    SerInfoState.STATE = "1";
                    SerInfoState.NAME  = ServName + "[" + SerInfoState.ID + "]";
                    AlarmEvent(SerInfoState);

                    Common.RemoveServStartList(_ServName);
                }
                else if (APPTYPE == "0")
                {
                    ProcessStartInfo info = new ProcessStartInfo();
                    info.FileName = _ServPath;    // 要启动的程序
                    ConsoleManage.Write(ErrorLevel.Serious,
                                        "RobotByServMonitor>>do_Job1>>" + _ServPath,
                                        " Test Show!");
                    if (CommClass.OStype != 0)
                    {
                        info.Arguments = CommClass.OStype.ToString();//传递给程序的参数
                    }
                    else
                    {
                        //info.UserName = "******";
                        //info.Arguments = "&";//传递给程序的参数
                    }
                    info.WindowStyle = ProcessWindowStyle.Hidden;   //隐藏窗口
                    //info.UseShellExecute = false;


                    try
                    {
                        Process pro = Process.Start(info); //启动程序
                        IsMsgShow = true;
                        ConsoleManage.Write(ErrorLevel.Serious,
                                            "RobotByServMonitor>>do_Job1>>" + _ServName,
                                            _ServName + " start Sourcess!");
                        /*ServInfoState*/
                        SerInfoState.ID    = _ID;
                        SerInfoState.TYPE  = _TYPE;
                        SerInfoState.STATE = "1";
                        SerInfoState.NAME  = ServName + "[" + SerInfoState.ID + "]";
                        AlarmEvent(SerInfoState);
                        Common.RemoveServStartList(_ServName);
                    }
                    catch (Exception ex)
                    {
                        if (IsMsgShow)
                        {
                            ConsoleManage.Write(ErrorLevel.Serious,
                                                "RobotByServMonitor>>do_Job1>>" + _ServName,
                                                _ServName + "  start faile!" + ex.ToString());
                            //Console.WriteLine(ex.ToString());
                        }
                        IsMsgShow = false;

                        //Stop();
                        return;
                    }
                }
            }
        }