/// <summary>
        /// Sends a notification by a notification object
        /// </summary>
        /// <param name="notificationObj">notification object</param>
        public override void SendNotification(vNotification notificationObj)
        {
            ////throw new NotImplementedException();
            //TemplateParams p = GetTemplateParams(notificationObj);

            //IUserDeviceSettingService service = UserDeviceSettingEN.GetService("");
            //MobileNotificationMessage message = new MobileNotificationMessage();
            //message.Type = new MobileNotificationTypeSEnum(notificationObj.MobilePushType);
            //message.ParamsJSON = p.ProcessTemplate(notificationObj.MobilePushParamsJSON);
            //message.Alert = p.ProcessTemplate(notificationObj.MobilePushAlert);
            //message.Title = p.ProcessTemplate(notificationObj.MobilePushTitle);
            //message.Sound = p.ProcessTemplate(notificationObj.MobilePushSound);
            //message.TimeToLiveSeconds = notificationObj.TimeToLiveSeconds;
            //message.CollapseKey = null;
            //message.DelayWhileIdle = null;
            //message.IsOneSufficient = false;

            ////string messageBody = p.ProcessTemplate(notificationObj.MobilePushBody);
            ////string sound = notificationObj.MobilePushSound;
            ////int? timeToLiveSeconds = notificationObj.TimeToLiveSeconds;
            ////string collapseKeyIfAny = null;
            ////bool? delayWhileIdle = null;
            ////service.PushNotification(notificationObj.ReceiverUserID, messageBody, sound, timeToLiveSeconds, collapseKeyIfAny, delayWhileIdle);
            //service.PushNotification(notificationObj.ReceiverUserID, message);

            //FWUtils.ExpLogUtils.Logger.WriteLog(new AppLog() { AppLogTypeID = (short)EntityEnums.AppLogType.Notify_MobilePush, UserID = notificationObj.ReceiverUserID, ExtraBigInt = notificationObj.NotificationID });
        }
예제 #2
0
        /// <summary>
        /// Gets the template parameters.
        /// It makes default parameters + notification parameters available in the object
        /// </summary>
        /// <param name="notificationObj">The notification object.</param>
        /// <returns></returns>
        public TemplateParams GetTemplateParams(vNotification notificationObj)
        {
            var    projectSettings            = FWUtils.ConfigUtils.GetAppSettings().Project;
            string websiteUrl                 = projectSettings.WebsiteUrl;
            string appTitle                   = projectSettings.Title;
            string emailVerificationUrl       = projectSettings.GetEmailVerificationCompleteUrl(notificationObj.RecieverUserEmailVerificationCode);
            string phoneNumberVerificationUrl = projectSettings.GetPhoneNumberVerificationCompleteUrl(notificationObj.RecieverUserPhoneVerificationCode);

            TemplateParams p = new TemplateParams().DeserializeFromString(notificationObj.ParametersValues);

            // adding default parameters
            p.AddParameter("App.WebsiteUrl", websiteUrl);
            p.AddParameter("App.Title", appTitle);

            p.AddParameter("ReceiverUser.UserTitle", FWUtils.EntityUtils.ConcatStrings(" ", notificationObj.RecieverUserNamePrefix, notificationObj.ReceiverUserFirstName, notificationObj.ReceiverUserLastName));
            p.AddParameter("ReceiverUser.FirstName", notificationObj.ReceiverUserFirstName);
            p.AddParameter("ReceiverUser.UserName", notificationObj.RecieverUserUserName);
            p.AddParameter("ReceiverUser.Email", notificationObj.ReceiverUserEmail);
            p.AddParameter("ReceiverUser.EmailVerificationCode", notificationObj.RecieverUserEmailVerificationCode.ToString());
            p.AddParameter("ReceiverUser.EmailVerificationUrl", emailVerificationUrl);
            p.AddParameter("ReceiverUser.PhoneVerificationCode", notificationObj.RecieverUserPhoneVerificationCode.ToString());
            p.AddParameter("ReceiverUser.PhoneVerificationUrl", phoneNumberVerificationUrl);

            p.AddParameter("SenderUser.UserTitle", FWUtils.EntityUtils.ConcatStrings(" ", notificationObj.SenderUserNamePrefix, notificationObj.SenderUserFirstName, notificationObj.SenderUserLastName));
            p.AddParameter("SenderUser.FirstName", notificationObj.SenderUserFirstName);
            p.AddParameter("SenderUser.UserName", notificationObj.SenderUserLastName);
            p.AddParameter("SenderUser.Email", notificationObj.SenderUserEmail);
            p.AddParameter("Notification.NotificationID", notificationObj.NotificationID.ToString());
            p.AddParameter("App.CompanyAddress", projectSettings.CompanyAddress);

            return(p);
        }
