コード例 #1
0
 /// <summary>
 /// 处理数据传给DB
 /// 将消息一拆为n个消息
 /// </summary>
 /// <param name="model"></param>
 private void HandleMsgToDB(object model)
 {
     //var _logger = _loggerFactory.CreateLogger<MsgService>();
     using (var scope = SherlockEngine.Current.CreateScope())
     {
         try
         {
             string         serialNO       = Guid.NewGuid().ToString();//同一条消息进行拆解
             SendMsgRequest sendMsgRequest = (SendMsgRequest)model;
             //将推送消息推送消息中心
             PushMessageToMessageCenter(sendMsgRequest);
             //拆分数据
             //获取设备和通道
             IPushTokenBrandService          pushTokenBrandService        = scope.ServiceProvider.GetService(typeof(IPushTokenBrandService)) as IPushTokenBrandService;
             List <DeviceChannelDomainModel> deviceChannelDomainModelList = pushTokenBrandService.GetDeviceChannelListAsync(sendMsgRequest.Token, sendMsgRequest.AppId).Result;
             List <DeviceChannelDto>         deviceChannelList            = _mapper.Map <List <DeviceChannelDto> >(deviceChannelDomainModelList);
             //未获取到,接收的消息直接进历史表,标记为账号登出
             if (deviceChannelList == null || deviceChannelList.Count == 0)
             {
                 //直接入历史表,标记错误
                 SendProcessDto sendProcessDto = SendMsgToSendProcess(sendMsgRequest, serialNO);
                 sendProcessDto.Token = sendMsgRequest.Token;
                 ISendProcessLogic sendProcessLogic = scope.ServiceProvider.GetService(typeof(ISendProcessLogic)) as ISendProcessLogic;
                 sendProcessLogic.RecordErrorProcess(sendProcessDto, ErrorTypeEnum.Logout, string.Empty);
                 return;
             }
             //获取到,根据设备Token拆分数据
             List <SendProcessDto> sendProcessDtoList = new List <SendProcessDto>();
             foreach (var item in deviceChannelList)
             {
                 SendProcessDto sendProcessDto = SendMsgToSendProcess(sendMsgRequest, serialNO);
                 sendProcessDto.Token = sendMsgRequest.Token;
                 //将获取到的TokenBrandId(核心),BrandId,ChannelId,DeviceToken 赋给对象,可做到新老接口兼容
                 //老接口发送数据时,可根据TokenBrandId直接找到需要发送的ChannelId和DeviceToken
                 //新接口发送数据时,通过ChannelId,DeviceToken 发送数据
                 sendProcessDto.TokenBrandId = item.Id;
                 sendProcessDto.BrandId      = item.BrandId;
                 sendProcessDto.ChannelId    = item.ChannelId;
                 sendProcessDto.DeviceToken  = item.DeviceToken;
                 sendProcessDtoList.Add(sendProcessDto);
             }
             IMapper mapper = scope.ServiceProvider.GetService(typeof(IMapper)) as IMapper;
             List <PushSendProcessDomainModel> domainList             = mapper.Map <List <PushSendProcessDomainModel> >(sendProcessDtoList);
             IPushSendProcessService           pushSendProcessService = scope.ServiceProvider.GetService(typeof(IPushSendProcessService)) as IPushSendProcessService;
             int rows = pushSendProcessService.InsertProcessListAsync(domainList).Result;
         }
         catch (Exception ex)
         {
             //_logger.LogError(ex.Message.ToString());
             //LogHelper.Error.Write("HandleMsgToDB", ex);
         }
         finally
         {
             _semaphore.Release();
             //LogHelper.Info.Write("HandleMsgToDB", "信号量释放之前使用的数量:" + count);
         }
     }
 }
コード例 #2
0
 public SendHandler(IMapper mapper
                    , IPushTokenBrandService pushTokenBrandService
                    , ISendProcessLogic sendProcessLogic
                    , IPushSendProcessService pushSendProcessService
                    )
 {
     _mapper = mapper;
     _pushTokenBrandService  = pushTokenBrandService;
     _sendProcessLogic       = sendProcessLogic;
     _pushSendProcessService = pushSendProcessService;
 }
コード例 #3
0
        //private ILoggerFactory _loggerFactory;

        public MsgService(IConfigLogic configLogic
                          , IMapper mapper
                          , ITokenBrandLogic tokenBrandLogic
                          , IPushTokenBrandService pushTokenBrandService
                          , ISendProcessLogic sendProcessLogic
                          , IPushSendProcessService pushSendProcessService
                          , IEventNotification eventNotification
                          //, ILoggerFactory loggerFactory
                          )
        {
            _configLogic            = configLogic;
            _mapper                 = mapper;
            _tokenBrandLogic        = tokenBrandLogic;
            _pushTokenBrandService  = pushTokenBrandService;
            _sendProcessLogic       = sendProcessLogic;
            _pushSendProcessService = pushSendProcessService;
            _eventNotification      = eventNotification;
            //_loggerFactory = loggerFactory;
            //初始化信号量
            InitSemaphore();
            //初始化队列
            InitQueue();
        }