Exemple #1
0
 private Commands.GetQpInstructions.Response getQpInstructions(QpChannel handler, Commands.GetQpInstructions.Request request)
 {
     return(new Commands.GetQpInstructions.Response()
     {
         Data = options.InstructionSet
     });
 }
        /// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="handler"></param>
        /// <param name="cmdRequestTypeName"></param>
        /// <param name="cmdRequestModel"></param>
        /// <returns></returns>
        public virtual object ExecuteCommand(QpChannel handler, string cmdRequestTypeName, object cmdRequestModel)
        {
            if (!CanExecuteCommand(cmdRequestTypeName))
            {
                throw new IOException($"Command Request Type[{cmdRequestTypeName}] has no executer.");
            }
            Delegate commandExecuter = commandExecuterDict[cmdRequestTypeName];

            return(commandExecuter.DynamicInvoke(new object[] { handler, cmdRequestModel }));
        }
Exemple #3
0
 private Commands.Authenticate.Response authenticate(QpChannel handler, Commands.Authenticate.Request request)
 {
     if (Utils.CryptographyUtils.ComputeMD5Hash(question + options.Password) != request.Answer)
     {
         Task.Delay(1000).ContinueWith(t =>
         {
             Stop();
         });
         throw new CommandException(1, "认证失败!");
     }
     Auchenticated?.Invoke(this, EventArgs.Empty);
     return(new Commands.Authenticate.Response());
 }
Exemple #4
0
        private Commands.HandShake.Response handShake(QpChannel handler, Commands.HandShake.Request request)
        {
            options.CommandExecuterManagerList.AddRange(authedCommandExecuterManagerList);
            options.InternalCompress         = request.EnableCompress;
            options.InternalEncrypt          = request.EnableEncrypt;
            options.InternalTransportTimeout = request.TransportTimeout;

            //改变传输超时时间
            ChangeTransportTimeout();

            //开始心跳
            if (options.HeartBeatInterval > 0)
            {
                BeginHeartBeat(cts.Token);
            }
            return(new Commands.HandShake.Response());
        }
Exemple #5
0
        private Commands.Connect.Response connect(QpChannel handler, Commands.Connect.Request request)
        {
            if (request.InstructionIds != null)
            {
                foreach (var id in request.InstructionIds.Where(t => !string.IsNullOrEmpty(t)))
                {
                    if (!options.InstructionSet.Any(t => t.Id == id))
                    {
                        throw new CommandException(255, $"Unknown instruction: {id}");
                    }
                }
            }

            question = Guid.NewGuid().ToString("N");
            return(new Commands.Connect.Response()
            {
                BufferSize = options.BufferSize,
                Question = question
            });
        }