Пример #1
0
        /// <summary>
        /// Gets called by the provider to notify this subscriber about a new item retrieved from the queue.
        /// </summary>
        /// <param name="item">The queue item retrieved from the source queue.</param>
        public void OnNext(XDocument item)
        {
            Guard.ArgumentNotNull(item, "item");
            var callToken = TraceManager.WorkerRoleComponent.TraceIn(item.Root.Name);

            try
            {
                string transformName = ResolveTransformName(item);

                if (!String.IsNullOrEmpty(transformName))
                {
                    XDocument transformedDoc = this.transformService.ApplyTransform(transformName, item);

                    using (ICloudQueueStorage outputQueue = this.storageProviderExtension.GetQueueStorage(this.configSettingsExtension.Settings.CloudStorageAccount))
                    {
                        outputQueue.Put <XDocument>(this.configSettingsExtension.Settings.OutputQueue, transformedDoc);
                    }
                }
                else
                {
                    throw new CloudApplicationException(String.Format(CultureInfo.InstalledUICulture, ExceptionMessages.UnableToResolveTransformName, item.Root.Name, this.configSettingsExtension.Settings.HandlingPolicyName));
                }
            }
            finally
            {
                TraceManager.WorkerRoleComponent.TraceOut(callToken);
            }
        }
Пример #2
0
        public void PutLargeXmlMessage()
        {
            string testFileName = Path.Combine(testMessageFolder, "InventoryReport_2.xml");

            using (ICloudBlobStorage blobStorage = GetCloudBlobStorage())
                using (ICloudQueueStorage queueStorage = GetCloudQueueStorage())
                {
                    LargeQueueMessageInfo largeMsgInfo = LargeQueueMessageInfo.Create(testQueueName);
                    XDocument             testMessage  = XDocument.Load(testFileName);

                    queueStorage.Clear(testQueueName);
                    queueStorage.Put <XDocument>(testQueueName, testMessage);

                    int       blobCount    = blobStorage.GetCount(largeMsgInfo.ContainerName);
                    XDocument msgFromQueue = queueStorage.Get <XDocument>(testQueueName);

                    Assert.IsNotNull(msgFromQueue, "Unable to find message on the queue");
                    Assert.IsTrue(String.Compare(testMessage.ToString(), msgFromQueue.ToString(), false) == 0, "Message content is different");
                    Assert.IsTrue(blobCount == 1, "Blob storage must contain the message data");

                    bool deleted     = queueStorage.Delete <XDocument>(msgFromQueue);
                    int  queueLength = queueStorage.GetCount(testQueueName);

                    Assert.IsTrue(deleted, "Message has not been deleted by some reasons");
                    Assert.IsTrue(queueLength == 0, "Queue is not empty by some reasons");

                    blobCount = blobStorage.GetCount(largeMsgInfo.ContainerName);
                    Assert.IsTrue(blobCount == 0, "Blob storage is not empty by some reasons");
                }
        }
Пример #3
0
        private void DequeueXmlDataTaskMain(DequeueXmlDataTaskState state)
        {
            Guard.ArgumentNotNull(state, "state");

            using (ICloudQueueStorage workItemQueue = state.StorageProvider.GetQueueStorage(state.Settings.CloudStorageAccount))
                using (SqlAzurePersistenceQueue dbQueue = new SqlAzurePersistenceQueue())
                {
                    dbQueue.Open(WellKnownDatabaseName.PersistenceQueue);

                    using (XmlReader xmlReader = dbQueue.DequeueXmlData(state.QueueItemInfo.QueueItemId, state.HeaderSegments, state.BodySegments, state.FooterSegments, state.NamespaceManager))
                    {
                        if (xmlReader != null)
                        {
                            XDocument batch = XDocument.Load(xmlReader);

                            // Check for presence of any items in the batch.
                            bool batchFound = (batch.XPathSelectElement(state.ItemDetectionXPath) != null);

                            if (batchFound)
                            {
                                workItemQueue.Put <XDocument>(state.Settings.DestinationQueue, batch);
                            }
                        }
                    }
                }
        }
Пример #4
0
        public void PutLargeBinaryMessage()
        {
            int largeMessageSize = 2 * 1024 * 1024;
            var largeMessage     = new byte[largeMessageSize];

            randGenerator.NextBytes(largeMessage);

            using (ICloudBlobStorage blobStorage = GetCloudBlobStorage())
                using (ICloudQueueStorage queueStorage = GetCloudQueueStorage())
                {
                    LargeQueueMessageInfo largeMsgInfo = LargeQueueMessageInfo.Create(testQueueName);

                    queueStorage.Clear(testQueueName);
                    queueStorage.Put <byte[]>(testQueueName, largeMessage);

                    int    blobCount    = blobStorage.GetCount(largeMsgInfo.ContainerName);
                    byte[] msgFromQueue = queueStorage.Get <byte[]>(testQueueName);

                    Assert.IsNotNull(msgFromQueue, "Unable to find message on the queue");

                    var matchedBytes = msgFromQueue.Where((value, index) =>
                    {
                        return(largeMessage[index] == value);
                    });

                    Assert.IsTrue(matchedBytes.Count() == largeMessageSize, "Message content is different");
                    Assert.IsTrue(blobCount == 1, "Blob storage must contain the message data");

                    bool deleted     = queueStorage.Delete <byte[]>(msgFromQueue);
                    int  queueLength = queueStorage.GetCount(testQueueName);

                    Assert.IsTrue(deleted, "Message has not been deleted by some reasons");
                    Assert.IsTrue(queueLength == 0, "Queue is not empty by some reasons");

                    blobCount = blobStorage.GetCount(largeMsgInfo.ContainerName);
                    Assert.IsTrue(blobCount == 0, "Blob storage is not empty by some reasons");
                }
        }