Ejemplo n.º 1
0
        /// <summary>
        /// SMS from device.
        /// </summary>
        /// <param name="msg"></param>
        public override void TranslateFromDevice(ProviderMessage msg)
        {
            NmeaConnection.Login("MSISDN", msg.ClientAddress, null);

            ProcessPendingCommand(msg);

            // No framework processing of SMS implemented yet.
        }
        protected override bool SendOutgoing(ProviderMessage provMsg)
        {
            bool   statusCode = false;
            string url        = base.Url;

            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentException("No URL specified for HTTP message provider");
            }
            if (url.IndexOf("://") == -1)
            {
                url = string.Concat("http://", url);
            }
            string message = provMsg.Message;

            if ((message == null ? false : message.Length > 160))
            {
                message = message.Substring(0, 160);
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("&destination=");
            stringBuilder.Append(HttpUtility.UrlEncode(provMsg.ClientAddress.Replace("+", "")));
            stringBuilder.Append("&body=");
            stringBuilder.Append(HttpUtility.UrlEncode(message, Encoding.GetEncoding(1252)));
            url = string.Concat(url, stringBuilder.ToString());
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

            httpWebRequest.Method = "GET";
            this.m_nlog.Info("Send: {0}", url);
            string end = null;

            try
            {
                HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
                end = (new StreamReader(response.GetResponseStream())).ReadToEnd();

                statusCode = HttpStatusCode.OK == response.StatusCode;
                response.Close();
            }
            catch (Exception exception2)
            {
                Exception exception1 = exception2;
                this.m_nlog.Error("HTTP GET {0}", url);
                this.m_nlog.Error("HTTP Response {0}", end);
                this.m_nlog.ErrorException(exception1.GetType().ToString(), exception1);
                throw;
            }
            return(statusCode);
        }