예제 #1
0
        protected override void ProcessRecord()
        {
            _logger.Info("ServerPrefiexes: {0}", string.Join(", ", WebSocketParam.ServerPrefixes));

            using (Item.WssHandle = new WebSocketServer())
            {
                _logger.Debug("Set cancel event.");
                Console.CancelKeyPress += (sender, e) =>
                {
                    e.Cancel = false;
                    if (Item.WssHandle != null)
                    {
                        Item.WssHandle.Stop();
                    }
                    _logger.Info("Cancel key entered.");
                };
                Item.UnassignedCancelEvent = false;

                //  ワーキングセットを定期的に縮小化
                _logger.Info("Start ShrinkWorkingSet Thread.");
                WorkingSet.Shrink().ConfigureAwait(false);

                //  WebSocket待ち受け開始
                _logger.Info("Start WebSocket Server.");
                Item.WssHandle.Start().Wait();
            }

            //  終了処理
            _logger.Info("Stop WebSocket Server.");
            _logger.Info("Process End.");
            WebSocketParam.ClearConfig();
            Item.WssHandle = null;
        }
예제 #2
0
        protected override void ProcessRecord()
        {
            _logger.Info("Connect URI: {0}", Target);
            SessionBase session = new CmdSession();

            session.Connect(Target).ConfigureAwait(false);
            session.Init().Wait();

            if (session.Enabled)
            {
                try
                {
                    session.Send().ConfigureAwait(false);

                    WebSocketConnect.SessionInfo.CommandInfo info = new WebSocketConnect.SessionInfo.CommandInfo();
                    if (this.PowerShell)
                    {
                        info.Mode = WebSocketConnect.SessionInfo.CommandInfo.CommandMode.PowerShell;
                    }

                    if (!string.IsNullOrEmpty(Command))
                    {
                        //  リモートコマンド
                        info.Command = Command;
                        session.Request(info).ConfigureAwait(false);
                        while (session.Status < SessionStatus.Finished)
                        {
                            Thread.Sleep(_interval);
                        }
                        session.Close().ConfigureAwait(false);
                    }
                    else if (!string.IsNullOrEmpty(ScriptFile) && File.Exists(ScriptFile))
                    {
                        info.Mode = WebSocketConnect.SessionInfo.CommandInfo.CommandMode.Script;

                        //  リモートスクリプト
                        info.LoadScript(ScriptFile);
                        session.Request(info).ConfigureAwait(false);
                        while (session.Status < SessionStatus.Finished)
                        {
                            Thread.Sleep(_interval);
                        }
                        session.Close().ConfigureAwait(false);
                    }

                    if (!string.IsNullOrEmpty(session.Remark))
                    {
                        _logger.Info(session.Remark);
                    }
                }
                catch (Exception e)
                {
                    _logger.Error("Error: Error ccurred during WebSocket Connection.");
                    _logger.Error(e.ToString());
                }
            }

            if (!string.IsNullOrEmpty(session.Remark))
            {
                _logger.Info(session.Remark);
            }

            WebSocketParam.ClearConfig();
            _logger.Info("Process End.");
        }