Example #1
0
        public OutgoingState RecordOutgoingMessage(string senderDeviceId, string deviceId, string payload)
        {
            if (deviceId == null || senderDeviceId == null)
            {
                throw new ForbiddenException();
            }

            if (payload == null)
            {
                throw new ArgumentNullException();
            }

            if (payload.Length > OutgoingMessageSizeLimit)
            {
                throw new ArgumentOutOfRangeException("payload");
            }

            var messageBytes = Encoding.UTF8.GetBytes(payload);

            if (messageBytes.Length > OutgoingMessageSizeLimit)
            {
                throw new ArgumentOutOfRangeException("payload");
            }

            var device = _deviceOperations.Get(deviceId);

            if (senderDeviceId != deviceId)
            {
                var senderDevice = _deviceOperations.Get(senderDeviceId);

                if (device.NetworkId != senderDevice.NetworkId)
                {
                    throw new ForbiddenException();
                }
            }

            var outgoingMessage = new OutgoingMessageToStore(device.NumericId, messageBytes, -1, DateTime.UtcNow, senderDeviceId);

            return(_messagingOperations.Record(outgoingMessage));
        }
Example #2
0
 public OutgoingState Record(OutgoingMessageToStore message)
 {
     return(MessagingWorkers.BatchRunnerRecord.EnqueueAndWaitItem(message));
 }