Exemplo n.º 1
0
 /// <summary>
 /// 启动参数设置
 /// </summary>
 /// <param name="connectionConfig"></param>
 public override void SetupParamOptions(IConnectionConfig connectionConfig)
 {
     if (connectionConfig.Options.Count > 0)
     {
         SocketParam = new WebSocketParam();
         if (connectionConfig.HasOption(WebSocketParamEumns.IsUseCertificate.ToString()))
         {
             SocketParam.IsUseCertificate = Convert.ToBoolean(connectionConfig.GetOption(WebSocketParamEumns.IsUseCertificate.ToString()));
         }
         else if (connectionConfig.HasOption(WebSocketParamEumns.Port.ToString()))
         {
             SocketParam.Port = Convert.ToInt32(connectionConfig.GetOption(WebSocketParamEumns.Port.ToString()));
         }
         else if (connectionConfig.HasOption(WebSocketParamEumns.ServerName.ToString()))
         {
             SocketParam.ServerName = Convert.ToString(connectionConfig.GetOption(WebSocketParamEumns.ServerName.ToString()));
         }
         else if (connectionConfig.HasOption(WebSocketParamEumns.ServerSecurity.ToString()))
         {
             SocketParam.ServerSecurity = Convert.ToString(connectionConfig.GetOption(WebSocketParamEumns.ServerSecurity.ToString()));
         }
         else if (connectionConfig.HasOption(WebSocketParamEumns.ServerStoreName.ToString()))
         {
             SocketParam.ServerStoreName = Convert.ToString(connectionConfig.GetOption(WebSocketParamEumns.ServerStoreName.ToString()));
         }
         else if (connectionConfig.HasOption(WebSocketParamEumns.ServerThumbprint.ToString()))
         {
             SocketParam.ServerThumbprint = Convert.ToString(connectionConfig.GetOption(WebSocketParamEumns.ServerThumbprint.ToString()));
         }
     }
 }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        protected override void BeginProcessing()
        {
            //  初期処理
            WebSocketParam.PrepareDebugMode(DebugMode);
            WebSocketParam.SetCurrentVersion();

            //  ログ開始
            _logger = Function.SetLogger(Item.LOG_DIRECTORY, "Receiver", WebSocketParam.DebugMode);
            _logger.Info("Process Start.");
            _logger.Info("Version: {0}", WebSocketParam.Version);
        }
Exemplo n.º 4
0
        protected override void BeginProcessing()
        {
            //  カレントディレクトリカレントディレクトリの一時変更
            _currentDirectory = System.Environment.CurrentDirectory;
            System.Environment.CurrentDirectory = this.SessionState.Path.CurrentFileSystemLocation.Path;

            //  初期処理
            WebSocketParam.PrepareDebugMode(DebugMode);
            WebSocketParam.SetCurrentVersion();

            //  ログ開始
            _logger = Function.SetLogger(Item.LOG_DIRECTORY, "Sender", WebSocketParam.DebugMode);
            _logger.Info("Process Start.");
            _logger.Info("Version: {0}", WebSocketParam.Version);
        }
Exemplo n.º 5
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.");
        }