Example #1
0
        private void HandleSendToCommand(SendToCommand command)
        {
            if (!_connection.ConnectionState.HasFlag(ConnectionState.LoggedIn))
            {
                _connection.Reply("sendto unauthorized");
                return;
            }

            try
            {
                var state = _messagingService.RecordOutgoingMessage(_connection.DeviceId, command.DeviceId, command.Message);
                if (state == OutgoingState.Fail)
                {
                    _connection.Reply("sendto error");
                }
                if (state == OutgoingState.Throttled)
                {
                    _connection.Reply("sendto throttled");
                }

                _connection.Reply("sendto ack");
            }
            catch (Exception ex)
            {
                Logger.Error("Send to device error. Device: {0}. {1}", _connection.DeviceId, ex.ToString());
                _connection.Reply("sendto error");
            }

            _connection.Heartbeat();
        }
Example #2
0
        public void SendToCommandTest()
        {
            var ticks         = DateTime.UtcNow.Ticks;
            var sendToCommand = new SendToCommand("deviceId {\"Temperature\":24, \"Time\":" + ticks + "}");

            Assert.IsTrue(sendToCommand.IsValid);
            Assert.AreEqual("deviceId", sendToCommand.DeviceId);
            Assert.AreEqual("{\"Temperature\":24, \"Time\":" + ticks + "}", sendToCommand.Message);
        }
Example #3
0
        public void SendToCommandErrorTest()
        {
            var sendToCommand = new SendToCommand("deviceId{\"Temperature\":24}");

            Assert.IsFalse(sendToCommand.IsValid);
        }