Пример #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
        private static void RobotByServListStart(object obj)
        {
            //RobotByServList.AddServStartList();
            //RobotByServList RbSl = new RobotByServList();
            //RbSl.AddServStartList();
            //RbSl.Interval = 20000;
            //RbSl.Start();

            RobotByServList.AddServStartList();
            RobotByServList.Interval = 3000;
            RobotByServList.Start();
        }
Пример #3
0
 /// <summary>
 /// 进程操作添加服务列表
 /// </summary>
 /// <param name="obj"></param>
 private static void ThreadAddServList(object obj)
 {
     try
     {
         string ServName = (string)obj;
         //Common.RemoveServStartList(ServName);
         RobotByServList.AddServStartList(ServName);
     }
     catch
     {
         return;
     }
 }
Пример #4
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;
            }
        }