Exemple #1
0
        private void PrepareRequestFillPatterns(NotifyRequest request, IServiceScope serviceScope)
        {
            if (request.Patterns == null)
            {
                request.Patterns = new IPattern[request.SenderNames.Length];
                if (request.Patterns.Length == 0)
                {
                    return;
                }

                var apProvider = request.GetPatternProvider(serviceScope);
                for (var i = 0; i < request.SenderNames.Length; i++)
                {
                    var      senderName = request.SenderNames[i];
                    IPattern pattern    = null;
                    if (apProvider.GetPatternMethod != null)
                    {
                        pattern = apProvider.GetPatternMethod(request.NotifyAction, senderName, request);
                    }
                    if (pattern == null)
                    {
                        pattern = apProvider.GetPattern(request.NotifyAction, senderName);
                    }

                    request.Patterns[i] = pattern ?? throw new NotifyException(string.Format("For action \"{0}\" by sender \"{1}\" no one patterns getted.", request.NotifyAction.ID, senderName));
                }
            }
        }
Exemple #2
0
        private void PrepareRequestFillTags(NotifyRequest request, IServiceScope serviceScope)
        {
            var patternProvider = request.GetPatternProvider(serviceScope);

            foreach (var pattern in request.Patterns)
            {
                IPatternFormatter formatter;
                try
                {
                    formatter = patternProvider.GetFormatter(pattern);
                }
                catch (Exception exc)
                {
                    throw new NotifyException(string.Format("For pattern \"{0}\" formatter not instanced.", pattern), exc);
                }
                var tags = new string[0];
                try
                {
                    if (formatter != null)
                    {
                        tags = formatter.GetTags(pattern) ?? new string[0];
                    }
                }
                catch (Exception exc)
                {
                    throw new NotifyException(string.Format("Get tags from formatter of pattern \"{0}\" failed.", pattern), exc);
                }

                foreach (var tag in tags.Where(tag => !request.Arguments.Exists(tagValue => Equals(tagValue.Tag, tag)) && !request.RequaredTags.Exists(rtag => Equals(rtag, tag))))
                {
                    request.RequaredTags.Add(tag);
                }
            }
        }
Exemple #3
0
        private SendResponse CreateNoticeMessageFromNotifyRequest(NotifyRequest request, string sender, IServiceScope serviceScope, out NoticeMessage noticeMessage)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var recipientProvider = request.GetRecipientsProvider(serviceScope);
            var recipient         = request.Recipient as IDirectRecipient;

            var addresses = recipient.Addresses;

            if (addresses == null || !addresses.Any())
            {
                addresses = recipientProvider.GetRecipientAddresses(request.Recipient as IDirectRecipient, sender);
                recipient = new DirectRecipient(request.Recipient.ID, request.Recipient.Name, addresses);
            }

            recipient     = recipientProvider.FilterRecipientAddresses(recipient);
            noticeMessage = request.CreateMessage(recipient);

            addresses = recipient.Addresses;
            if (addresses == null || !addresses.Any(a => !string.IsNullOrEmpty(a)))
            {
                //checking addresses
                return(new SendResponse(request.NotifyAction, sender, recipient, new NotifyException(string.Format("For recipient {0} by sender {1} no one addresses getted.", recipient, sender))));
            }

            var pattern = request.GetSenderPattern(sender);

            if (pattern == null)
            {
                return(new SendResponse(request.NotifyAction, sender, recipient, new NotifyException(string.Format("For action \"{0}\" by sender \"{1}\" no one patterns getted.", request.NotifyAction, sender))));
            }

            noticeMessage.Pattern     = pattern;
            noticeMessage.ContentType = pattern.ContentType;
            noticeMessage.AddArgument(request.Arguments.ToArray());
            var patternProvider = request.GetPatternProvider(serviceScope);

            var formatter = patternProvider.GetFormatter(pattern);

            try
            {
                if (formatter != null)
                {
                    formatter.FormatMessage(noticeMessage, noticeMessage.Arguments);
                }
                sysTagFormatter.FormatMessage(
                    noticeMessage, new[]
                {
                    new TagValue(Context._SYS_RECIPIENT_ID, request.Recipient.ID),
                    new TagValue(Context._SYS_RECIPIENT_NAME, request.Recipient.Name),
                    new TagValue(Context._SYS_RECIPIENT_ADDRESS, addresses != null && addresses.Length > 0 ? addresses[0] : null)
                }
                    );
                //Do styling here
                if (!string.IsNullOrEmpty(pattern.Styler))
                {
                    //We need to run through styler before templating
                    StyleMessage(serviceScope, noticeMessage);
                }
            }
            catch (Exception exc)
            {
                return(new SendResponse(request.NotifyAction, sender, recipient, exc));
            }
            return(null);
        }