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);
            }
        }
Beispiel #2
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);

                responce.Result = result switch
                {
                    NoticeSendResult.TryOnceAgain => SendResult.Inprogress,
                    NoticeSendResult.MessageIncorrect => SendResult.IncorrectRecipient,
                    NoticeSendResult.SendingImpossible => SendResult.Impossible,
                    _ => SendResult.OK,
                };
                return(responce);
            }
            catch (Exception e)
            {
                return(new SendResponse(message, senderName, e));
            }
        }
        public override SendResponse ProcessMessage(INoticeMessage message)
        {
            try
            {
                var result = SendResult.OK;
                var username = CoreContext.UserManager.GetUsers(new Guid(message.Recipient.ID)).UserName;
                if (string.IsNullOrEmpty(username))
                {
                    result = SendResult.IncorrectRecipient;
                }
                else
                {
                    var m = new NotifyMessage
                    {
                        To = username,
                        Subject = message.Subject,
                        ContentType = message.ContentType,
                        Content = message.Body,
                        Sender = senderName,
                        CreationDate = DateTime.UtcNow,
                    };

                    var tenant = CoreContext.TenantManager.GetCurrentTenant(false);
                    m.Tenant = tenant == null ? Tenant.DEFAULT_TENANT : tenant.TenantId;

                    sender.Send(m);
                }
                return new SendResponse(message, senderName, result);
            }
            catch (Exception ex)
            {
                return new SendResponse(message, senderName, ex);
            }
        }
Beispiel #4
0
        static void DoNotifyRequestAbsoluteUrl(INoticeMessage msg)
        {
            var body = msg.Body;


            body = urlReplacer.Replace(body, (m =>
            {
                var url = m.Groups["url"].Value;
                var ind = m.Groups["url"].Index - m.Index;
                if (String.IsNullOrEmpty(url) && ind > 0)
                {
                    return((m.Value).Insert(ind, CommonLinkUtility.GetFullAbsolutePath("")));
                }
                return((m.Value).Replace(url, CommonLinkUtility.GetFullAbsolutePath(url)));
            }));

            body = TextileLinkReplacer.Replace(body, (m =>
            {
                var url = m.Groups["link"].Value;
                var ind = m.Groups["link"].Index - m.Index;
                if (String.IsNullOrEmpty(url) && ind > 0)
                {
                    return((m.Value).Insert(ind, CommonLinkUtility.GetFullAbsolutePath("")));
                }
                return((m.Value).Replace(url, CommonLinkUtility.GetFullAbsolutePath(url)));
            }));

            msg.Body = body;
        }
Beispiel #5
0
 public DispatchRequest(INoticeMessage message, ISenderChannel senderChannel, Action <INoticeMessage, SendResponse> callback)
 {
     Interlocked.Increment(ref DispatchNum);
     NoticeMessage    = message;
     SenderChannel    = senderChannel;
     DispatchCallback = callback;
 }
