public void TestCoreOperations() { string testFileName = Path.Combine(testMessageFolder, "InventoryReport_0.xml"); PersistenceQueueItemInfo queueItemInfo = null; try { using (FileStream fileStream = new FileStream(testFileName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (SqlAzurePersistenceQueue persistenceQueue = new SqlAzurePersistenceQueue()) { persistenceQueue.Open(WellKnownDatabaseName.PersistenceQueue); queueItemInfo = persistenceQueue.Enqueue(fileStream); } } Assert.IsTrue(queueItemInfo.QueueItemSize > 0, "QueueItemSize is zero"); Assert.IsTrue(!String.IsNullOrEmpty(queueItemInfo.QueueItemType), "QueueItemType is zero"); XPathQueryLibrary xPathLib = ApplicationConfiguration.Current.GetConfigurationSection <XPathQueryLibrary>(XPathQueryLibrary.SectionName); string itemCountXPath = xPathLib.GetXPathQuery("InventoryItemCount"); using (SqlAzurePersistenceQueue persistenceQueue = new SqlAzurePersistenceQueue()) { persistenceQueue.Open(WellKnownDatabaseName.PersistenceQueue); using (XmlReader resultReader = persistenceQueue.QueryXmlData(queueItemInfo.QueueItemId, new string[] { itemCountXPath }, xPathLib.Namespaces.NamespaceManager)) { int itemCount = resultReader.ReadContentAsInt(); Assert.IsTrue(itemCount > 0, "Item count is zero"); Assert.AreEqual <int>(6, itemCount, "Wrong item count"); } } } finally { if (queueItemInfo != null) { using (SqlAzurePersistenceQueue persistenceQueue = new SqlAzurePersistenceQueue()) { persistenceQueue.Open(WellKnownDatabaseName.PersistenceQueue); bool removed = persistenceQueue.Remove(queueItemInfo.QueueItemId); Assert.IsTrue(removed, "Item was not removed"); } } } }
/// <summary> /// Persists the specified stream of data into the queue and returns an unique identify that corresponds to the persisted queue item. /// </summary> /// <param name="data">The stream containing the data to be persisted.</param> /// <returns>The unique identity of the queue item.</returns> public Guid PersistDataStream(Stream data) { Guard.ArgumentNotNull(data, "data"); var callToken = TraceManager.WorkerRoleComponent.TraceIn(data.GetType().FullName); PersistenceQueueItemInfo queueItemInfo = null; using (SqlAzurePersistenceQueue dbQueue = new SqlAzurePersistenceQueue(StreamingMode.FixedBuffer)) { dbQueue.Open(WellKnownDatabaseName.PersistenceQueue); queueItemInfo = dbQueue.Enqueue(data); } if (PersistDataStreamCompleted != null) { PersistDataStreamCompleted(queueItemInfo); } TraceManager.WorkerRoleComponent.TraceOut(callToken, queueItemInfo.QueueItemId); return(queueItemInfo.QueueItemId); }