示例#1
0
        public Boolean Send()
        {
            if (Recipient == null || !Recipient.Any())
            {
                throw new NullReferenceException("Recipient");
            }
            if (From == null && string.IsNullOrWhiteSpace(FromText))
            {
                throw new NullReferenceException("From");
            }
            if (string.IsNullOrWhiteSpace(Message))
            {
                throw new NullReferenceException("Message");
            }
            if (string.IsNullOrWhiteSpace(UserName))
            {
                throw new NullReferenceException("UserName");
            }
            if (string.IsNullOrWhiteSpace(Password))
            {
                throw new NullReferenceException("Password");
            }


            string Query = "utf8=1&from=" + (From == null ? HttpUtility.UrlEncode(FromText) : HttpUtility.UrlEncode(PhoneNumberBuild(From)));

            Query += string.Format("&username={0}&password={1}", HttpUtility.UrlEncode(UserName), HttpUtility.UrlEncode(Password));
            Query += "&message=" + HttpUtility.UrlEncode(Message);

            if (Recipient.Count() == 1)
            {
                Query += "&recipient=" + HttpUtility.UrlEncode(PhoneNumberBuild(Recipient.First()));
            }
            else
            {
                int i = 1;
                foreach (Person P in Recipient)
                {
                    Query += "&recipient[" + i.ToString() + "]=" + HttpUtility.UrlEncode(PhoneNumberBuild(P));
                }
            }

            if (FlashText)
            {
                Query += "&flash=1";
            }

            if (DeliveryTime != new DateTime())
            {
                Query += "&timestamp=" + DeliveryTime.ToString("yyyyMMddHHmm");
            }

            if (!string.IsNullOrWhiteSpace(HandShakeUrl))
            {
                UriBuilder HS = new UriBuilder(HandShakeUrl);
                Query += "&url=" + HS.ToString();
            }


            CpTestUri.Query = Query;
            //WebRequest theReq = WebRequest.Create();
            System.IO.File.AppendAllText(ConfigurationManager.AppSettings["DummyTextService"] + "\\DummyTextMessages.txt", DateTime.Now.ToString() + " , " + HttpUtility.UrlEncode(this.Message) + " , " + CpTestUri.ToString() + "\r\n");


            // var request = (HttpWebRequest)WebRequest.Create(CpTestUri.ToString());
            // try
            // {
            //     using (var response = request.GetResponse() as HttpWebResponse)
            //     {
            //         if (request.HaveResponse && response != null)
            //         {
            //             using (var reader = new StreamReader(response.GetResponseStream()))
            //             {
            //                 string result = reader.ReadToEnd();
            //             }
            //         }
            //     }
            // }
            //catch (Exception ex)
            //{
            //    Error = ex.ToString();
            //    return false;
            //}


            return(true);
        }
示例#2
0
        public Boolean Send()
        {
            if (Recipient == null || !Recipient.Any())
            {
                throw new NullReferenceException("Recipient");
            }
            if (From == null && string.IsNullOrWhiteSpace(FromText))
            {
                throw new NullReferenceException("From");
            }
            if (string.IsNullOrWhiteSpace(Message))
            {
                throw new NullReferenceException("Message");
            }
            if (string.IsNullOrWhiteSpace(UserName))
            {
                throw new NullReferenceException("UserName");
            }
            if (string.IsNullOrWhiteSpace(Password))
            {
                throw new NullReferenceException("Password");
            }

            Recipient = Recipient.Where(R => R.Mobile != null && !string.IsNullOrWhiteSpace(R.Mobile)).ToList();
            if (!Recipient.Any())
            {
                return(true);
            }

            string Query = "utf8=1&from=" + (From == null ? HttpUtility.UrlEncode(FromText) : HttpUtility.UrlEncode(PhoneNumberBuild(From)));

            Query += string.Format("&username={0}&password={1}", HttpUtility.UrlEncode(UserName), HttpUtility.UrlEncode(Password));
            Query += "&message=" + HttpUtility.UrlEncode(Message);

            if (Recipient.Count() == 1)
            {
                Query += "&recipient=" + HttpUtility.UrlEncode(PhoneNumberBuild(Recipient.First()));
            }
            else
            {
                int i = 1;
                foreach (Person P in Recipient)
                {
                    Query += "&recipient[" + i.ToString() + "]=" + HttpUtility.UrlEncode(PhoneNumberBuild(P));
                }
            }

            if (FlashText)
            {
                Query += "&flash=1";
            }

            if (DeliveryTime != new DateTime())
            {
                Query += "&timestamp=" + DeliveryTime.ToString("yyyyMMddHHmm");
            }

            if (!string.IsNullOrWhiteSpace(HandShakeUrl))
            {
                UriBuilder HS = new UriBuilder(HandShakeUrl);
                Query += "&url=" + HS.ToString();
            }


            CpTestUri.Query = Query;



            //WebRequest theReq = WebRequest.Create();
            var request = (HttpWebRequest)WebRequest.Create(CpTestUri.ToString());

            try
            {
                using (var response = request.GetResponse() as HttpWebResponse)
                {
                    if (request.HaveResponse && response != null)
                    {
                        using (var reader = new StreamReader(response.GetResponseStream()))
                        {
                            string result = reader.ReadToEnd();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Error = ex.ToString();
                LogFile.Write(ex, CpTestUri.ToString());
                return(false);
            }

            LogFile.Write("Text send ˃˃˃ " + CpTestUri.ToString());
            return(true);
        }