private SendResponse SendDirectNotify(NotifyRequest request, ISenderChannel channel) { var recipient = request.Recipient as IDirectRecipient; if (recipient == null) { throw new ArgumentException("request.Recipient not IDirectRecipient", "request"); } request.CurrentSender = channel.SenderName; NoticeMessage noticeMessage; var oops = CreateNoticeMessageFromNotifyRequest(request, channel.SenderName, out noticeMessage); if (oops != null) { return(oops); } request.CurrentMessage = noticeMessage; var preventresponse = CheckPreventInterceptors(request, InterceptorPlace.MessageSend, channel.SenderName); if (preventresponse != null) { return(preventresponse); } channel.SendAsync(noticeMessage); return(new SendResponse(noticeMessage, channel.SenderName, SendResult.Inprogress)); }
private void PrepareRequestFillTags(NotifyRequest request) { var patternProvider = request.NotifySource.GetPatternProvider(); 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); } } }
private List <SendResponse> SendGroupNotify(NotifyRequest request) { var responces = new List <SendResponse>(); SendGroupNotify(request, responces); return(responces); }
private NotifyResult SendNotify(NotifyRequest request) { var sendResponces = new List <SendResponse>(); var response = CheckPreventInterceptors(request, InterceptorPlace.Prepare, null); if (response != null) { sendResponces.Add(response); } else { sendResponces.AddRange(SendGroupNotify(request)); } NotifyResult result = null; if (sendResponces == null || sendResponces.Count == 0) { result = new NotifyResult(SendResult.OK, sendResponces); } else { result = new NotifyResult(sendResponces.Aggregate((SendResult)0, (s, r) => s |= r.Result), sendResponces); } log.Debug(result); return(result); }
private void PrepareRequestFillPatterns(NotifyRequest request) { if (request.Patterns == null) { request.Patterns = new IPattern[request.SenderNames.Length]; if (request.Patterns.Length == 0) { return; } var apProvider = request.NotifySource.GetPatternProvider(); 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); } if (pattern == null) { throw new NotifyException(string.Format("For action \"{0}\" by sender \"{1}\" no one patterns getted.", request.NotifyAction.Name, senderName)); } request.Patterns[i] = pattern; } } }
private List <SendResponse> SendGroupNotify(NotifyRequest request, IServiceScope serviceScope) { var responces = new List <SendResponse>(); SendGroupNotify(request, responces, serviceScope); return(responces); }
private void PrepareRequestFillPatterns(NotifyRequest request) { if (!request.IsNeedRetrivePatterns) { return; } request.Patterns = new IPattern[request.SenderNames.Length]; if (request.Patterns.Length == 0) { return; } var apProvider = ProviderResolver.GetEnsure <IActionPatternProvider>(request.NotifySource); for (var i = 0; i < request.SenderNames.Length; i++) { var senderName = request.SenderNames[i]; var pattern = (apProvider.GetPatternMethod != null ? apProvider.GetPatternMethod(request.NotifyAction, senderName, request) : null) ?? apProvider.GetPattern(request.NotifyAction, senderName) ?? apProvider.GetPattern(request.NotifyAction); if (pattern == null) { throw new NotifyException(string.Format("For action \"{0}\" by sender \"{1}\" no one patterns getted.", request.NotifyAction.Name, senderName)); } request.Patterns[i] = pattern; } }
private List <SendResponse> SendDirectNotify(NotifyRequest request, IServiceScope serviceScope) { if (!(request.Recipient is IDirectRecipient)) { throw new ArgumentException("request.Recipient not IDirectRecipient", "request"); } var responses = new List <SendResponse>(); var response = CheckPreventInterceptors(request, InterceptorPlace.DirectSend, serviceScope, null); if (response != null) { responses.Add(response); return(responses); } try { PrepareRequestFillSenders(request, serviceScope); PrepareRequestFillPatterns(request, serviceScope); PrepareRequestFillTags(request, serviceScope); } catch (Exception ex) { responses.Add(new SendResponse(request.NotifyAction, null, request.Recipient, SendResult.Impossible)); log.Error("Prepare", ex); } 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, serviceScope); } 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); }
private IPattern SelectPattern(INotifyAction action, string sender, NotifyRequest request) { if (action != Constants.ActionAdminNotify) return null; //after that pattern will be selected by xml var tagvalue = request.Arguments.Find(tag => tag.Tag.Name == "UNDERLYING_ACTION"); if (tagvalue == null) return null; return ActionPatternProvider.GetPattern(new NotifyAction(Convert.ToString(tagvalue.Value), ""), sender); }
public bool PreventSend(NotifyRequest request, InterceptorPlace place) { var sendTo = request.Recipient; if (!sendedTo.Exists(rec => Equals(rec, sendTo))) { sendedTo.Add(sendTo); return false; } return true; }
public bool PreventSend(NotifyRequest request, InterceptorPlace place) { var sendTo = request.Recipient; if (!sendedTo.Exists(rec => Equals(rec, sendTo))) { sendedTo.Add(sendTo); return(false); } return(true); }
private void PrepareRequestFillSenders(NotifyRequest request) { if (!request.IsNeedRetriveSenders) { return; } var subscriptionSource = ProviderResolver.GetEnsure <ISubscriptionSource>(request.NotifySource); request.SenderNames = subscriptionSource.GetSubscriptionMethod(request.NotifyAction, request.Recipient) ?? new string[0]; }
private void PrepareRequestFillSenders(NotifyRequest request) { if (request.SenderNames == null) { var subscriptionProvider = request.NotifySource.GetSubscriptionProvider(); var senderNames = new List <string>(); senderNames.AddRange(subscriptionProvider.GetSubscriptionMethod(request.NotifyAction, request.Recipient) ?? new string[0]); senderNames.AddRange(request.Arguments.OfType <AdditionalSenderTag>().Select(tag => (string)tag.Value)); request.SenderNames = senderNames.ToArray(); } }
public virtual void QueueRequest(NotifyRequest request) { BeforeTransferRequest?.Invoke(this, request); lock (requests) { if (!notifySender.IsAlive) { notifySender.Start(); } requests.Enqueue(request); } requestsEvent.Set(); }
public virtual void QueueRequest(NotifyRequest request) { if (BeforeTransferRequest != null) { BeforeTransferRequest(this, request); } lock (requests) { if (!notifySender.IsAlive) { notifySender.Start(); } requests.Enqueue(request); } requestsEvent.Set(); }
internal NotifyRequest Split(IRecipient recipient) { if (recipient == null) { throw new ArgumentNullException("recipient"); } var newRequest = new NotifyRequest(NotifySource, NotifyAction, ObjectID, recipient); newRequest.SenderNames = SenderNames; newRequest.Patterns = Patterns; newRequest.Arguments = new List <ITagValue>(Arguments); newRequest.RequaredTags = RequaredTags; newRequest.CurrentSender = CurrentSender; newRequest.CurrentMessage = CurrentMessage; newRequest.Interceptors.AddRange(Interceptors); return(newRequest); }
private void NotifySender(object state) { try { while (true) { NotifyRequest request = null; lock (requests) { if (requests.Any()) { request = requests.Dequeue(); } } if (request != null) { if (AfterTransferRequest != null) { AfterTransferRequest(this, request); } try { SendNotify(request); } catch (Exception e) { log.Error(e); } } else { requestsEvent.WaitOne(); } } } catch (ThreadAbortException) { return; } catch (Exception e) { log.Error(e); } }
private void NotifySender(object state) { try { while (true) { NotifyRequest request = null; lock (requests) { if (requests.Any()) { request = requests.Dequeue(); } } if (request != null) { using var scope = ServiceProvider.CreateScope(); AfterTransferRequest?.Invoke(this, request, scope); try { SendNotify(request, scope); } catch (Exception e) { log.Error(e); } } else { requestsEvent.WaitOne(); } } } catch (ThreadAbortException) { return; } catch (Exception e) { log.Error(e); } }
private void NotifySender(object state) { try { while (true) { NotifyRequest request = null; lock (requests) { if (requests.Any()) { request = requests.Dequeue(); } } if (request != null) { AfterTransferRequest?.Invoke(this, request); try { SendNotify(CoreContext.TenantManager.GetCurrentTenant(), request); } catch (Exception e) { log.Error(e); } } else { requestsEvent.WaitOne(); } } } catch (ThreadAbortException) { return; } catch (Exception e) { log.Error(e); } }
private void PrepareRequestFillTags(NotifyRequest request) { if (!request.IsNeedRetriveTags) { return; } var patternProvider = ProviderResolver.GetEnsure <IPatternProvider>(request.NotifySource); foreach (var pattern in request.Patterns) { IPatternFormatter formatter; try { formatter = patternProvider.GetFormatter(pattern) ?? new NullPatternFormatter(); } catch (Exception exc) { throw new NotifyException(string.Format("For pattern \"{0}\" formatter not instanced.", pattern), exc); } ITag[] tags; try { tags = formatter.GetTags(pattern) ?? new ITag[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); } } }
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; }
private void SendGroupNotify(NotifyRequest request, List <SendResponse> responces) { if (request.Recipient is IDirectRecipient) { var subscriptionSource = request.NotifySource.GetSubscriptionProvider(); if (!request.IsNeedCheckSubscriptions || !subscriptionSource.IsUnsubscribe(request.Recipient as IDirectRecipient, request.NotifyAction, request.ObjectID)) { var directresponses = new List <SendResponse>(1); try { directresponses = SendDirectNotify(request); } catch (Exception exc) { directresponses.Add(new SendResponse(request.NotifyAction, request.Recipient, exc)); } responces.AddRange(directresponses); } } else { if (request.Recipient is IRecipientsGroup) { var checkresp = CheckPreventInterceptors(request, InterceptorPlace.GroupSend, null); if (checkresp != null) { responces.Add(checkresp); } else { var recipientProvider = request.NotifySource.GetRecipientsProvider(); try { var recipients = recipientProvider.GetGroupEntries(request.Recipient as IRecipientsGroup, request.ObjectID) ?? new IRecipient[0]; foreach (var recipient in recipients) { try { var newRequest = request.Split(recipient); SendGroupNotify(newRequest, responces); } catch (Exception exc) { responces.Add(new SendResponse(request.NotifyAction, request.Recipient, exc)); } } } catch (Exception exc) { responces.Add(new SendResponse(request.NotifyAction, request.Recipient, exc) { Result = SendResult.IncorrectRecipient }); } } } else { responces.Add(new SendResponse(request.NotifyAction, request.Recipient, null) { Result = SendResult.IncorrectRecipient, Exception = new NotifyException("recipient may be IRecipientsGroup or IDirectRecipient") }); } } }
private SendResponse CreateNoticeMessageFromNotifyRequest(NotifyRequest request, string sender, out NoticeMessage noticeMessage) { if (request == null) { throw new ArgumentNullException("request"); } var recipientProvider = request.NotifySource.GetRecipientsProvider(); var recipient = request.Recipient as IDirectRecipient; var addresses = recipient.Addresses; if (addresses == null || !addresses.Any()) { addresses = recipientProvider.GetRecipientAddresses(request.Recipient as IDirectRecipient, sender, request.ObjectID); 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.NotifySource.GetPatternProvider(); 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(noticeMessage); } } catch (Exception exc) { return(new SendResponse(request.NotifyAction, sender, recipient, exc)); } return(null); }
private static void NotifyEngine_AfterTransferRequest(NotifyEngine sender, NotifyRequest request) { var tenant = (request.Properties.Contains("Tenant") ? request.Properties["Tenant"] : null) as Tenant; if (tenant != null) { CoreContext.TenantManager.SetCurrentTenant(tenant); } }
private SendResponse CheckPreventInterceptors(NotifyRequest request, InterceptorPlace place, string sender) { return(request.Intercept(place) ? new SendResponse(request.NotifyAction, sender, request.Recipient, SendResult.Prevented) : null); }
private SendResponse CheckPreventInterceptors(NotifyRequest request, InterceptorPlace place, string sender) { return request.Intercept(place) ? new SendResponse(request.NotifyAction, sender, request.Recipient, SendResult.Prevented) : null; }
static void NotifyEngine_AfterTransferRequest(ASC.Notify.Engine.NotifyEngine sender, ASC.Notify.Engine.NotifyRequest request) { var productID = (Guid)request.Properties["asc.web.product_id"]; if (productID != Guid.Empty) { CallContext.SetData("asc.web.product_id", productID); } }
public bool PreventSend(NotifyRequest request, InterceptorPlace place) { return method(request, place); }
private List<SendResponse> SendGroupNotify(NotifyRequest request) { var responces = new List<SendResponse>(); SendGroupNotify(request, responces); return responces; }
private void PrepareRequestFillSenders(NotifyRequest request) { if (request.SenderNames == null) { var subscriptionProvider = request.NotifySource.GetSubscriptionProvider(); var senderNames = new List<string>(); senderNames.AddRange(subscriptionProvider.GetSubscriptionMethod(request.NotifyAction, request.Recipient) ?? new string[0]); senderNames.AddRange(request.Arguments.OfType<AdditionalSenderTag>().Select(tag => (string) tag.Value)); request.SenderNames = senderNames.ToArray(); } }
private SendResponse CreateNoticeMessageFromNotifyRequest(NotifyRequest request, string sender, out NoticeMessage noticeMessage) { if (request == null) throw new ArgumentNullException("request"); var recipientProvider = request.NotifySource.GetRecipientsProvider(); var recipient = request.Recipient as IDirectRecipient; var addresses = recipient.Addresses; if (addresses == null || !addresses.Any()) { addresses = recipientProvider.GetRecipientAddresses(request.Recipient as IDirectRecipient, sender, request.ObjectID); 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.NotifySource.GetPatternProvider(); 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(noticeMessage); } } catch (Exception exc) { return new SendResponse(request.NotifyAction, sender, recipient, exc); } return null; }
private SendResponse SendDirectNotify(NotifyRequest request, ISenderChannel channel) { var recipient = request.Recipient as IDirectRecipient; if (recipient == null) throw new ArgumentException("request.Recipient not IDirectRecipient", "request"); request.CurrentSender = channel.SenderName; NoticeMessage noticeMessage; var oops = CreateNoticeMessageFromNotifyRequest(request, channel.SenderName, out noticeMessage); if (oops != null) return oops; request.CurrentMessage = noticeMessage; var preventresponse = CheckPreventInterceptors(request, InterceptorPlace.MessageSend, channel.SenderName); if (preventresponse != null) return preventresponse; channel.SendAsync(noticeMessage); return new SendResponse(noticeMessage, channel.SenderName, SendResult.Inprogress); }
private static void BeforeTransferRequest(NotifyEngine sender, NotifyRequest request) { var aid = Guid.Empty; var aname = string.Empty; if (SecurityContext.IsAuthenticated) { aid = SecurityContext.CurrentAccount.ID; if (CoreContext.UserManager.UserExists(aid)) { aname = CoreContext.UserManager.GetUsers(aid).DisplayUserName(false) .Replace(">", ">") .Replace("<", "<"); } } IProduct product; IModule module; CommonLinkUtility.GetLocationByRequest(out product, out module); if (product == null && CallContext.GetData("asc.web.product_id") != null) { product = WebItemManager.Instance[(Guid)CallContext.GetData("asc.web.product_id")] as IProduct; } request.Arguments.Add(new TagValue(CommonTags.AuthorID, aid)); request.Arguments.Add(new TagValue(CommonTags.AuthorName, aname)); request.Arguments.Add(new TagValue(CommonTags.AuthorUrl, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(aid)))); request.Arguments.Add(new TagValue(CommonTags.VirtualRootPath, CommonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/'))); request.Arguments.Add(new TagValue(CommonTags.ProductID, product != null ? product.ID : Guid.Empty)); request.Arguments.Add(new TagValue(CommonTags.ModuleID, module != null ? module.ID : Guid.Empty)); request.Arguments.Add(new TagValue(CommonTags.ProductUrl, CommonLinkUtility.GetFullAbsolutePath(product != null ? product.StartURL : "~"))); request.Arguments.Add(new TagValue(CommonTags.DateTime, TenantUtil.DateTimeNow())); request.Arguments.Add(new TagValue(CommonTags.Helper, new PatternHelper())); request.Arguments.Add(new TagValue(CommonTags.RecipientID, Context.SYS_RECIPIENT_ID)); request.Arguments.Add(new TagValue(CommonTags.RecipientSubscriptionConfigURL, CommonLinkUtility.GetMyStaff())); if (!request.Arguments.Any(x => CommonTags.SendFrom.Equals(x.Tag))) { request.Arguments.Add(new TagValue(CommonTags.SendFrom, CoreContext.TenantManager.GetCurrentTenant().Name)); } }
static void NotifyEngine_BeforeTransferRequest(ASC.Notify.Engine.NotifyEngine sender, ASC.Notify.Engine.NotifyRequest request) { request.Properties.Add("asc.web.product_id", CommonLinkUtility.GetProductID()); Guid aid = Guid.Empty; string aname = ""; if (SecurityContext.IsAuthenticated) { aid = SecurityContext.CurrentAccount.ID; if (CoreContext.UserManager.UserExists(aid)) { aname = CoreContext.UserManager.GetUsers(aid).DisplayUserName(); } } //__AuthorID request.Arguments.Add(new TagValue(CommonTags.AuthorID, aid)); //__AuthorName request.Arguments.Add(new TagValue(CommonTags.AuthorName, aname)); //__AuthorUrl request.Arguments.Add(new TagValue(CommonTags.AuthorUrl, CommonLinkUtility.GetUserProfile(aid, CommonLinkUtility.GetProductID()))); if (!request.Arguments.Any(x => CommonTags.SendFrom.Equals(x.Tag.Name)))//If none add current { request.Arguments.Add(new TagValue(CommonTags.SendFrom, CoreContext.TenantManager.GetCurrentTenant(false).Name)); } }
public bool PreventSend(NotifyRequest request, InterceptorPlace place) { return(method(request, place)); }
private NotifyResult SendNotify(NotifyRequest request) { var sendResponces = new List<SendResponse>(); var response = CheckPreventInterceptors(request, InterceptorPlace.Prepare, null); if (response != null) { sendResponces.Add(response); } else { sendResponces.AddRange(SendGroupNotify(request)); } NotifyResult result = null; if (sendResponces == null || sendResponces.Count == 0) { result = new NotifyResult(SendResult.OK, sendResponces); } else { result = new NotifyResult(sendResponces.Aggregate((SendResult)0, (s, r) => s |= r.Result), sendResponces); } log.Debug(result); return result; }
private static void NotifyEngine_BeforeTransferRequest(NotifyEngine sender, NotifyRequest request) { request.Properties.Add("Tenant", CoreContext.TenantManager.GetCurrentTenant(false)); }
internal NotifyRequest Split(IRecipient recipient) { if (recipient == null) throw new ArgumentNullException("recipient"); var newRequest = new NotifyRequest(NotifySource, NotifyAction, ObjectID, recipient); newRequest.SenderNames = SenderNames; newRequest.Patterns = Patterns; newRequest.Arguments = new List<ITagValue>(Arguments); newRequest.RequaredTags = RequaredTags; newRequest.CurrentSender = CurrentSender; newRequest.CurrentMessage = CurrentMessage; newRequest.Interceptors.AddRange(Interceptors); return newRequest; }
private void PrepareRequestFillTags(NotifyRequest request) { if (!request.IsNeedRetriveTags) return; var patternProvider = ProviderResolver.GetEnsure<IPatternProvider>(request.NotifySource); foreach (var pattern in request.Patterns) { IPatternFormatter formatter; try { formatter = patternProvider.GetFormatter(pattern) ?? new NullPatternFormatter(); } catch (Exception exc) { throw new NotifyException(string.Format("For pattern \"{0}\" formatter not instanced.", pattern), exc); } ITag[] tags; try { tags = formatter.GetTags(pattern) ?? new ITag[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); } } }
private void SendAsync(NotifyRequest request) { request.Interceptors = interceptors.GetAll(); AddStaticTags(request); ctx.NotifyEngine.QueueRequest(request); }
private void PrepareRequestFillPatterns(NotifyRequest request) { if (!request.IsNeedRetrivePatterns) return; request.Patterns = new IPattern[request.SenderNames.Length]; if (request.Patterns.Length == 0) return; var apProvider = ProviderResolver.GetEnsure<IActionPatternProvider>(request.NotifySource); for (var i = 0; i < request.SenderNames.Length; i++) { var senderName = request.SenderNames[i]; var pattern = (apProvider.GetPatternMethod != null ? apProvider.GetPatternMethod(request.NotifyAction, senderName, request) : null) ?? apProvider.GetPattern(request.NotifyAction, senderName) ?? apProvider.GetPattern(request.NotifyAction); if (pattern == null) { throw new NotifyException(string.Format("For action \"{0}\" by sender \"{1}\" no one patterns getted.", request.NotifyAction.Name, senderName)); } request.Patterns[i] = pattern; } }
private void AddStaticTags(NotifyRequest request) { lock (tags) { foreach (var t in tags) { if (t != null && !request.Arguments.Exists(a => a.Tag.Name == t.Tag.Name)) { request.Arguments.Add(t); } } } }
private void PrepareRequestFillSenders(NotifyRequest request) { if (!request.IsNeedRetriveSenders) return; var subscriptionSource = ProviderResolver.GetEnsure<ISubscriptionSource>(request.NotifySource); request.SenderNames = subscriptionSource.GetSubscriptionMethod(request.NotifyAction, request.Recipient) ?? new string[0]; }
private NotifyRequest CreateRequest(INotifyAction action, string objectID, IRecipient recipient, SendNoticeCallback sendCallback, ITagValue[] args, string[] senders, bool checkSubsciption) { if (action == null) throw new ArgumentNullException("action"); if (recipient == null) throw new ArgumentNullException("recipient"); if (sendCallback != null) throw new NotImplementedException("sendCallback"); var request = new NotifyRequest(notifySource, action, objectID, recipient); request.SenderNames = senders; request.IsNeedCheckSubscriptions = checkSubsciption; if (args != null) request.Arguments.AddRange(args); return request; }
private void PrepareRequestFillPatterns(NotifyRequest request) { if (request.Patterns == null) { request.Patterns = new IPattern[request.SenderNames.Length]; if (request.Patterns.Length == 0) return; var apProvider = request.NotifySource.GetPatternProvider(); 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); } if (pattern == null) { throw new NotifyException(string.Format("For action \"{0}\" by sender \"{1}\" no one patterns getted.", request.NotifyAction.Name, senderName)); } request.Patterns[i] = pattern; } } }
private void SendGroupNotify(NotifyRequest request, List<SendResponse> responces) { if (request.Recipient is IDirectRecipient) { var subscriptionSource = request.NotifySource.GetSubscriptionProvider(); if (!request.IsNeedCheckSubscriptions || !subscriptionSource.IsUnsubscribe(request.Recipient as IDirectRecipient, request.NotifyAction, request.ObjectID)) { var directresponses = new List<SendResponse>(1); try { directresponses = SendDirectNotify(request); } catch (Exception exc) { directresponses.Add(new SendResponse(request.NotifyAction, request.Recipient, exc)); } responces.AddRange(directresponses); } } else { if (request.Recipient is IRecipientsGroup) { var checkresp = CheckPreventInterceptors(request, InterceptorPlace.GroupSend, null); if (checkresp != null) { responces.Add(checkresp); } else { var recipientProvider = request.NotifySource.GetRecipientsProvider(); try { var recipients = recipientProvider.GetGroupEntries(request.Recipient as IRecipientsGroup, request.ObjectID) ?? new IRecipient[0]; foreach (var recipient in recipients) { try { var newRequest = request.Split(recipient); SendGroupNotify(newRequest, responces); } catch (Exception exc) { responces.Add(new SendResponse(request.NotifyAction, request.Recipient, exc)); } } } catch (Exception exc) { responces.Add(new SendResponse(request.NotifyAction, request.Recipient, exc) { Result = SendResult.IncorrectRecipient }); } } } else { responces.Add(new SendResponse(request.NotifyAction, request.Recipient, null) { Result = SendResult.IncorrectRecipient, Exception = new NotifyException("recipient may be IRecipientsGroup or IDirectRecipient") }); } } }
public bool PreventSend(NotifyRequest request, InterceptorPlace place, IServiceScope serviceScope) { return(method(request, place, serviceScope)); }