public void ValidateXPathExpressions() { XPathQueryLibrary xPathLib = ApplicationConfiguration.Current.XPathQueries; Assert.IsNotNull(xPathLib.Queries, "Unable to load the XPathQueryLibrary configuration sections"); Assert.IsTrue(xPathLib.Namespaces.Count > 0, "Namespaces are not found"); Assert.IsTrue(xPathLib.Queries.Count > 0, "XPath expressions are not found"); NamespaceInfo ns1 = xPathLib.Namespaces.Get("GComInternalSchemas"); Assert.IsNotNull(ns1, "Namespace definition (GComInternalSchemas) is not found"); Assert.IsFalse(String.IsNullOrEmpty(ns1.Name), "Namespace is missing its title"); Assert.IsFalse(String.IsNullOrEmpty(ns1.Prefix), "Namespace is missing its prefix"); XPathQueryInfo query1 = xPathLib.Queries.Get("InventoryReportRoot"); XPathQueryInfo query2 = xPathLib.Queries.Get("InventoryHeader"); XPathQueryInfo query3 = xPathLib.Queries.Get("InventoryReferenceNumber"); Assert.IsFalse(String.IsNullOrEmpty(query1.XPath), "XPath expression (InventoryReportRoot) is empty"); Assert.IsFalse(String.IsNullOrEmpty(query2.XPath), "XPath expression (InventoryHeader) is empty"); Assert.IsFalse(String.IsNullOrEmpty(query3.XPath), "XPath expression (InventoryReferenceNumber) is empty"); Assert.IsTrue(query1.XPath.Contains("ns0"), "XPath expression doesn't contain XML namespace prefix"); Assert.IsTrue(query2.XPath.Contains("{$"), "XPath expression doesn't contain a macro"); Assert.IsTrue(query3.XPath.Contains("{$"), "XPath expression doesn't contain a macro"); string parsedQuery1 = xPathLib.GetXPathQuery(query1.Name); string parsedQuery2 = xPathLib.GetXPathQuery(query2.Name); string parsedQuery3 = xPathLib.GetXPathQuery(query3.Name); Assert.IsFalse(parsedQuery1.Contains("ns0"), "XPath expression must not contain XML namespace prefix"); Assert.IsFalse(parsedQuery2.Contains("{$"), "XPath expression must not contain a macro"); Assert.IsFalse(parsedQuery3.Contains("{$"), "XPath expression must not contain a macro"); XPathQueryInfo lastNameQuery = xPathLib.Queries.Get("LastName"); Trace.WriteLine(String.Format("Original lastNameQuery = {0}", lastNameQuery.XPath)); string parsedLastNameQuery = xPathLib.GetXPathQuery("LastName"); Trace.WriteLine(String.Format("Parsed lastNameQuery = {0}", parsedLastNameQuery)); }
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"); } } } }
public void TestDequeueXmlData() { XPathQueryLibrary xPathLib = ApplicationConfiguration.Current.XPathQueries; var headerSegments = new List <string>(); var bodySegments = new List <string>(); var footerSegments = new List <string>(); headerSegments.Add(xPathLib.GetXPathQuery("InventoryHeader")); footerSegments.Add(xPathLib.GetXPathQuery("InventorySummary")); footerSegments.Add(xPathLib.GetXPathQuery("InventoryIRRSegment")); string itemXPath = xPathLib.GetXPathQuery("InventoryItems"); int fromItem = 1; int xmlBatchSize = 50; XDocument batch = null; Guid queueItemId = Guid.Parse("6DA1B27D-714D-465D-93B8-234B085CF6E4"); using (SqlAzurePersistenceQueue dbQueue = new SqlAzurePersistenceQueue()) { dbQueue.Open(WellKnownDatabaseName.PersistenceQueue); int toItem = fromItem + xmlBatchSize - 1; bodySegments.Clear(); bodySegments.Add(String.Format(xPathLib.GetXPathQuery("InventoryItemBatchTemplate"), fromItem, toItem)); using (XmlReader xmlReader = dbQueue.DequeueXmlData(queueItemId, headerSegments, bodySegments, footerSegments, xPathLib.Namespaces.NamespaceManager)) { if (xmlReader != null) { batch = XDocument.Load(xmlReader); } } } }
/// <summary> /// Synchronously executes the task using the specified <see cref="RuntimeTaskExecutionContext"/> execution context object. /// </summary> /// <param name="context">The execution context.</param> public override void Run(RuntimeTaskExecutionContext context) { string propName, propNamespace; // Check if there are any properties with values to be promoted. if (this.propertyToValueMap.Count > 0) { foreach (var property in this.propertyToValueMap) { if (TryParsePropertyName(property.Key, out propName, out propNamespace)) { #if DEBUG TraceManager.CustomComponent.TraceDetails("DETAIL: Context property promoted: {0}{1}{2} = {3}", propNamespace, BizTalkUtility.ContextPropertyNameSeparator, propName, property.Value); #endif context.Message.Context.Promote(propName, propNamespace, property.Value); } } } // Check if there are any properties to be promoted by inspecting the incoming message and capturing property values using XPath. if (this.propertyToXPathMap.Count > 0) { Stream messageDataStream = BizTalkUtility.EnsureSeekableStream(context.Message, context.PipelineContext); if (messageDataStream != null) { byte[] buffer = new byte[BizTalkUtility.VirtualStreamBufferSize]; string[] propValues = new string[this.propertyToXPathMap.Count]; int arrIndex = 0, matchFound = 0; XPathCollection xc = new XPathCollection(); XPathQueryLibrary xPathLib = ApplicationConfiguration.Current.XPathQueries; foreach (var property in this.propertyToXPathMap) { propValues[arrIndex++] = property.Key; xc.Add(xPathLib.GetXPathQuery(property.Value)); } try { XPathMutatorStream mutator = new XPathMutatorStream(messageDataStream, xc, delegate(int matchIdx, XPathExpression expr, string origValue, ref string finalValue) { if (matchIdx >= 0 && matchIdx < propValues.Length) { if (TryParsePropertyName(propValues[matchIdx], out propName, out propNamespace)) { #if DEBUG TraceManager.CustomComponent.TraceDetails("DETAIL: Context property promoted: {0}{1}{2} = {3}", propNamespace, BizTalkUtility.ContextPropertyNameSeparator, propName, origValue); #endif context.Message.Context.Promote(propName, propNamespace, origValue); } matchFound++; } }); while (mutator.Read(buffer, 0, buffer.Length) > 0 && matchFound < propValues.Length) { ; } } finally { if (messageDataStream.CanSeek) { messageDataStream.Seek(0, SeekOrigin.Begin); } } } } }
/// <summary> /// Synchronously executes the task using the specified <see cref="RuntimeTaskExecutionContext"/> execution context object. /// </summary> /// <param name="context">The execution context.</param> public override void Run(RuntimeTaskExecutionContext context) { if (this.lateBoundActivityValueMap.Count > 0) { foreach (var dateTimeMilestone in this.lateBoundActivityValueMap.Where((item) => { return(item.Value == typeof(DateTime)); })) { SetActivityData(dateTimeMilestone.Key, DateTime.UtcNow); } } if (this.milestoneToXPathMap.Count > 0) { Stream messageDataStream = BizTalkUtility.EnsureSeekableStream(context.Message, context.PipelineContext); if (messageDataStream != null) { byte[] buffer = new byte[BizTalkUtility.VirtualStreamBufferSize]; string[] milestones = new string[this.milestoneToXPathMap.Count]; int arrIndex = 0, matchFound = 0; XPathCollection xc = new XPathCollection(); XPathQueryLibrary xPathLib = ApplicationConfiguration.Current.XPathQueries; foreach (var listItem in this.milestoneToXPathMap) { milestones[arrIndex++] = listItem.Key; xc.Add(xPathLib.GetXPathQuery(listItem.Value)); } try { XPathMutatorStream mutator = new XPathMutatorStream(messageDataStream, xc, delegate(int matchIdx, XPathExpression expr, string origValue, ref string finalValue) { if (matchIdx >= 0 && matchIdx < milestones.Length) { SetActivityData(milestones[matchIdx], origValue); matchFound++; } }); while (mutator.Read(buffer, 0, buffer.Length) > 0 && matchFound < milestones.Length) { ; } // Check we had performed continuation token value resolution via XPath. object continuationToken = null; if (CurrentActivity.ActivityData.TryGetValue(ContinuationTokenInternalDataItemName, out continuationToken)) { CurrentActivity.ContinuationToken = (string)continuationToken; CurrentActivity.ActivityData.Remove(ContinuationTokenInternalDataItemName); } } finally { if (messageDataStream.CanSeek) { messageDataStream.Seek(0, SeekOrigin.Begin); } } } } }