コード例 #1
0
        public async Task <CommunicationResponse> Handle(SendNotificationRequest Request, CancellationToken cancellationToken)
        {
            try
            {
                var Notification = new NotificationQueue()
                {
                    Message      = Request.Message,
                    Subject      = Request.Subject,
                    DeviceID     = Request.DeviceID,
                    TickerText   = Request.TickerText,
                    ContentTitle = Request.ContentTitle,
                    Status       = 0,
                    CreatedBy    = 1,
                    CreatedDate  = DateTime.UtcNow
                };
                _MessageRepository.Add(Notification);
                Notification.InQueueMessage();
                _MessageRepository.Update(Notification);
                IQueryable Result = await _MessageConfiguration.GetAPIConfigurationAsync(1, 2);

                foreach (CommunicationProviderList Provider in Result)
                {
                    string Response = await _MessageService.SendNotificationAsync(Notification.DeviceID, Notification.TickerText, Notification.ContentTitle, Notification.Message, Provider.SendURL, Provider.RequestFormat, Provider.SenderID, Provider.MethodType, Provider.ContentType);

                    CopyClass.CopyObject(Provider, ref _GetDataForParsingAPI);
                    _GenerateResponse = _WebApiParseResponse.ParseResponseViaRegex(Response, _GetDataForParsingAPI);
                    if (_GenerateResponse.Status == enTransactionStatus.Success)
                    {
                        Notification.SentMessage();
                        _MessageRepository.Update(Notification);
                        return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.Success, ReturnMsg = EnResponseMessage.NotificationSuccessMessage }));
                    }
                    else
                    {
                        continue;
                    }
                }
                Notification.FailMessage();
                _MessageRepository.Update(Notification);
                return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.NotificationFailMessage }));
            }
            catch (Exception ex)
            {
                return(await Task.FromResult(new CommunicationResponse { ReturnCode = enResponseCode.InternalError, ReturnMsg = EnResponseMessage.NotificationExceptionMessage }));
            }
        }