public IFatpipeMessage GetSuspendedMessage(string messageIdentifier)
        {
            string                 location         = "FpmDal->GetSuspendedMessage";
            IFatpipeMessage        result           = null;
            SuspendedMessageEntity suspendedMessage = null;

            try
            {
                Stopwatch watch = Stopwatch.StartNew();

                suspendedMessage =
                    (from e in this.suspendedTableServiceContext.CreateQuery <SuspendedMessageEntity>(MaargConfiguration.Instance[MaargConfiguration.SuspendedMessageTableName])
                     where e.RowKey == messageIdentifier
                     select e).FirstOrDefault();

                if (suspendedMessage != null)
                {
                    IFatpipeMessage message = null;
                    CloudBlob       blob    = this.suspendedContainer.GetBlobReference(suspendedMessage.SuspendedMessageBlobReference);
                    using (MemoryStream stream = new MemoryStream())
                    {
                        blob.DownloadToStream(stream);
                        stream.Position = 0;
                        message         = BizpipeMesssageStreaming.CreateBizpipeMessageFromStream(stream, this.fpm);
                    }

                    if (!string.IsNullOrEmpty(suspendedMessage.PartnerIdentifier))
                    {
                        IOutboundFatpipeMessage outboundMessage = this.fpm.CreateNewOutboundMessage();
                        outboundMessage.Header                    = message.Header;
                        outboundMessage.Body                      = message.Body;
                        outboundMessage.Status                    = message.Status;
                        outboundMessage.RoutingInfo               = new RoutingInfo();
                        outboundMessage.RoutingInfo.PartnerId     = suspendedMessage.PartnerIdentifier;
                        outboundMessage.RoutingInfo.TransportType = TransportType.Suspend;

                        result = outboundMessage;
                    }
                    else
                    {
                        result = message;
                    }
                }

                watch.Stop();
                LoggerFactory.Logger.Debug(location,
                                           "Message {0} retrieved from suspended queue in {1} ms.",
                                           messageIdentifier,
                                           watch.ElapsedMilliseconds);
            }
            catch (Exception exception)
            {
                LoggerFactory.Logger.Error(location, EventId.BizpipeGetSuspendMessage
                                           , "Error getting the suspended message {0}: {1}."
                                           , messageIdentifier
                                           , exception.ToString());
            }

            return(result);
        }
        public IFatpipeMessage Dequeue(Constants.QueueType type)
        {
            string          location       = "FpmDal->Dequeue";
            IFatpipeMessage fatpipeMessage = null;

            bool               inbound   = (type == Constants.QueueType.INBOUND);
            CloudQueue         queue     = inbound ? this.incomingQ : this.outgoingQ;
            CloudBlobContainer container = inbound ? this.inContainer : this.outContainer;

            try
            {
                Stopwatch         watch = Stopwatch.StartNew();
                CloudQueueMessage entry = queue.GetMessage(this.visibilityTimeout);
                if (entry != null)
                {
                    watch.Stop();
                    LoggerFactory.Logger.Info(location + (inbound ? "->B2BEngineReadingFromIncomingQ" : "OutboundTransportReadingFromOutgoingQ"),
                                              "timeInMs={0}, entry={1}",
                                              watch.ElapsedMilliseconds, entry.AsString);

                    byte[]       buffer          = null;
                    bool         isInlineContent = inbound ? GetContent(entry, out buffer) : false;
                    MemoryStream blobStream      = null;
                    if (isInlineContent)
                    {
                        blobStream = new MemoryStream(buffer);
                    }
                    else
                    {
                        watch = Stopwatch.StartNew();
                        string             blobName = entry.AsString;
                        CloudBlob          blob     = container.GetBlobReference(blobName);
                        BlobRequestOptions options  = new BlobRequestOptions();
                        blobStream = new MemoryStream();
                        blob.DownloadToStream(blobStream);
                        watch.Stop();
                        LoggerFactory.Logger.Info(location + (inbound ? "->B2BEngineReadingFromIncomingBlob" : "OutboundTransportReadingFromOutgoingBlob"),
                                                  "timeInMs={0}, blob={1}",
                                                  watch.ElapsedMilliseconds, blobName);
                    }
                    blobStream.Position = 0;
                    //msg = DecodeBlobPayload(blobStream, this.fpm);
                    fatpipeMessage = BizpipeMesssageStreaming.CreateBizpipeMessageFromStream(blobStream, this.fpm);
                    // set the QueueName and the queue message identifiers
                    fatpipeMessage.Header.QueueName              = (inbound == true) ? incomingQ.Name : outgoingQ.Name;
                    fatpipeMessage.Header.QueueMessageId         = entry.Id;
                    fatpipeMessage.Header.QueueMessagePopReceipt = entry.PopReceipt;
                    fatpipeMessage.Status.NumberOfRetryAttempts  = entry.DequeueCount;
                }
            }
            catch (Exception ex)
            {
                LoggerFactory.Logger.Warning(location, EventId.BizpipeDequeueMessage
                                             , "Exception encountered during Dequeue operation: {0}", ex.ToString());
            }

            return(fatpipeMessage);
        }