Beispiel #6
0
        public override SendResponse ProcessMessage(INoticeMessage message)
        {
            try
            {
                var result   = SendResult.OK;
                var username = CoreContext.UserManager.GetUsers(new Guid(message.Recipient.ID)).UserName;
                if (string.IsNullOrEmpty(username))
                {
                    result = SendResult.IncorrectRecipient;
                }
                else
                {
                    var m = new NotifyMessage
                    {
                        To           = username,
                        Subject      = message.Subject,
                        ContentType  = message.ContentType,
                        Content      = message.Body,
                        Sender       = senderName,
                        CreationDate = DateTime.UtcNow,
                    };

                    var tenant = CoreContext.TenantManager.GetCurrentTenant(false);
                    m.Tenant = tenant == null ? Tenant.DEFAULT_TENANT : tenant.TenantId;

                    sender.Send(m);
                }
                return(new SendResponse(message, senderName, result));
            }
            catch (Exception ex)
            {
                return(new SendResponse(message, senderName, ex));
            }
        }
        public override SendResponse ProcessMessage(INoticeMessage message)
        {
            try
            {
                var result = SendResult.OK;
                var m      = new NotifyMessage
                {
                    To           = message.Recipient.ID,
                    Subject      = message.Subject,
                    ContentType  = message.ContentType,
                    Content      = message.Body,
                    Sender       = senderName,
                    CreationDate = DateTime.UtcNow.Ticks,
                };

                using var scope = serviceProvider.CreateScope();
                var tenantManager = scope.ServiceProvider.GetService <TenantManager>();

                var tenant = tenantManager.GetCurrentTenant(false);
                m.Tenant = tenant == null ? Tenant.DEFAULT_TENANT : tenant.TenantId;

                sender.Send(m);

                return(new SendResponse(message, senderName, result));
            }
            catch (Exception ex)
            {
                return(new SendResponse(message, senderName, ex));
            }
        }
        private NotifyMessage CreateNotifyMessage(INoticeMessage message)
        {
            var m = new NotifyMessage
            {
                Subject      = message.Subject.Trim(' ', '\t', '\n', '\r'),
                ContentType  = message.ContentType,
                Content      = message.Body,
                Sender       = senderName,
                CreationDate = DateTime.UtcNow,
            };

            var tenant = CoreContext.TenantManager.GetCurrentTenant(false);

            m.Tenant = tenant == null ? Tenant.DEFAULT_TENANT : tenant.TenantId;

            var from    = MailAddressUtils.Create(CoreContext.Configuration.SmtpSettings.SenderAddress, CoreContext.Configuration.SmtpSettings.SenderDisplayName);
            var fromTag = message.Arguments.FirstOrDefault(x => x.Tag.Equals("MessageFrom"));

            if ((CoreContext.Configuration.SmtpSettings.IsDefaultSettings || string.IsNullOrEmpty(CoreContext.Configuration.SmtpSettings.SenderDisplayName)) &&
                fromTag != null && fromTag.Value != null)
            {
                try
                {
                    from = MailAddressUtils.Create(from.Address, fromTag.Value.ToString());
                }
                catch { }
            }
            m.From = from.ToString();

            var to = new List <string>();

            foreach (var address in message.Recipient.Addresses)
            {
                to.Add(MailAddressUtils.Create(address, message.Recipient.Name).ToString());
            }
            m.To = string.Join("|", to.ToArray());

            var replyTag = message.Arguments.FirstOrDefault(x => x.Tag == "replyto");

            if (replyTag != null && replyTag.Value is string)
            {
                try
                {
                    m.ReplyTo = MailAddressUtils.Create((string)replyTag.Value).ToString();
                }
                catch (Exception e)
                {
                    LogManager.GetLogger("ASC.Notify").Error("Error creating reply to tag for: " + replyTag.Value, e);
                }
            }

            var priority = message.Arguments.FirstOrDefault(a => a.Tag == "Priority");

            if (priority != null)
            {
                m.Priority = Convert.ToInt32(priority.Value);
            }

            return(m);
        }
