Esempio n. 1
0
        public void Write(IGatewayMessage message)
        {
            Guard.NotNull(message, "message");

            byte[] bytes = GatewayPacket.Pack(message, _gatewayBlobStore);
            _queue.AddMessage(bytes);
        }
        public void Write(IGatewayMessage message)
        {
            Guard.NotNull(message, "message");

            byte[] bytes = GatewayPacket.Pack(message, _gatewayBlobStore);
            if (_isSequential)
            {
                SequentialWrite(bytes);
            }
            else
            {
                ParallelWrite(bytes);
            }
        }
Esempio n. 3
0
        public static T Unpack <T>(byte[] packed, IGatewayBlobStore gatewayBlobStore)
            where T : IGatewayMessage
        {
            Guard.NotNull(packed, "packed");
            Guard.NotNull(gatewayBlobStore, "gatewayBlobStore");

            GatewayPacket packet = ZipCompressor.Uncompress <GatewayPacket>(packed);

            if (packet.MessageSerialized == null)
            {
                return(Unpack <T>(gatewayBlobStore.Read(packet.Packet), gatewayBlobStore));
            }

            return(JsonCustomConvert.DeserializeObject <T>(packet.MessageSerialized));
        }
Esempio n. 4
0
        public static byte[] Pack(IGatewayMessage message, IGatewayBlobStore gatewayBlobStore)
        {
            Guard.NotNull(message, "message");
            Guard.NotNull(gatewayBlobStore, "gatewayBlobStore");

            GatewayPacket packet = new GatewayPacket(message);

            byte[] packed = ZipCompressor.Compress(packet);

            if (packed.Length <= CloudQueueMessage.MaxMessageSize)
            {
                return(packed);
            }

            return(ZipCompressor.Compress(new GatewayPacket(gatewayBlobStore.Write(packed))));
        }
Esempio n. 5
0
        /// <summary>
        /// Gets and processes the next message from the queue.
        /// </summary>
        /// <param name="processMessage">Processing action.</param>
        /// <param name="onError">Error action. Should not throw an exception.</param>
        /// <returns>True if the message is processed, false if the queue is empty.</returns>
        public bool ReadNextMessage <T>(
            Action <T> processMessage,
            Action <Exception, T, CloudQueueMessage> onError
            ) where T : IGatewayMessage
        {
            Guard.NotNull(processMessage, "processMessage");

            // TODO set a thread updating invisibility timeout
            CloudQueueMessage queueMessage = _queue.GetMessage();

            if (queueMessage == null)
            {
                return(false);
            }

            T msg = default(T);

            try
            {
                msg = GatewayPacket.Unpack <T>(queueMessage.AsBytes, _gatewayBlobStore);
                processMessage(msg);
            }
            catch (Exception e)
            {
                if (onError != null)
                {
                    onError(e, msg, queueMessage);
                }
            }
            finally
            {
                _queue.DeleteMessage(queueMessage);
            }

            return(true);
        }