public NotificationParameter[] ResolveNotificationParameters(Core.Notifications.Notification notification)
        {
            var retVal = new List <NotificationParameter>();

            List <PropertyInfo> properties = notification.GetType().GetProperties().Where(p => p.GetCustomAttributes(typeof(NotificationParameterAttribute), true).Any()).ToList();

            if (properties.Count > 0)
            {
                foreach (var property in properties)
                {
                    var attributes = property.GetCustomAttributes(typeof(NotificationParameterAttribute), true);
                    retVal.Add(new NotificationParameter
                    {
                        ParameterName        = property.Name,
                        ParameterDescription = attributes.Length > 0 ? ((NotificationParameterAttribute)(attributes[0])).Description : string.Empty,
                        ParameterCodeInView  = GetLiquidCodeOfParameter(property.Name),
                        IsDictionary         = property.PropertyType.IsAssignableFrom(typeof(IDictionary)),
                        IsArray = property.PropertyType.IsArray,
                        Type    = GetParameterType(property.PropertyType.Name)
                    });
                }
            }

            return(retVal.ToArray());
        }
Ejemplo n.º 2
0
        public bool ValidateNotification(Core.Notifications.Notification notification)
        {
            var retVal = false;

            retVal = ValidateNotificationRecipient(notification.Recipient);
            return(retVal);
        }
        SendNotificationResult INotificationManager.SendNotification(Core.Notifications.Notification notification)
        {
            ResolveTemplate(notification);

            var result = notification.SendNotification();

            return(result);
        }
 public void UpdateNotification(Core.Notifications.Notification notification)
 {
     using (var repository = _repositoryFactory())
     {
         repository.Update(notification.ToDataModel());
         repository.UnitOfWork.Commit();
     }
 }
Ejemplo n.º 5
0
        public static NotificationEntity ToDataModel(this Core.Notifications.Notification notification)
        {
            NotificationEntity retVal = new NotificationEntity();

            retVal.InjectFrom(notification);

            retVal.SendingGateway = notification.NotificationSendingGateway.GetType().Name;

            return(retVal);
        }
        public void ScheduleSendNotification(Core.Notifications.Notification notification)
        {
            ResolveTemplate(notification);

            using (var repository = _repositoryFactory())
            {
                var addedNotification = notification.ToDataModel();
                repository.Add(addedNotification);
                repository.UnitOfWork.Commit();
            }
        }
        public Core.Notifications.Notification GetNotificationById(string id)
        {
            Core.Notifications.Notification retVal = null;
            using (var repository = _repositoryFactory())
            {
                var notificationEntity = repository.Notifications.FirstOrDefault(x => x.Id == id);
                if (notificationEntity != null)
                {
                    retVal = GetNotificationCoreModel(notificationEntity);
                }
            }

            return(retVal);
        }
Ejemplo n.º 8
0
        public Core.Notifications.Notification GetNotification(string id)
        {
            Core.Notifications.Notification retVal = null;

            using (var repository = _repositoryFactory())
            {
                var notification = repository.Notifications.FirstOrDefault(n => n.Id == id);
                if (notification != null)
                {
                    retVal = GetNotificationCoreModel(notification);
                }
            }

            return(retVal);
        }
Ejemplo n.º 9
0
        public static NotificationEntity ToDataModel(this Core.Notifications.Notification notification)
        {
            var retVal = new NotificationEntity();

            retVal.InjectFrom(notification);

            retVal.SendingGateway = notification.NotificationSendingGateway.GetType().Name;

            if (notification is EmailNotification emailNotification)
            {
                retVal.Сс  = !emailNotification.CC.IsNullOrEmpty() ? string.Join(",", emailNotification.CC) : null;
                retVal.Bcс = !emailNotification.Bcc.IsNullOrEmpty() ? string.Join(",", emailNotification.Bcc) : null;
            }

            return(retVal);
        }
        public void ResolveTemplate(Core.Notifications.Notification notification)
        {
            var parameters = ResolveNotificationParameters(notification);
            Dictionary <string, object> myDict = new Dictionary <string, object>();

            foreach (var parameter in parameters)
            {
                myDict.Add(parameter.ParameterName, notification.GetType().GetProperty(parameter.ParameterName).GetValue(notification));
            }

            Template templateSubject = Template.Parse(notification.NotificationTemplate.Subject);

            notification.Subject = templateSubject.Render(Hash.FromDictionary(myDict));

            Template templateBody = Template.Parse(notification.NotificationTemplate.Body);

            notification.Body = templateBody.Render(Hash.FromDictionary(myDict));
        }
Ejemplo n.º 11
0
        public SendNotificationResult SendNotification(Core.Notifications.Notification notification)
        {
            var retVal = new SendNotificationResult();

            SendGridMessage mail = new SendGridMessage();

            mail.From = new MailAddress(notification.Sender);
            mail.AddTo(notification.Recipient);
            mail.Subject = notification.Subject;
            mail.Html    = notification.Body;

            var userName = _settingsManager.GetSettingByName(sendGridUserNameSettingName).Value;
            var password = _settingsManager.GetSettingByName(sendGridPasswordSettingName).Value;

            var credentials  = new NetworkCredential(userName, password);
            var transportWeb = new Web(credentials);

            try
            {
                Task.Run(async() => await transportWeb.DeliverAsync(mail)).Wait();
                retVal.IsSuccess = true;
            }
            catch (Exception ex)
            {
                retVal.ErrorMessage = ex.Message;

                if (ex.InnerException is InvalidApiRequestException)
                {
                    var apiEx = ex.InnerException as InvalidApiRequestException;
                    if (apiEx.Errors != null && apiEx.Errors.Length > 0)
                    {
                        retVal.ErrorMessage = string.Join(" ", apiEx.Errors);
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 12
0
 private void ResolveTemplate(Core.Notifications.Notification notification)
 {
     _resolver.ResolveTemplate(notification);
 }
 public bool ValidateNotification(Core.Notifications.Notification notification)
 {
     throw new NotImplementedException();
 }
 public SendNotificationResult SendNotification(Core.Notifications.Notification notification)
 {
     throw new NotImplementedException();
 }
 private void ResolveTemplate(Core.Notifications.Notification notification)
 {
     GetNewNotification(notification.GetType().Name, notification.ObjectId, notification.ObjectTypeId, notification.Language);
     _resolver.ResolveTemplate(notification);
 }