Beispiel #9
0
        public void SendAsync(INoticeMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            firstSink.ProcessMessageAsync(message);
        }
        private NotifyMessage CreateNotifyMessage(INoticeMessage message)
        {
            var m = new NotifyMessage
            {
                Subject      = message.Subject.Trim(' ', '\t', '\n', '\r'),
                ContentType  = message.ContentType,
                Content      = message.Body,
                Sender       = senderName,
                CreationDate = DateTime.UtcNow,
            };

            var tenant = CoreContext.TenantManager.GetCurrentTenant(false);

            m.Tenant = tenant == null ? Tenant.DEFAULT_TENANT : tenant.TenantId;

            var from    = new MailAddress(CoreContext.Configuration.SmtpSettings.SenderAddress, CoreContext.Configuration.SmtpSettings.SenderDisplayName);
            var fromTag = message.Arguments.FirstOrDefault(x => x.Tag.Name.Equals(NotifyArgumentConstants.MessageFrom));

            if (fromTag != null && fromTag.Value != null)
            {
                try
                {
                    from = new MailAddress(from.Address, fromTag.Value.ToString(), Encoding.UTF8);
                }
                catch { }
            }
            m.From = from.ToString();

            var to      = new List <string>();
            var nameOne = false;

            foreach (var address in message.Recipient.Addresses)
            {
                var recipient = !nameOne ? new MailAddress(address, message.Recipient.Name) : new MailAddress(address);
                to.Add(recipient.ToString());
                nameOne = true;
            }
            m.To = string.Join("|", to.ToArray());

            var replyTag = message.Arguments.FirstOrDefault(x => x.Tag.Name == "replyto");

            if (replyTag != null && replyTag.Value is string)
            {
                try
                {
                    m.ReplyTo = new MailAddress((string)replyTag.Value).ToString();
                }
                catch (Exception e)
                {
                    LogManager.GetLogger("ASC.Notify").Error("Error creating reply to tag for: " + replyTag.Value, e);
                }
            }

            return(m);
        }
 protected override void BeforeFormat(INoticeMessage message, ITagValue[] tagsValues)
 {
     _nvelocityContext = new VelocityContext();
     _nvelocityContext.AttachEventCartridge(new EventCartridge());
     _nvelocityContext.EventCartridge.ReferenceInsertion += EventCartridgeReferenceInsertion;
     foreach (var tagValue in tagsValues)
     {
         _nvelocityContext.Put(tagValue.Tag, tagValue.Value);
     }
     base.BeforeFormat(message, tagsValues);
 }
Beispiel #12
0
 public SendResponse(INoticeMessage message, string sender, SendResult result)
 {
     NoticeMessage = message;
     SenderName = sender;
     Result = result;
     if (message != null)
     {
         Recipient = message.Recipient;
         NotifyAction = message.Action;
     }
 }
Beispiel #13
0
 public SendResponse(INoticeMessage message, string sender, SendResult result)
 {
     NoticeMessage = message;
     SenderName    = sender;
     Result        = result;
     if (message != null)
     {
         Recipient    = message.Recipient;
         NotifyAction = message.Action;
     }
 }
        private NotifyMessage CreateNotifyMessage(INoticeMessage message)
        {
            var m = new NotifyMessage
            {
                Subject = message.Subject.Trim(' ', '\t', '\n', '\r'),
                ContentType = message.ContentType,
                Content = message.Body,
                Sender = senderName,
                CreationDate = DateTime.UtcNow,
            };

            var tenant = CoreContext.TenantManager.GetCurrentTenant(false);
            m.Tenant = tenant == null ? Tenant.DEFAULT_TENANT : tenant.TenantId;

            var from = MailAddressUtils.Create(CoreContext.Configuration.SmtpSettings.SenderAddress, CoreContext.Configuration.SmtpSettings.SenderDisplayName);
            var fromTag = message.Arguments.FirstOrDefault(x => x.Tag.Equals("MessageFrom"));
            if (fromTag != null && fromTag.Value != null)
            {
                try
                {
                    from = MailAddressUtils.Create(from.Address, fromTag.Value.ToString());
                }
                catch { }
            }
            m.From = from.ToString();

            var to = new List<string>();
            foreach (var address in message.Recipient.Addresses)
            {
                to.Add(MailAddressUtils.Create(address, message.Recipient.Name).ToString());
            }
            m.To = string.Join("|", to.ToArray());

            var replyTag = message.Arguments.FirstOrDefault(x => x.Tag == "replyto");
            if (replyTag != null && replyTag.Value is string)
            {
                try
                {
                    m.ReplyTo = MailAddressUtils.Create((string)replyTag.Value).ToString();
                }
                catch (Exception e)
                {
                    LogManager.GetLogger("ASC.Notify").Error("Error creating reply to tag for: " + replyTag.Value, e);
                }
            }

            var priority = message.Arguments.FirstOrDefault(a => a.Tag == "Priority");
            if (priority != null)
            {
                m.Priority = Convert.ToInt32(priority.Value);
            }

            return m;
        }
 protected override void BeforeFormat(INoticeMessage message, ITagValue[] tagsValues)
 {
     _nvelocityContext = new VelocityContext();
     _nvelocityContext.AttachEventCartridge(new EventCartridge());
     _nvelocityContext.EventCartridge.ReferenceInsertion += EventCartridgeReferenceInsertion;
     foreach (var tagValue in tagsValues)
     {
         _nvelocityContext.Put(tagValue.Tag, tagValue.Value);
     }
     base.BeforeFormat(message, tagsValues);
 }
