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);
        }
        public bool Enqueue(IFatpipeMessage msg, Constants.QueueType type)
        {
            string    location = "FpmDal->Enqueue";
            Stopwatch watch;

            try
            {
                // store the entire message in Blob
                string    blobName = msg.Header.Identifier;
                CloudBlob blob;
                bool      inbound = (type == Constants.QueueType.INBOUND);

                Stream blobStream = BizpipeMesssageStreaming.WriteBizpipeMessageToStream(msg);
                // The entry in the Q is the message blob name
                CloudQueueMessage entry = new CloudQueueMessage(blobName);
                //SetQueueBodyData(entry, blobStream);

                if (inbound)
                {
                    //Measure and write to blob storage
                    watch = Stopwatch.StartNew();
                    blob  = inContainer.GetBlobReference(blobName);
                    blob.UploadFromStream(blobStream);
                    watch.Stop();
                    LoggerFactory.Logger.Info(location + "->SaveToIncomingBlob", "timeInMs={0} blobName={1}",
                                              watch.ElapsedMilliseconds, blobName);

                    //Measure and write to incomingQ
                    watch = Stopwatch.StartNew();
                    incomingQ.AddMessage(entry);
                    watch.Stop();
                    LoggerFactory.Logger.Info(location + "->WriteToIncomingQ", "timeInMs={0} entry={1}",
                                              watch.ElapsedMilliseconds, blobName);
                }
                else
                {
                    //Measure and write to blob storage
                    watch = Stopwatch.StartNew();
                    blob  = outContainer.GetBlobReference(blobName);
                    blob.UploadFromStream(blobStream);
                    watch.Stop();
                    LoggerFactory.Logger.Info(location + "->B2BEngineWritingToOutgoingBlob", "timeInMs={0}, blob={1}",
                                              watch.ElapsedMilliseconds, blobName);

                    //Measure and write to incomingQ
                    watch = Stopwatch.StartNew();
                    outgoingQ.AddMessage(entry);
                    watch.Stop();
                    LoggerFactory.Logger.Info(location + "->B2BEngineWritingToOutgoingQ", "timeInMs={0}, entry={1}",
                                              watch.ElapsedMilliseconds, blobName);
                }

                // set the QueueName and the queue message identifiers
                msg.Header.QueueName              = (inbound == true) ? incomingQ.Name : outgoingQ.Name;
                msg.Header.QueueMessageId         = entry.Id;
                msg.Header.QueueMessagePopReceipt = entry.PopReceipt;
            }

            catch (Exception ex)
            {
                LoggerFactory.Logger.Warning(location, EventId.BizpipeEnqueueMessage
                                             , "Exception encountered during Enqueue operation: {0}", ex.ToString());
                return(false);
            }

            return(true);
        }