Пример #1
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);
        }
Пример #2
0
        /// <summary>
        /// 停止服务
        /// </summary>
        /// <param name="ID">服务器ID编号</param>
        /// <param name="TYPE">服务器类型</param>
        /// <param name="ServName">服务名称</param>
        public static void  ServStop(string ID, string TYPE, string ServName)
        {
            try
            {
                Process[] myProcess;
                myProcess = System.Diagnostics.Process.GetProcessesByName(ServName);
                Console.WriteLine(ServName + "    " + "ServStop myProcess.Length=" + myProcess.Length.ToString());
                if (myProcess.Length > 0)
                {
                    Console.WriteLine(myProcess[0].ProcessName.ToString());
                    //myProcess[0].Close();
                    myProcess[0].Kill();
                    ServOptState SerInfoState = new ServOptState();//服务器状态信息
                    SerInfoState.ID       = ID;
                    SerInfoState.TYPE     = TYPE;
                    SerInfoState.OPTSTATE = "0";
                    SerInfoState.NAME     = ServName;
                    OptEvent(SerInfoState);

                    ServInfoState SerAlareState = new ServInfoState();//服务器状态信息
                    SerAlareState.ID    = ID;
                    SerAlareState.TYPE  = TYPE;
                    SerAlareState.STATE = "2";
                    SerAlareState.NAME  = ServName + "[" + ID + "]";
                    RobotByServList.AlarmEvent(SerAlareState);

                    ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadAddServList), ServName);
                }
                else
                {
                    ServOptState SerInfoState = new ServOptState();//服务器状态信息
                    SerInfoState.ID       = ID;
                    SerInfoState.TYPE     = TYPE;
                    SerInfoState.OPTSTATE = "-2";
                    SerInfoState.NAME     = ServName;
                    OptEvent(SerInfoState);


                    ServInfoState SerAlareState = new ServInfoState();//服务器状态信息
                    SerAlareState.ID    = ID;
                    SerAlareState.TYPE  = TYPE;
                    SerAlareState.STATE = "2";
                    SerAlareState.NAME  = ServName + "[" + ID + "]";
                    RobotByServList.AlarmEvent(SerAlareState);
                }
            }
            catch
            {
                return;
            }
        }
Пример #3
0
        ///// <summary>
        ///// 开启服务
        ///// </summary>
        ///// <param name="ID">服务器ID编号</param>
        ///// <param name="TYPE">服务器类型</param>
        ///// <param name="resqust">连接对像返回给谁</param>
        //public static void ServStart(string ID, string TYPE,StateObject resqust)
        //{
        //    try
        //    {
        //        string ServName = "";
        //        string ServPath = "";
        //        GetServOptInfo(ID, TYPE, ref ServName, ref ServPath);
        //        ServMag.ServStart(ID, TYPE, ServName, ServPath, resqust);
        //    }
        //    catch
        //    {
        //        return;
        //    }
        //}

        ///// <summary>
        ///// 停止服务
        ///// </summary>
        ///// <param name="ID">服务器ID编号</param>
        ///// <param name="TYPE">服务器类型</param>
        ///// <param name="resqust">连接对像返回给谁</param>
        //public static void ServStop(string ID, string TYPE, StateObject resqust)
        //{
        //    try
        //    {
        //        string ServName = "";
        //        string ServPath = "";
        //        GetServOptInfo(ID, TYPE, ref ServName, ref ServPath);
        //        ServMag.ServStop(ID, TYPE, ServName, resqust);
        //    }
        //    catch
        //    {
        //        return;
        //    }
        //}

        ///// <summary>
        ///// 重启服务
        ///// </summary>
        ///// <param name="ID">服务器ID编号</param>
        ///// <param name="TYPE">服务器类型</param>
        ///// <param name="resqust">连接对像返回给谁</param>
        //public static void ServRestart(string ID, string TYPE, StateObject resqust)
        //{
        //    try
        //    {
        //        string ServName = "";
        //        string ServPath = "";
        //        GetServOptInfo(ID, TYPE, ref ServName, ref ServPath);
        //        ServMag.ServRestart(ID, TYPE, ServName, ServPath, resqust);
        //    }
        //    catch
        //    {
        //        return;
        //    }
        //}



        public static void MonitorAlarmEvent(ServInfoState sender)
        {
            try
            {
                if (AlarmEvent != null)
                {
                    AlarmEvent(sender);
                }
            }
            catch
            {
                return;
            }
        }
Пример #4
0
 public static void AlarmEvent(ServInfoState sender)
 {
     try
     {
         //Console.WriteLine(sender.ToString());
         MonitorInterface.MonitorAlarmEvent(sender);
     }
     catch (Exception ex)
     {
         //Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Serious, "BusinessDAL.KNS>>tcpClient_ExceptionHandlingEvent>>ReceiveEvent>>", ex.Message);
     }
     finally
     {
     }
 }
Пример #5
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;
            }
        }
Пример #6
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;
                    }
                }
            }
        }