Beispiel #16
0
 public SendResponse(INoticeMessage message, string sender, Exception exc)
 {
     NoticeMessage = message;
     SenderName = sender;
     Result = SendResult.Impossible;
     Exception = exc;
     if (message != null)
     {
         Recipient = message.Recipient;
         NotifyAction = message.Action;
     }
 }
Beispiel #17
0
 public SendResponse(INoticeMessage message, string sender, Exception exc)
 {
     NoticeMessage = message;
     SenderName    = sender;
     Result        = SendResult.Impossible;
     Exception     = exc;
     if (message != null)
     {
         Recipient    = message.Recipient;
         NotifyAction = message.Action;
     }
 }
        public void FormatMessage(INoticeMessage message, ITagValue[] tagsValues)
        {
            if (message == null) throw new ArgumentNullException("message");
            if (message.Pattern == null) throw new ArgumentException("message");
            if (tagsValues == null) throw new ArgumentNullException("tagsValues");

            BeforeFormat(message, tagsValues);

            message.Subject = FormatText(doformat ? message.Subject : message.Pattern.Subject, tagsValues);
            message.Body = FormatText(doformat ? message.Body : message.Pattern.Body, tagsValues);

            AfterFormat(message);
        }
        private NotifyMessage CreateNotifyMessage(INoticeMessage message)
        {
            var m = new NotifyMessage
            {
                Subject = message.Subject.Trim(' ', '\t', '\n', '\r'),
                ContentType = message.ContentType,
                Content = message.Body,
                Sender = senderName,
                CreationDate = DateTime.UtcNow,
            };

            var tenant = CoreContext.TenantManager.GetCurrentTenant(false);
            m.Tenant = tenant == null ? Tenant.DEFAULT_TENANT : tenant.TenantId;

            var from = new MailAddress(CoreContext.Configuration.SmtpSettings.SenderAddress, CoreContext.Configuration.SmtpSettings.SenderDisplayName);
            var fromTag = message.Arguments.FirstOrDefault(x => x.Tag.Name.Equals(NotifyArgumentConstants.MessageFrom));
            if (fromTag != null && fromTag.Value != null)
            {
                try
                {
                    from = new MailAddress(from.Address, fromTag.Value.ToString(), Encoding.UTF8);
                }
                catch { }
            }
            m.From = from.ToString();

            var to = new List<string>();
            var nameOne = false;
            foreach (var address in message.Recipient.Addresses)
            {
                var recipient = !nameOne ? new MailAddress(address, message.Recipient.Name) : new MailAddress(address);
                to.Add(recipient.ToString());
                nameOne = true;
            }
            m.To = string.Join("|", to.ToArray());

            var replyTag = message.Arguments.FirstOrDefault(x => x.Tag.Name == "replyto");
            if (replyTag != null && replyTag.Value is string)
            {
                try
                {
                    m.ReplyTo = new MailAddress((string)replyTag.Value).ToString();
                }
                catch (Exception e)
                {
                    LogManager.GetLogger("ASC.Notify").Error("Error creating reply to tag for: " + replyTag.Value, e);
                }
            }

            return m;
        }
 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);
     }
 }
