Beispiel #1
0
        /// <summary>
        /// Gets the SMS notification template.
        /// </summary>
        /// <param name="templateName">Name of the template.</param>
        /// <returns></returns>
        public async Task <DatabaseResponse> GetSMSNotificationTemplate(string templateName)
        {
            try
            {
                SqlParameter[] parameters =
                {
                    new SqlParameter("@TemplateName", SqlDbType.NVarChar)
                };

                parameters[0].Value = templateName;

                _DataHelper = new DataAccessHelper(DbObjectNames.z_GetSMSTemplateByName, parameters, _configuration);

                DataTable dt = new DataTable();

                int result = await _DataHelper.RunAsync(dt); // 109 /105

                DatabaseResponse response = new DatabaseResponse();

                SMSTemplates template = new SMSTemplates();

                if (dt != null && dt.Rows.Count > 0)
                {
                    template = (from model in dt.AsEnumerable()
                                select new SMSTemplates()
                    {
                        SMSTemplateID = model.Field <int>("SMSTemplateID"),
                        TemplateName = model.Field <string>("TemplateName"),
                        SMSTemplate = model.Field <string>("SMSTemplate")
                    }).FirstOrDefault();

                    response = new DatabaseResponse {
                        ResponseCode = result, Results = template
                    };
                }


                else
                {
                    response = new DatabaseResponse {
                        ResponseCode = result
                    };
                }

                return(response);
            }

            catch (Exception ex)
            {
                Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                throw (ex);
            }
            finally
            {
                _DataHelper.Dispose();
            }
        }
Beispiel #2
0
        private void SMSTemplatesForm_Load(object sender, EventArgs e)
        {
            SMSTemplates ST   = new SMSTemplates(General.settings.username, General.settings.password, General.settings.host, General.settings.lang);
            string       data = ST.execute();
            IList <IDictionary <string, object> > list_of_dict = new JavaScriptSerializer().Deserialize <IList <IDictionary <string, object> > >(data);
            int i = 0;

            foreach (IDictionary <string, object> item in list_of_dict)
            {
                sms_template_lstbx.Items.Insert(i, item["message"].ToString());
                i++;
            }
        }
        public async void ProcessNotification(object message)
        {
            try
            {
                Amazon.SQS.Model.Message msg = (Amazon.SQS.Model.Message)message;

                string queMessage = msg.Body;
                //LogInfo.Information("8 - bsubscription is  {" + msg.MessageId + "} object");
                SNSSubscription subscription = JsonConvert.DeserializeObject <SNSSubscription>(queMessage);

                //LogInfo.Information("8 - bsubscription is  {" + subscription.MessageId + "} object");
                NotificationMessage NotMessage = JsonConvert.DeserializeObject <NotificationMessage>(subscription.Message);
                //LogInfo.Information("9 - NotMessage is  {" + NotMessage.Message +" "+ NotMessage.MessageType + "} object");
                // SNSSubscription messageObject= new SNSSubscription {  Message=me};

                //   NotificationMessage notification= JsonConvert.DeserializeObject<NotificationMessage>(messageObject.Message);
                if (NotMessage.MessageType == NotificationMsgType.Email.GetDescription())
                {
                    OutboundEmail _email = new OutboundEmail();

                    ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration);

                    DatabaseResponse emailTemplate = await _configAccess.GetEmailNotificationTemplate(NotMessage.Message.messagetemplate.ToString());

                    EmailTemplate template = (EmailTemplate)emailTemplate.Results;

                    var responses = await _email.SendEmail(NotMessage, _iconfiguration, template);


                    foreach (Mandrill.Model.MandrillSendMessageResponse response in responses)
                    {
                        foreach (NotificationParams param in NotMessage.Message.parameters)
                        {
                            if (response.Email == param.emailaddress)
                            {
                                DatabaseResponse notificationLogResponse = await _configAccess.CreateEMailNotificationLog(new NotificationLog {
                                    Status          = response.Status.ToString() == "Sent" ? 1 : 0, Email = response.Email,
                                    EmailTemplateID = template.EmailTemplateID, EmailBody = template.EmailBody,
                                    EmailSubject    = template.EmailSubject, ScheduledOn = subscription.Timestamp, SendOn = DateTime.Now
                                });
                            }
                        }
                    }
                }
                else if (NotMessage.MessageType == NotificationMsgType.SMS.GetDescription())
                {
                    OutboundSMS      _SMS          = new OutboundSMS();
                    TextMessage      smsData       = new TextMessage();
                    ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration);

                    DatabaseResponse smsTemplate = await _configAccess.GetSMSNotificationTemplate(NotMessage.Message.messagetemplate.ToString());

                    SMSTemplates template = (SMSTemplates)smsTemplate.Results;

                    foreach (var item in NotMessage.Message.parameters)
                    {
                        smsData.PhoneNumber = item.mobilenumber;

                        smsData.SMSText = template.SMSTemplate.Replace("*|NAME|*", item.name)
                                          .Replace("*|PARAM1|*", item.param1)
                                          .Replace("*|PARAM2|*", item.param2)
                                          .Replace("*|PARAM3|*", item.param3)
                                          .Replace("*|PARAM4|*", item.param4)
                                          .Replace("*|PARAM5|*", item.param5)
                                          .Replace("*|PARAM6|*", item.param6)
                                          .Replace("*|PARAM7|*", item.param7)
                                          .Replace("*|PARAM8|*", item.param8)
                                          .Replace("*|PARAM9|*", item.param9)
                                          .Replace("*|PARAM10|*", item.param10);
                        //LogInfo.Information("10 - SendSMS is  { "+ smsData+ "}");
                        string response = await _SMS.SendSMSNotification(smsData, _iconfiguration);

                        await _configAccess.CreateSMSNotificationLog(new SMSNotificationLog()
                        {
                            Email         = NotMessage.Message.parameters.Select(x => x.emailaddress).FirstOrDefault(),
                            Mobile        = smsData.PhoneNumber,
                            SMSTemplateID = template.SMSTemplateID,
                            SMSText       = smsData.SMSText,
                            Status        = response != "failure" ? 1 : 0,
                            ScheduledOn   = subscription.Timestamp,
                            SendOn        = DateTime.Now
                        });
                    }

                    //LogInfo.Information("10 - SendSMSLog is  { " + NotMessage.Message.parameters.Select(x => x.emailaddress).FirstOrDefault() + " " + smsData.PhoneNumber + " "+ response + "}");
                }
            }

            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
            }
        }