Exemplo n.º 1
0
        public static List <SMSSendResponse> ParseSendBulkSMSResponse(string ResponseXML)
        {
            List <SMSSendResponse> lstSMSResponse = null;
            SMSSendResponse        objSMSResponse = null;

            try
            {
                lstSMSResponse = new List <SMSSendResponse>();

                foreach (XElement level1Element in XElement.Parse(ResponseXML).Elements())
                {
                    objSMSResponse      = new SMSSendResponse();
                    objSMSResponse.GUID = level1Element.Attribute("GUID") != null?level1Element.Attribute("GUID").Value : string.Empty;

                    objSMSResponse.SubmitDate = level1Element.Attribute("SUBMITDATE") != null?level1Element.Attribute("SUBMITDATE").Value : string.Empty;

                    objSMSResponse.ID = level1Element.Attribute("ID") != null?level1Element.Attribute("ID").Value : string.Empty;

                    foreach (XElement level2Element in level1Element.Elements("ERROR"))
                    {
                        objSMSResponse.ErrorSEQ = level2Element.Attribute("SEQ") != null?level2Element.Attribute("SEQ").Value : string.Empty;

                        objSMSResponse.ErrorCODE = level2Element.Attribute("CODE") != null?level2Element.Attribute("CODE").Value : string.Empty;
                    }
                    if (!string.IsNullOrEmpty(objSMSResponse.GUID))
                    {
                        lstSMSResponse.Add(objSMSResponse);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(lstSMSResponse);
        }
Exemplo n.º 2
0
        public static void GetdataFromMySQL()
        {
            List <SMSEntity>       lstSMSEntity       = null;
            List <SMSSendResponse> lstSMSSendResponse = null;
            string                  SMSRequest        = string.Empty;
            string                  SMSResponse       = string.Empty;
            string                  UserName          = string.Empty;
            string                  Password          = string.Empty;
            string                  SMSURL            = string.Empty;
            int                     ID                  = 0;
            var                     Programcode         = string.Empty;
            var                     StoreCode           = string.Empty;
            var                     CampaignCode        = string.Empty;
            var                     MobileNumber        = string.Empty;
            var                     EmailID             = string.Empty;
            var                     MessageText         = string.Empty;
            var                     SenderId            = string.Empty;
            int                     ClientID            = 0;
            string                  apiResponse         = string.Empty;
            MySqlConnection         con                 = null;
            List <ListofSMSDetails> objListofSMSDetails = new List <ListofSMSDetails>();

            try
            {
                DataTable dt = new DataTable();

                IConfiguration config       = new ConfigurationBuilder().AddJsonFile("appsettings.json", true, true).Build();
                var            constr       = config.GetSection("ConnectionStrings").GetSection("HomeShop").Value;
                string         ClientAPIURL = config.GetSection("ConnectionStrings").GetSection("ClientAPIURL").Value;
                con = new MySqlConnection(constr);
                MySqlCommand cmd = new MySqlCommand("SP_HSGetDetailforSMSBroadcast", con)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                };
                cmd.Connection.Open();
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                da.Fill(dt);
                cmd.Connection.Close();
                lstSMSEntity = new List <SMSEntity>();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        ID           = Convert.ToInt32(dr["ID"]);
                        Programcode  = Convert.ToString(dr["Programcode"]);
                        StoreCode    = Convert.ToString(dr["StoreCode"]);
                        CampaignCode = Convert.ToString(dr["CampaignCode"]);
                        MobileNumber = Convert.ToString(dr["MobileNumber"]);
                        EmailID      = Convert.ToString(dr["EmailID"]);
                        MessageText  = Convert.ToString(dr["MessageText"]);
                        SenderId     = Convert.ToString(dr["SenderId"]);
                        ClientID     = Convert.ToInt32(dr["ClientID"]);
                        if (!String.IsNullOrEmpty(MessageText))
                        {
                            SMSEntity objSMSEntity = new SMSEntity()
                            {
                                SMSText      = MessageText,
                                SMSID        = ID.ToString(),
                                SMSSenderID  = SenderId,
                                MobileNumber = MobileNumber,
                                SMSSEQ       = ID.ToString()
                            };
                            lstSMSEntity.Add(objSMSEntity);
                        }
                        if (!String.IsNullOrEmpty(MessageText))
                        {
                            ListofSMSDetails listofSMSDetails = new ListofSMSDetails()
                            {
                                ID           = ID.ToString(),
                                Programcode  = Programcode,
                                MobileNumber = MobileNumber
                            };
                            objListofSMSDetails.Add(listofSMSDetails);
                        }
                    }

                    SMSRequest = SMSCore.PrepareBulkSMSXML(lstSMSEntity);
                    SMSSendResponse chatSendSMSResponse = new SMSSendResponse();
                    if (!string.IsNullOrEmpty(SMSRequest))
                    {
                        UserName    = config.GetSection("MySettings").GetSection("SMSAPIUserName").Value;
                        Password    = config.GetSection("MySettings").GetSection("SMSAPIPassword").Value;
                        SMSURL      = config.GetSection("MySettings").GetSection("SMSAPIURL").Value;
                        SMSResponse = SMSCore.ProcessBulkSMSXML(SMSRequest, UserName, Password, SMSURL);
                        if (!string.IsNullOrEmpty(SMSResponse))
                        {
                            lstSMSSendResponse = new List <SMSSendResponse>();
                            lstSMSSendResponse = SMSCore.ParseSendBulkSMSResponse(SMSResponse);

                            for (int j = 0; j < lstSMSSendResponse.Count; j++)
                            {
                                if (lstSMSSendResponse[j].ErrorCODE == null & lstSMSSendResponse[j].ErrorSEQ == null)
                                {
                                    string Responcetext = "Success";
                                    UpdateResponse(Convert.ToInt32(lstSMSSendResponse[j].ID), lstSMSSendResponse[j].SubmitDate, Responcetext, 1);

                                    try
                                    {
                                        ListofSMSDetails objSMSDetails = new ListofSMSDetails();
                                        objSMSDetails = objListofSMSDetails.Where(x => x.ID == lstSMSSendResponse[j].ID).FirstOrDefault();
                                        MakeBellActive(objSMSDetails.MobileNumber, objSMSDetails.Programcode, ClientAPIURL);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                                else
                                {
                                    string Responcetext = "Fail";
                                    UpdateResponse(Convert.ToInt32(lstSMSSendResponse[j].ID), lstSMSSendResponse[j].SubmitDate, Responcetext, 2);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
                GC.Collect();
            }
        }