Beispiel #21
0
        public override SendResponse ProcessMessage(INoticeMessage message)
        {
            try
            {
                using var scope = ServiceProvider.CreateScope();
                var tenantManager = scope.ServiceProvider.GetService <TenantManager>();

                var notification = new PushNotification
                {
                    Module       = GetTagValue <PushModule>(message, PushConstants.PushModuleTagName),
                    Action       = GetTagValue <PushAction>(message, PushConstants.PushActionTagName),
                    Item         = GetTagValue <PushItem>(message, PushConstants.PushItemTagName),
                    ParentItem   = GetTagValue <PushItem>(message, PushConstants.PushParentItemTagName),
                    Message      = message.Body,
                    ShortMessage = message.Subject
                };

                if (configured)
                {
                    try
                    {
                        using var pushClient = new PushServiceClient();
                        pushClient.EnqueueNotification(
                            tenantManager.GetCurrentTenant().TenantId,
                            message.Recipient.ID,
                            notification,
                            new List <string>());
                    }
                    catch (InvalidOperationException)
                    {
                        configured = false;
                        _log.Debug("push sender endpoint is not configured!");
                    }
                }
                else
                {
                    _log.Debug("push sender endpoint is not configured!");
                }

                return(new SendResponse(message, Constants.NotifyPushSenderSysName, SendResult.OK));
            }
            catch (Exception error)
            {
                return(new SendResponse(message, Constants.NotifyPushSenderSysName, error));
            }
        }
        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);
            }
        }
 private void LogMessage(INoticeMessage message, string senderName)
 {
     try
     {
         if (logMessages.IsDebugEnabled)
         {
             logMessages.DebugFormat("[{5}]->[{1}] by [{6}] to [{2}] at {0}\r\n\r\n[{3}]\r\n{4}\r\n{7}",
                                     DateTime.Now,
                                     message.Recipient.Name,
                                     0 < message.Recipient.Addresses.Length ? message.Recipient.Addresses[0] : string.Empty,
                                     message.Subject,
                                     (message.Body ?? string.Empty).Replace(Environment.NewLine, Environment.NewLine + @"   "),
                                     message.Action,
                                     senderName,
                                     new string('-', 80));
         }
     }
     catch { }
 }
        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;
        }
        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);
        }
Beispiel #26
0
        public SendResponse Dispatch(INoticeMessage message, string senderName)
        {
            var response = new SendResponse(message, senderName, SendResult.OK);

            if (!logOnly)
            {
                if (context.SenderHolder.GetSender(senderName) != null)
                {
                    var request = new DispatchRequest(message, context.SenderHolder.GetSender(senderName), (n, r) => response = r)
                    {
                        SendAttemptInterval = sendAttemptInterval,
                    };
                    DispatchExecutor(request);
                }
                else
                {
                    response = new SendResponse(message, senderName, SendResult.Impossible);
                }
            }
            LogMessage(message, senderName);
            return(response);
        }
Beispiel #27
0
        public void FormatMessage(INoticeMessage message, ITagValue[] tagsValues)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (message.Pattern == null)
            {
                throw new ArgumentException("message");
            }
            if (tagsValues == null)
            {
                throw new ArgumentNullException("tagsValues");
            }

            BeforeFormat(message, tagsValues);

            message.Subject = FormatText(doformat ? message.Subject : message.Pattern.Subject, tagsValues);
            message.Body    = FormatText(doformat ? message.Body : message.Pattern.Body, tagsValues);

            AfterFormat(message);
        }
Beispiel #28
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));
            }
        }
Beispiel #29
0
        public override SendResponse ProcessMessage(INoticeMessage message)
        {
            try
            {
                var notification = new PushNotification
                {
                    Module       = GetTagValue <PushModule>(message, PushConstants.PushModuleTagName),
                    Action       = GetTagValue <PushAction>(message, PushConstants.PushActionTagName),
                    Item         = GetTagValue <PushItem>(message, PushConstants.PushItemTagName),
                    ParentItem   = GetTagValue <PushItem>(message, PushConstants.PushParentItemTagName),
                    Message      = message.Body,
                    ShortMessage = message.Subject
                };

                if (IsServiceConfigured)
                {
                    using (var pushClient = new PushServiceClient())
                    {
                        pushClient.EnqueueNotification(
                            CoreContext.TenantManager.GetCurrentTenant().TenantId,
                            message.Recipient.ID,
                            notification,
                            new List <string>());
                    }
                }
                else
                {
                    _log.Debug("push sender endpoint is not configured!");
                }

                return(new SendResponse(message, Constants.NotifyPushSenderSysName, SendResult.OK));
            }
            catch (Exception error)
            {
                return(new SendResponse(message, Constants.NotifyPushSenderSysName, error));
            }
        }
 public SendResponse DirectSend(INoticeMessage message)
 {
     return senderSink.ProcessMessage(message);
 }