예제 #3
0
        /// <summary>
        /// Sends the notification
        /// </summary>
        /// <param name="notification">The notification.</param>
        public static void SendNotification(vNotification notification)
        {
            //TODO: This design is not scalable for Mobile Push system
            //send email notification
            string errorMessage = null;

            if (notification.IsEmail)
            {
                try
                {
                    emailNotificationSender.SendNotification(notification);
                    notification.EmailNotificationStatusID = (int)EntityEnums.NotificationStatusEnum.Sent;
                    notification.EmailSendDate             = DateTime.UtcNow;
                }
                catch (Exception ex)
                {
                    FWUtils.ExpLogUtils.ExceptionLogger.LogError(ex, "EMail, NotificationID:" + notification.NotificationID);
                    errorMessage = ex.Message;
                }
            }

            // send SMS notification
            if (notification.IsSMS)
            {
                try
                {
                    smsNotificationSender.SendNotification(notification);
                    notification.SMSNotificationStatusID = (int)EntityEnums.NotificationStatusEnum.Sent;
                    notification.SMSSendDate             = DateTime.UtcNow;
                }
                catch (Exception ex)
                {
                    FWUtils.ExpLogUtils.ExceptionLogger.LogError(ex, "SMS, NotificationID:" + notification.NotificationID);
                    errorMessage = ex.Message;
                }
            }

            //send mobile push notify
            if (notification.IsMobilePushMessage)
            {
                try
                {
                    mobilePushMessageSender.SendNotification(notification);
                }
                catch (Exception ex)
                {
                    FWUtils.ExpLogUtils.ExceptionLogger.LogError(ex, "MobilePush, NotificationID:" + notification.NotificationID);
                    errorMessage = ex.Message;
                }
            }

            notification.NotificationErrorMessage = errorMessage;

            UpdateNotificationStatus(notification);
        }
        public override void SendNotification(vNotification notificationObj)
        {
            TemplateParams p    = GetTemplateParams(notificationObj);
            string         to   = notificationObj.ReceiverUserPhoneNumber;
            string         body = p.ProcessTemplate(notificationObj.SMSBody);

            SendSMS(to, body);
            //Console.WriteLine(message.Sid);

            FWUtils.ExpLogUtils.Logger.WriteLog(new AppLog()
            {
                AppLogTypeID = (short)EntityEnums.AppLogType.Notify_SMS, UserID = notificationObj.ReceiverUserID, ExtraBigInt = notificationObj.NotificationID
            });
            //throw new NotImplementedException();
        }
예제 #5
0
        /// <summary>
        /// Updates the notification status.
        /// </summary>
        /// <param name="notification">The notification.</param>
        public static void UpdateNotificationStatus(vNotification notification)
        {
            INotificationService service = (INotificationService)EntityFactory.GetEntityServiceByName(
                vNotification.EntityName, "");

            Notification n = (Notification)service.GetByID(notification.NotificationID, new GetByIDParameters());

            n.SMSNotificationStatusID   = notification.SMSNotificationStatusID;
            n.EmailNotificationStatusID = notification.EmailNotificationStatusID;
            n.NotificationErrorMessage  = notification.NotificationErrorMessage;
            n.EmailSendDate             = notification.EmailSendDate;
            n.SMSSendDate = notification.SMSSendDate;

            service.Update(n, new UpdateParameters());
        }
        public override void SendNotification(vNotification notificationObj)
        {
            TemplateParams p = GetTemplateParams(notificationObj);

            // ignoring sending emails when receiver doesn't have any email address in our system (causes exception)
            if (string.IsNullOrEmpty(notificationObj.ReceiverUserEmail) == false)
            {
                string fromEmail  = null;
                string toEmail    = notificationObj.ReceiverUserEmail;
                string subject    = p.ProcessTemplate(notificationObj.EmailSubject);
                string body       = p.ProcessTemplate(GetEmailMasterTemplate(notificationObj.EmailBodyText));
                bool   isBodyHtml = true;

                SendEmailMessage(fromEmail, toEmail, subject, body, isBodyHtml);

                // logging the details
                FWUtils.ExpLogUtils.Logger.WriteLog(new AppLog()
                {
                    AppLogTypeID = (short)EntityEnums.AppLogType.Notify_Email, UserID = notificationObj.ReceiverUserID, ExtraBigInt = notificationObj.NotificationID
                });
            }
        }
        public void SendNotificationTest()
        {
            Notification notification = CreateNewNotification((short)EntityEnums.NotificationTemplateEnum.TestNotification);

            notification.IsSMS = true;
            notification.IsMobilePushMessage = true;

            INotificationService service = (INotificationService)
                                           EntityFactory.GetEntityServiceByName(vNotification.EntityName, "");

            service.Insert(notification, new InsertParameters());
            vNotification nSaved = (vNotification)service.GetByID(notification.NotificationID, new GetByIDParameters(GetSourceTypeEnum.View));

            NotificationSenderAgent.SendNotification(nSaved);

            // Check that log inserted for all notifications (no error happened anywhere)
            IAppLogService logService = (IAppLogService)
                                        EntityFactory.GetEntityServiceByName(AppLog.EntityName, "");
            FilterExpression filter = new FilterExpression(new Filter(AppLog.ColumnNames.ExtraBigInt, nSaved.NotificationID));
            FilterExpression f2     = new FilterExpression();

            f2.AddFilter(new Filter(AppLog.ColumnNames.AppLogTypeID, (int)EntityEnums.AppLogType.Notify_Email));
            f2.AddFilter(new Filter(AppLog.ColumnNames.AppLogTypeID, (int)EntityEnums.AppLogType.Notify_MobilePush));
            f2.AddFilter(new Filter(AppLog.ColumnNames.AppLogTypeID, (int)EntityEnums.AppLogType.Notify_SMS));
            f2.LogicalOperator = FilterLogicalOperatorEnum.OR;
            filter.AndMerge(f2);

            long logCount = logService.GetCount(filter);

            Assert.AreEqual(2, logCount, "EMAIL, SMS has not saved in logs. So, error in media");

            // check that all parameters are valid after save
            vNotification nSaved2 = (vNotification)service.GetByID(notification.NotificationID, new GetByIDParameters(GetSourceTypeEnum.View));

            Assert.IsNull(nSaved2.NotificationErrorMessage);
            Assert.IsNotNull(nSaved2.EmailSendDate);
            Assert.IsNotNull(nSaved2.SMSSendDate);
        }
예제 #8
0
 public abstract void SendNotification(vNotification notificationObj);