コード例 #1
0
        public void Run(Models.ServerModel server, Models.SchtaskModel schtask)
        {
            var    isLocal = Commons.NetHelper.IsLocalIPAddress(server.IP);
            string cmd;

            if (isLocal)
            {
                cmd = string.Format("schtasks /run /tn {0}", schtask.TaskName);
            }
            else
            {
                cmd = string.Format("schtasks /run /s {0} /u {1} /p {2} /tn {3}", server.IP, server.UserName, server.Password, schtask.TaskName);
            }

            var result = CmdHelper.ExecuteCmd(cmd).ToLower();

            if (result.Contains("成功") || result.Contains("success"))
            {
                schtask.TaskStatus = Models.SchtaskStatus.Executed;
            }
            else
            {
                schtask.TaskStatus = Models.SchtaskStatus.Failed;
            }
        }
コード例 #2
0
        public void Query(Models.ServerModel server, Models.SchtaskModel schtask)
        {
            var    isLocal = Commons.NetHelper.IsLocalIPAddress(server.IP);
            string cmd;

            //string chcp437 = "chcp 437";
            //CmdHelper.ExecuteCmd(chcp437);
            if (isLocal)
            {
                cmd = string.Format("schtasks /query /tn {0}", schtask.TaskName);
            }
            else
            {
                cmd = string.Format("schtasks /query /s {0} /u {1} /p {2} /tn {3}", server.IP, server.UserName, server.Password, schtask.TaskName);
            }

            var result = CmdHelper.ExecuteCmd(cmd).ToLower();

            if (result.Contains("任务名") || result.Contains("folder"))
            {
                schtask.TaskStatus = Models.SchtaskStatus.Exist;
            }
            else
            {
                schtask.TaskStatus = Models.SchtaskStatus.NotExist;
            }
        }
コード例 #3
0
        public void CreateTask(Models.ServerModel server, Models.SchtaskModel schtask)
        {
            string time    = DateTime.Now.AddMinutes(-10).ToString("HH:mm");
            var    isLocal = Commons.NetHelper.IsLocalIPAddress(server.IP);

            string cmd;

            if (isLocal)
            {
                cmd = string.Format("schtasks /create /tn {0} /tr {1} /sc once /st {2}", schtask.TaskName, schtask.TaskPath, time);
            }
            else
            {
                cmd = string.Format("schtasks /create /s {0} /u {1} /p {2} /tn {3} /tr {4} /sc once /st {5}", server.IP, server.UserName, server.Password, schtask.TaskName, schtask.TaskPath, time);
            }
            var result = CmdHelper.ExecuteCmd(cmd);

            if (result.Contains("成功") || result.ToLower().Contains("success"))
            {
                schtask.TaskStatus = Models.SchtaskStatus.Exist;
            }
            else
            {
                schtask.TaskStatus = Models.SchtaskStatus.Failed;
            }
        }
コード例 #4
0
        private void runprocess_Click(object sender, RoutedEventArgs e)
        {
            var value = ServerList.SelectedValue;

            if (value == null)
            {
                return;
            }
            var server     = (value as ViewModel.ServerViewModel);
            var pingResult = Commons.NetHelper.Ping(server.IP);

            if (!pingResult)
            {
                return;
            }
            else
            {
                server.State = Models.ServerState.Online;
            }

            Models.SchtaskModel StartModel = new Models.SchtaskModel();
            switch (server.Mode)
            {
            case Models.ServerMode.xPanel:
            {
                StartModel.TaskName = Commons.Constants.xPanel;
                StartModel.TaskPath = Commons.Constants.xPanelBat; break;
            };

            case Models.ServerMode.xSwitch:
            {
                StartModel.TaskName = Commons.Constants.xSwitch;
                StartModel.TaskPath = Commons.Constants.xSwitchBat; break;
            };

            case Models.ServerMode.xServer:
            {
                StartModel.TaskName = Commons.Constants.xServer;
                StartModel.TaskPath = Commons.Constants.xServerBat; break;
            };
            }

            Schtask.Query(server.Server, StartModel);
            if (StartModel.TaskStatus == Models.SchtaskStatus.NotExist)
            {
                Schtask.CreateTask(server.Server, StartModel);
            }
            if (StartModel.TaskStatus == Models.SchtaskStatus.Exist)
            {
                Schtask.Run(server.Server, StartModel);
            }
            else
            {
                server.State = Models.ServerState.Warn;
            }
        }
コード例 #5
0
        private async void btn_shutdown_Click(object sender, RoutedEventArgs e)
        {
            var value = ServerList.SelectedValue;

            if (value == null)
            {
                return;
            }

            var model      = value as ViewModel.ServerViewModel;
            var pingResult = Commons.NetHelper.Ping(model.IP);

            if (!pingResult)
            {
                model.State = Models.ServerState.Off;
                return;
            }
            var mySettings = new MetroDialogSettings
            {
                AffirmativeButtonText = "确定",
                NegativeButtonText    = "取消"
            };

            mySettings.ColorScheme = MetroDialogColorScheme.Accented;
            var strWarnning            = string.Format("是否关闭 {0} ?", model.IP);
            MessageDialogResult result = await this.ShowMessageAsync("...", strWarnning, MessageDialogStyle.AffirmativeAndNegative, mySettings);

            if (result == MessageDialogResult.Affirmative)
            {
                Models.SchtaskModel shutdown = new Models.SchtaskModel
                {
                    TaskName = Commons.Constants.ShutDown,
                    TaskPath = Commons.Constants.ShutDownBat
                };
                Schtask.Query(model.Server, shutdown);
                if (shutdown.TaskStatus == Models.SchtaskStatus.NotExist)
                {
                    Schtask.CreateTask(model.Server, shutdown);
                }
                if (shutdown.TaskStatus == Models.SchtaskStatus.Exist)
                {
                    Schtask.Run(model.Server, shutdown);
                }
                else
                {
                    model.State = Models.ServerState.Warn;
                }
            }
        }
コード例 #6
0
        private async void btn_shutdownall_Click(object sender, RoutedEventArgs e)
        {
            //confirm if shutdown
            var mySettings = new MetroDialogSettings
            {
                AffirmativeButtonText = "确定",
                NegativeButtonText    = "取消"
            };

            mySettings.ColorScheme = MetroDialogColorScheme.Accented;
            MessageDialogResult result = await this.ShowMessageAsync("...", "是否关闭所有设备 ? ", MessageDialogStyle.AffirmativeAndNegative, mySettings);

            if (result == MessageDialogResult.Affirmative)
            {
                foreach (var s in Servers)
                {
                    var pingResult = Commons.NetHelper.Ping(s.IP);
                    if (!pingResult)
                    {
                        s.State = Models.ServerState.Off;
                        continue;
                    }
                    Models.SchtaskModel shutdown = new Models.SchtaskModel()
                    {
                        TaskName = Commons.Constants.ShutDown,
                        TaskPath = Commons.Constants.ShutDownBat
                    };
                    Schtask.Query(s.Server, shutdown);
                    if (shutdown.TaskStatus == Models.SchtaskStatus.NotExist)
                    {
                        Schtask.CreateTask(s.Server, shutdown);
                    }
                    if (shutdown.TaskStatus == Models.SchtaskStatus.Exist)
                    {
                        Schtask.Run(s.Server, shutdown);
                    }
                    else
                    {
                        s.State = Models.ServerState.Warn;
                    }
                }
            }
        }