Beispiel #31
0
 public virtual void ProcessMessageAsync(INoticeMessage message)
 {
     NextSink.ProcessMessageAsync(message);
 }
        public void SendAsync(INoticeMessage message)
        {
            if (message == null) throw new ArgumentNullException("message");

            firstSink.ProcessMessageAsync(message);
        }
Beispiel #33
0
 protected virtual void AfterFormat(INoticeMessage message)
 {
 }
Beispiel #34
0
 public abstract SendResponse ProcessMessage(INoticeMessage message);
Beispiel #35
0
 public ITagValue[] GetDependencies(INoticeMessage message, string objectID, ITag[] tags)
 {
     return(new ITagValue[0]);
 }
 private void LogMessage(INoticeMessage message, string senderName)
 {
     try
     {
         if (logMessages.IsDebugEnabled)
         {
             logMessages.DebugFormat("[{5}]->[{1}] by [{6}] to [{2}] at {0}\r\n\r\n[{3}]\r\n{4}\r\n{7}",
                 DateTime.Now,
                 message.Recipient.Name,
                 0 < message.Recipient.Addresses.Length ? message.Recipient.Addresses[0] : string.Empty,
                 message.Subject,
                 (message.Body ?? string.Empty).Replace(Environment.NewLine, Environment.NewLine + @"   "),
                 message.Action,
                 senderName,
                 new string('-', 80));
         }
     }
     catch { }
 }
Beispiel #37
0
 public override SendResponse ProcessMessage(INoticeMessage message)
 {
     return dispatcher.Dispatch(message, senderName);
 }
 protected virtual void BeforeFormat(INoticeMessage message, ITagValue[] tagsValues)
 {
 }
Beispiel #39
0
 public abstract SendResponse ProcessMessage(INoticeMessage message);
Beispiel #40
0
 public override void ProcessMessageAsync(INoticeMessage message)
 {
     dispatcher.Dispatch(message, senderName);
 }
 protected override void AfterFormat(INoticeMessage message)
 {
     _nvelocityContext = null;
     base.AfterFormat(message);
 }
Beispiel #42
0
 protected virtual void BeforeFormat(INoticeMessage message, ITagValue[] tagsValues)
 {
 }
Beispiel #43
0
 public SendResponse DirectSend(INoticeMessage message)
 {
     return(senderSink.ProcessMessage(message));
 }
 public void FormatMessage(INoticeMessage message, ITagValue[] tagsValues)
 {
 }
