Beispiel #1
0
        void IDataStore.Add(IncomingMessageLog msg)
        {
            lock (_lock)
            {
                if (msg.Id == 0)
                {
                    msg.Id = TestDataStore.NextId();
                }

                _incomingMessageLogs[msg.Id] = msg;
            }
        }
Beispiel #2
0
        public void Incoming(Stream input)
        {
            NameValueCollection param = new NameValueCollection();

            using (StreamReader sr = new StreamReader(input))
            {
                param = HttpUtility.ParseQueryString(sr.ReadToEnd());
            }

            OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;

            string body = param["Body"];
            string from = param["From"];

            IncomingMessageLog incomingLog = new IncomingMessageLog
            {
                Date    = DateTime.UtcNow,
                From    = from,
                Message = body,
            };

            DataStore.GetInstance().Add(incomingLog);

            LogManager.Log.Trace("SMS RECV: {0} {1}", from, body);

            context.Headers.Add(System.Net.HttpResponseHeader.CacheControl, "no-cache");

            if (!ValidatePhoneNumber(from))
            {
                LogManager.Log.Warn("SMS RECV: Invalid Phone Number {0} (reference IncomingMessageLog {1})",
                                    from == null ? "<no from>" : from,
                                    incomingLog.Id);

                context.StatusCode = System.Net.HttpStatusCode.Forbidden;
            }
            else
            {
                ICommandProcessor handler = CommandProcessor.GetInstance();
                handler.Add(new IncomingSmsMessage {
                    From = from, Message = body
                });
                context.StatusCode = System.Net.HttpStatusCode.OK;
            }
        }