/// <summary>
        /// Execute ServerCommand based on Command Type
        /// </summary>
        /// <param name="handlerId">Handler for which command is to be executed</param>
        /// <param name="command">Type of the command to be executed</param>
        private void ExecuteCommand(string handlerId, string command)
        {
            ServerCommandContext commandContext = new ServerCommandContext(Services, handlerId, command);
            IServerCommand       serverCommand  = _commandFactory.GetCommand(commandContext);

            serverCommand.Execute();
        }
        public void Execute()
        {
            _writer.Write("Nuclear.Channels.Server version 1.0");
            _writer.Write("Starting the server....");
            _initServerCommand.Execute();
            _writer.Write("Starting the Server Manager....");
            //Wait for handlers to be initialized since IChannelServer will start
            //a new Task for every ChannelMethod
            for (var i = 0; i < 10; i++)
            {
                _methodHandlersList = _methodHandlers.AsList();
                var startingState = 0;
                foreach (var handler in _methodHandlersList)
                {
                    if (handler.State == EntityState.Starting)
                    {
                        startingState++;
                    }
                    else if (handler.State != EntityState.Running)
                    {
                        _writer.Write($"{handler.HandlerId} " +
                                      $"{handler.Url} " +
                                      $"{Enum.GetName(typeof(EntityState),handler.State)}");
                    }
                }


                //Give time for IChannelServer to start all ChannelMethod tasks
                Thread.Sleep(3000);

                if (i <= 2 || startingState != 0)
                {
                    continue;
                }
                {
                    foreach (var handler in _methodHandlersList)
                    {
                        _writer.Write($"{handler.HandlerId} {handler.Url} {handler.State}");
                    }
                    _writer.Write("Server initialized...");
                    return;
                }
            }
        }
Esempio n. 3
0
 private void ProcessCommand(IServerCommand cmd, string[] paramList)
 {
     Task.Run(() => cmd.Execute(paramList));
 }