示例#1
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;
            }
        }
示例#2
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;
                }
            }
        }
示例#3
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;
                    }
                }
            }
        }