コード例 #1
0
        public override SendResponse ProcessMessage(INoticeMessage message)
        {
            if (message.Recipient.Addresses == null || message.Recipient.Addresses.Length == 0)
            {
                return new SendResponse(message, senderName, SendResult.IncorrectRecipient);
            }

            var responce = new SendResponse(message, senderName, default(SendResult));
            try
            {
                var m = CreateNotifyMessage(message);
                var result = sender.Send(m);

                switch (result)
                {
                    case NoticeSendResult.TryOnceAgain:
                        responce.Result = SendResult.Inprogress;
                        break;
                    case NoticeSendResult.MessageIncorrect:
                        responce.Result = SendResult.IncorrectRecipient;
                        break;
                    case NoticeSendResult.SendingImpossible:
                        responce.Result = SendResult.Impossible;
                        break;
                    default:
                        responce.Result = SendResult.OK;
                        break;
                }
                return responce;
            }
            catch (Exception e)
            {
                return new SendResponse(message, senderName, e);
            }
        }
コード例 #2
0
 private void LogResponce(INoticeMessage message, SendResponse response, string senderName)
 {
     var logmsg = string.Format("[{0}] sended to [{1}] over {2}, status: {3} ", message.Subject, message.Recipient, senderName, response.Result);
     if (response.Result == SendResult.Inprogress)
     {
         log.Debug(logmsg, response.Exception);
     }
     else if (response.Result == SendResult.Impossible)
     {
         log.Error(logmsg, response.Exception);
     }
     else
     {
         log.Debug(logmsg);
     }
 }
コード例 #3
0
        public SendResponse Dispatch(INoticeMessage message, string senderName)
        {
            var response = new SendResponse(message, senderName, SendResult.OK);
            if (!logOnly)
            {
                var sender = context.NotifyService.GetSender(senderName);
                if (sender != null)
                {
                    response = sender.DirectSend(message);
                }
                else
                {
                    response = new SendResponse(message, senderName, SendResult.Impossible);
                }

                LogResponce(message, response, sender != null ? sender.SenderName : string.Empty);
            }
            LogMessage(message, senderName);
            return response;
        }
コード例 #4
0
        private List<SendResponse> SendDirectNotify(NotifyRequest request)
        {
            if (!(request.Recipient is IDirectRecipient)) throw new ArgumentException("request.Recipient not IDirectRecipient", "request");

            var responses = new List<SendResponse>();
            var response = CheckPreventInterceptors(request, InterceptorPlace.DirectSend, null);
            if (response != null)
            {
                responses.Add(response);
                return responses;
            }

            try
            {
                PrepareRequestFillSenders(request);
                PrepareRequestFillPatterns(request);
                PrepareRequestFillTags(request);
            }
            catch (Exception)
            {
                responses.Add(new SendResponse(request.NotifyAction, null, request.Recipient, SendResult.Impossible));
            }

            if (request.SenderNames != null && request.SenderNames.Length > 0)
            {
                foreach (var sendertag in request.SenderNames)
                {
                    var channel = context.NotifyService.GetSender(sendertag);
                    if (channel != null)
                    {
                        try
                        {
                            response = SendDirectNotify(request, channel);
                        }
                        catch (Exception exc)
                        {
                            response = new SendResponse(request.NotifyAction, channel.SenderName, request.Recipient, exc);
                        }
                    }
                    else
                    {
                        response = new SendResponse(request.NotifyAction, sendertag, request.Recipient, new NotifyException(String.Format("Not registered sender \"{0}\".", sendertag)));
                    }
                    responses.Add(response);
                }
            }
            else
            {
                response = new SendResponse(request.NotifyAction, request.Recipient, new NotifyException("Notice hasn't any senders."));
                responses.Add(response);
            }
            return responses;
        }