/// <summary> /// 处理请求. /// </summary> /// <param name="req"></param> /// <returns></returns> public AbstractResponse ProcessRequest(AbstractRequest req) { if (req.MsgType == MessageType.EventMsgType) { // 处理事件. AbstractEventRequest e = req as AbstractEventRequest; if (!this.EventServiceDictionary.ContainsKey(e.Event)) { // 不包含特定的事件处理. return(null); } IMessageProcessService service = this.EventServiceDictionary[e.Event]; return(service.ProcessRequest(req)); } if (req.MsgType == MessageType.TextMsgType) { // 处理文本请求. IMessageProcessService service = this.MessageServiceList.FirstOrDefault(p => p.CommandText.ToUpper() == ((TextRequest)req).Content.ToUpper()); if (service != null) { // 找到服务, 进行处理. return(service.ProcessRequest(req)); } } // 未知的命令, 或者未知的 消息类型. return(GetHelp(req)); }
public ImplementMeServiceTest_ProcessMessageAsync() { var repository = Substitute.For <IKVRepository>(); repository.DeleteAsync(Arg.Any <string>()) .Returns(Task.FromResult(new ActionResult { IsSuccessfull = true })); _repository = repository; var logService = Substitute.For <ILogService>(); _logService = logService; var centralizedLock = Substitute.For <CentralizedLock>(_repository, 30, _logService); centralizedLock.TryAcquireAsync(Arg.Any <string>()) .Returns(Task.FromResult(new CentralizedLockItem(() => { }, true))); _centralizedLock = centralizedLock; var processService = Substitute.For <IMessageProcessService>(); processService.ProccessMessageAsync(Arg.Any <RingbaUOW>()) .Returns(Task.FromResult(new ActionResult { IsSuccessfull = true })); _processService = processService; }
public ImplementMeService(IKVRepository repository, ILogService logService, IMessageProcessService messageProcessService, IMessageQueService messageQueService) : this(repository, logService, messageProcessService, messageQueService, null) { }
public ImplementMeService( IKVRepository repository, ILogService logService, IMessageProcessService messageProcessService, IMessageQueService messageQueService) { _repository = repository; _logservice = logService; _queService = messageQueService; _processService = messageProcessService; }
public ImplementMeService( IUOWStatusService uowStatusService, ILogService logService, IMessageProcessService messageProcessService, IMessageQueService messageQueService) { _uowStatusService = uowStatusService; _logService = logService; _queService = messageQueService; _processService = messageProcessService; _cts = new CancellationTokenSource(); _logId = typeof(ImplementMeService).Name; }
public ImplementMeService(IKVRepository repository, ILogService logService, IMessageProcessService messageProcessService, IMessageQueService messageQueService, CentralizedLock centralizedLock = null, CancellationTokenSource cancellationTokenSource = null, TimeSpan?maxStopWait = null) { _repository = repository; _logservice = logService; _queService = messageQueService; _processService = messageProcessService; _cancellationTokenSource = cancellationTokenSource ?? new CancellationTokenSource(); _maxStopWait = maxStopWait ?? TimeSpan.FromSeconds(5); _centralizedLock = centralizedLock ?? new CentralizedLock(repository, -1, _logservice); }