Ejemplo n.º 1
0
 private static void ConsoleCancelKeyPress(object sender, ConsoleCancelEventArgs consoleCancelEventArgs)
 {
     //取消此控制台的^c指令
     consoleCancelEventArgs.Cancel = true;
     //并转发到已附加的单元
     if (String.IsNullOrWhiteSpace(AttachedUnitKey))
     {
         return;
     }
     RemoteControlModule.CommandlineRequest(AttachedUnitKey, 9, String.Empty);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 执行指令
        /// </summary>
        /// <param name="args"></param>
        private static void InvokeCommand(String[] args)
        {
            String command        = args[0];
            String argumentValue1 = args.GetLength(0) > 1?args[1]:null;

            //String argumentValue2=args.GetLength(0)>2?args[2]:null;
            //非远程控制指令
            if (!CommandHelper.IsRemoteCommand(command))
            {
                switch (command)
                {
                case "version": CommandHelper.Version(); break;

                default: CommandHelper.Help(); break;
                }
                return;
            }
            //需要验证unitKey
            if (!CommandHelper.RequireUnitKey(command, argumentValue1))
            {
                Console.WriteLine("command execute failed,invalid unitKey");
                return;
            }
            //链接服务端
            if (!RemoteControlModule.Useable)
            {
                Console.WriteLine("command execute failed,remote control module not initialized");
                return;
            }
            if (!RemoteControlModule.Start())
            {
                Console.WriteLine("command execute failed,can not connect to daemon service");
                return;
            }
            if (!RemoteControlModule.Valid())
            {
                Console.WriteLine("command execute failed,connection invalid");
                return;
            }
            //执行远程控制指令
            switch (command)
            {
            case "status": RemoteControlModule.StatusRequest(argumentValue1); break;

            case "start": RemoteControlModule.StartRequest(argumentValue1); break;

            case "stop": RemoteControlModule.StopRequest(argumentValue1); break;

            case "restart": RemoteControlModule.RestartRequest(argumentValue1); break;

            case "load": RemoteControlModule.LoadRequest(argumentValue1); break;

            case "remove": RemoteControlModule.RemoveRequest(argumentValue1); break;

            case "logs": RemoteControlModule.LogsRequest(argumentValue1); break;

            case "attach":
                AttachedUnitKey = argumentValue1;
                RemoteControlModule.LogsRequest(AttachedUnitKey);
                break;

            case "status-all": RemoteControlModule.StatusAllRequest(); break;

            case "start-all": RemoteControlModule.StartAllRequest(); break;

            case "stop-all": RemoteControlModule.StopAllRequest(); break;

            case "restart-all": RemoteControlModule.RestartAllRequest(); break;

            case "load-all": RemoteControlModule.LoadAllRequest(); break;

            case "remove-all": RemoteControlModule.RemoveAllRequest(); break;

            case "daemon-version": RemoteControlModule.DaemonVersionRequest(); break;

            case "daemon-status": RemoteControlModule.DaemonStatusRequest(); break;

            case "daemon-shutdown": RemoteControlModule.DaemonShutdownRequest(); break;

            default: CommandHelper.Help(); break;
            }
            //等待查询完成
            if (command == "attach")
            {
                SpinWait.SpinUntil(() => false, 1000);
                while (!String.IsNullOrWhiteSpace(AttachedUnitKey))
                {
                    String attachedCommandLine = Console.ReadLine();
                    if (String.IsNullOrWhiteSpace(attachedCommandLine))
                    {
                        continue;
                    }
                    RemoteControlModule.CommandlineRequest(AttachedUnitKey, 1, attachedCommandLine.Trim());
                }
            }
            else
            {
                SpinWait.SpinUntil(() => !InAction, 8000);
            }
        }