コード例 #1
0
        public static void QueueInboundSMS(MobileOriginatedMessage msg)
        {
            MessageQueue _mq = null;

            _mq           = new MessageQueue(InboundQueueName);
            _mq.Formatter = new BinaryMessageFormatter();

            if (msg.MessageId == null || msg.MessageId == "")
            {
                msg.MessageId = System.Guid.NewGuid().ToString();
            }

            Message qmsg = new Message(msg, new BinaryMessageFormatter());

            qmsg.Recoverable = true;
            switch (msg.Priority)
            {
            case 1:
                qmsg.Priority = MessagePriority.Highest;
                break;

            case 2:
                qmsg.Priority = MessagePriority.High;
                break;

            // case 3 is below
            case 4:
                qmsg.Priority = MessagePriority.Low;
                break;

            default:
            case 3:
                qmsg.Priority = MessagePriority.Normal;
                break;
            }
            qmsg.Label = "MobileOriginatedMessage";
            _mq.Send(qmsg);
            qmsg.Dispose();

            InboundSms.Increment();
            InboundSmsPerSec.Increment();
        }
コード例 #2
0
        public static MobileOriginatedMessage BuildMsgFromCollection(NameValueCollection col)
        {
            MobileOriginatedMessage mo = new MobileOriginatedMessage();

            if (!IsNull(col["connection"]))
            {
                mo.Connection = col["connection"];
            }
            if (!IsNull(col["custom1"]))
            {
                mo.Custom1 = col["custom1"];
            }
            if (!IsNull(col["custom2"]))
            {
                mo.Custom2 = col["custom2"];
            }
            if (!IsNull(col["custom3"]))
            {
                mo.Custom3 = col["custom3"];
            }
            if (!IsNull(col["encoding"]) || !IsNull(col["coding"]))
            {
                string enc = col["encoding"];
                if (IsNull(enc))
                {
                    enc = col["coding"];
                }

                enc = enc.ToLowerInvariant();

                if (enc == "7bit")
                {
                    mo.Encoding = SmsEncoding.Default7Bit;
                }
                else if (enc == "utf-8")
                {
                    mo.Encoding = SmsEncoding.Utf8;
                }
                else if (enc == "8bit")
                {
                    mo.Encoding = SmsEncoding.Data8Bit;
                }
                else if (enc == "ucs2")
                {
                    mo.Encoding = SmsEncoding.Ucs2;
                }
                else
                {
                    throw new Exception("Invalid sms encoding type");
                }
            }
            if (!IsNull(col["la"]))
            {
                mo.LargeAccount = col["la"];
            }
            if (!IsNull(col["msgid"]))
            {
                mo.MessageId = col["msgid"];
            }
            if (!IsNull(col["msisdn"]))
            {
                mo.MSISDN = col["msisdn"];
            }
            if (!IsNull(col["opcode"]))
            {
                mo.OperatorCode = col["opcode"];
            }
            if (!IsNull(col["priority"]))
            {
                mo.Priority = Convert.ToInt32(col["priority"]);
            }
            if (!IsNull(col["sent"]))
            {
                string d = col["sent"].ToString();
                mo.Sent = new DateTime(Convert.ToInt32(d.Substring(0, 4)), Convert.ToInt32(d.Substring(4, 2)), Convert.ToInt32(d.Substring(6, 2)), Convert.ToInt32(d.Substring(8, 2)), Convert.ToInt32(d.Substring(10, 2)), Convert.ToInt32(d.Substring(12, 2)));
            }
            if (!IsNull(col["udh"]))
            {
                mo.UDH = col["udh"];
            }
            if (!IsNull(col["message"]))
            {
                mo.Message = col["message"];
            }
            if (!IsNull(col["bin"]))
            {
                mo.BinaryMessage = col["bin"];
            }
            return(mo);
        }
コード例 #3
0
        public static string QueryStringFromMsg(MobileOriginatedMessage mo)
        {
            string qs = "";

            if (!IsNull(mo.Connection))
            {
                qs += "connection=" + HttpUtility.UrlEncode(mo.Connection, Encoding.UTF8) + "&";
            }
            if (!IsNull(mo.Custom1))
            {
                qs += "custom1=" + HttpUtility.UrlEncode(mo.Custom1, Encoding.UTF8) + "&";
            }
            if (!IsNull(mo.Custom2))
            {
                qs += "custom2=" + HttpUtility.UrlEncode(mo.Custom2, Encoding.UTF8) + "&";
            }
            if (!IsNull(mo.Custom3))
            {
                qs += "custom3=" + HttpUtility.UrlEncode(mo.Custom3, Encoding.UTF8) + "&";
            }
            qs += "encoding=";
            switch (mo.Encoding)
            {
            case SmsEncoding.Default7Bit: {
                qs += HttpUtility.UrlEncode("7bit", Encoding.UTF8) + "&";
                break;
            }

            case SmsEncoding.Utf8: {
                qs += HttpUtility.UrlEncode("utf-8", Encoding.UTF8) + "&";
                break;
            }

            case SmsEncoding.Data8Bit: {
                qs += HttpUtility.UrlEncode("8bit", Encoding.UTF8) + "&";
                break;
            }

            case SmsEncoding.Ucs2: {
                qs += HttpUtility.UrlEncode("ucs2", Encoding.UTF8) + "&";
                break;
            }
            }
            if (!IsNull(mo.LargeAccount))
            {
                qs += "la=" + HttpUtility.UrlEncode(mo.LargeAccount, Encoding.UTF8) + "&";
            }
            if (!IsNull(mo.MessageId))
            {
                qs += "msgid=" + HttpUtility.UrlEncode(mo.MessageId, Encoding.UTF8) + "&";
            }
            if (!IsNull(mo.MSISDN))
            {
                qs += "msisdn=" + HttpUtility.UrlEncode(mo.MSISDN, Encoding.UTF8) + "&";
            }
            if (!IsNull(mo.OperatorCode))
            {
                qs += "opcode=" + HttpUtility.UrlEncode(mo.OperatorCode, Encoding.UTF8) + "&";
            }
            qs += "priority=" + HttpUtility.UrlEncode(mo.Priority.ToString(), Encoding.UTF8) + "&";
            if (mo.Sent != DateTime.MinValue)
            {
                qs += "sent=" + HttpUtility.UrlEncode(mo.Sent.ToString("yyyyMMddHHmmss"), Encoding.UTF8) + "&";
            }
            if (!IsNull(mo.UDH))
            {
                qs += "udh=" + HttpUtility.UrlEncode(mo.UDH, Encoding.UTF8) + "&";
            }
            if (!IsNull(mo.Message))
            {
                qs += "message=" + HttpUtility.UrlEncode(mo.Message, Encoding.UTF8) + "&";
            }
            if (!IsNull(mo.BinaryMessage))
            {
                qs += "bin=" + HttpUtility.UrlEncode(mo.BinaryMessage, Encoding.UTF8) + "&";
            }
            qs.TrimEnd(new char[] { '&' });
            return(qs);
        }