Beispiel #45
0
        private NotifyMessage CreateNotifyMessage(INoticeMessage message)
        {
            var m = new NotifyMessage
            {
                Subject      = message.Subject.Trim(' ', '\t', '\n', '\r'),
                ContentType  = message.ContentType,
                Content      = message.Body,
                Sender       = senderName,
                CreationDate = DateTime.UtcNow.Ticks,
            };

            using var scope = ServiceProvider.CreateScope();

            var scopeClass = scope.ServiceProvider.GetService <EmailSenderSinkScope>();

            var(tenantManager, configuration, options) = scopeClass;

            var tenant = tenantManager.GetCurrentTenant(false);

            m.Tenant = tenant == null ? Tenant.DEFAULT_TENANT : tenant.TenantId;

            var from    = MailAddressUtils.Create(configuration.SmtpSettings.SenderAddress, configuration.SmtpSettings.SenderDisplayName);
            var fromTag = message.Arguments.FirstOrDefault(x => x.Tag.Equals("MessageFrom"));

            if ((configuration.SmtpSettings.IsDefaultSettings || string.IsNullOrEmpty(configuration.SmtpSettings.SenderDisplayName)) &&
                fromTag != null && fromTag.Value != null)
            {
                try
                {
                    from = MailAddressUtils.Create(from.Address, fromTag.Value.ToString());
                }
                catch { }
            }
            m.From = from.ToString();

            var to = new List <string>();

            foreach (var address in message.Recipient.Addresses)
            {
                to.Add(MailAddressUtils.Create(address, message.Recipient.Name).ToString());
            }
            m.To = string.Join("|", to.ToArray());

            var replyTag = message.Arguments.FirstOrDefault(x => x.Tag == "replyto");

            if (replyTag != null && replyTag.Value is string)
            {
                try
                {
                    m.ReplyTo = MailAddressUtils.Create((string)replyTag.Value).ToString();
                }
                catch (Exception e)
                {
                    ServiceProvider.GetService <IOptionsMonitor <ILog> >().Get("ASC.Notify").Error("Error creating reply to tag for: " + replyTag.Value, e);
                }
            }

            var priority = message.Arguments.FirstOrDefault(a => a.Tag == "Priority");

            if (priority != null)
            {
                m.Priority = Convert.ToInt32(priority.Value);
            }

            var attachmentTag = message.Arguments.FirstOrDefault(x => x.Tag == "EmbeddedAttachments");

            if (attachmentTag != null && attachmentTag.Value != null)
            {
                m.EmbeddedAttachments.AddRange(attachmentTag.Value as NotifyMessageAttachment[]);
            }

            var autoSubmittedTag = message.Arguments.FirstOrDefault(x => x.Tag == "AutoSubmitted");

            if (autoSubmittedTag != null && autoSubmittedTag.Value is string)
            {
                try
                {
                    m.AutoSubmitted = autoSubmittedTag.Value.ToString();
                }
                catch (Exception e)
                {
                    Log.Error("Error creating AutoSubmitted tag for: " + autoSubmittedTag.Value, e);
                }
            }

            return(m);
        }
        static void DoNotifyRequestAbsoluteUrl(INoticeMessage msg)
        {
            var body = msg.Body;


            body = urlReplacer.Replace(body, (m =>
            {
                var url = m.Groups["url"].Value;
                var ind = m.Groups["url"].Index - m.Index;
                if (String.IsNullOrEmpty(url) && ind > 0)
                    return (m.Value).Insert(ind, CommonLinkUtility.GetFullAbsolutePath(""));
                return (m.Value).Replace(url, CommonLinkUtility.GetFullAbsolutePath(url));
            }));

            body = TextileLinkReplacer.Replace(body, (m =>
            {
                var url = m.Groups["link"].Value;
                var ind = m.Groups["link"].Index - m.Index;
                if (String.IsNullOrEmpty(url) && ind > 0)
                    return (m.Value).Insert(ind, CommonLinkUtility.GetFullAbsolutePath(""));
                return (m.Value).Replace(url, CommonLinkUtility.GetFullAbsolutePath(url));
            }));

            msg.Body = body;
        }
Beispiel #47
0
 public override SendResponse ProcessMessage(INoticeMessage message)
 {
     return(dispatcher.Dispatch(message, senderName));
 }
Beispiel #48
0
        private T GetTagValue <T>(INoticeMessage message, string tagName)
        {
            var tag = message.Arguments.FirstOrDefault(arg => arg.Tag == tagName);

            return(tag != null ? (T)tag.Value : default);
Beispiel #49
0
 public override void ProcessMessageAsync(INoticeMessage message)
 {
     dispatcher.Dispatch(message, senderName);
 }
 protected virtual void AfterFormat(INoticeMessage message)
 {
 }
Beispiel #51
0
 public virtual void ProcessMessageAsync(INoticeMessage message)
 {
     NextSink.ProcessMessageAsync(message);
 }
 protected override void AfterFormat(INoticeMessage message)
 {
     _nvelocityContext = null;
     base.AfterFormat(message);
 }
 public override ITagValue[] GetDependencies(INoticeMessage message, string objectID, ITag[] tags)
 {
     return new ITagValue[0];
 }