/// <summary> /// Create the output message when validation errors are captured /// </summary> /// <param name="pContext">Pipeline context</param> /// <param name="pInMsg">Input message in the pipeline</param> /// <param name="errorStream">Stream for the Validation Errors</param> /// <param name="requestId">Request Id</param> /// <returns></returns> public static IBaseMessage CreateOutPutMessage(IPipelineContext pContext, IBaseMessage pInMsg, VirtualStream errorStream, string requestId) { VirtualStream seekableStream = new VirtualStream(pInMsg.BodyPart.GetOriginalDataStream()); seekableStream.Position = 0; errorStream.Position = 0; VirtualStream outMsgStream = CreateValidationErrorMessage(seekableStream, errorStream, requestId); outMsgStream.Position = 0; IBaseMessageFactory messageFactory = pContext.GetMessageFactory(); IBaseMessage pOutMsg = messageFactory.CreateMessage(); IBaseMessagePart pOutMsgBodyPart = messageFactory.CreateMessagePart(); IBasePropertyBag pOutPb = PipelineUtil.CopyPropertyBag(pInMsg.BodyPart.PartProperties, messageFactory); pOutMsg.Context = PipelineUtil.CloneMessageContext(pInMsg.Context); pOutMsgBodyPart.Charset = Constants.BodyPartCharSet; pOutMsgBodyPart.ContentType = Constants.BodyPartContentType; pOutMsgBodyPart.Data = outMsgStream; string outMessageType = string.Format("{0}#{1}", Constants.AIBPValidationErrorNameSpace, Constants.AIBPValidationErrorRootNode); pOutMsg.Context.Promote(Constants.MessageTypePropName, Constants.SystemPropertiesNamespace, outMessageType); pOutMsg.AddPart("Body", pOutMsgBodyPart, true); // Add resources to the resource tracker to be disposed of at correct time pContext.ResourceTracker.AddResource(seekableStream); pContext.ResourceTracker.AddResource(outMsgStream); pContext.ResourceTracker.AddResource(errorStream); return(pOutMsg); }
internal IBaseMessagePart CopyMessagePart(IBaseMessageFactory factory) { IBaseMessagePart part = factory.CreateMessagePart(); part.Data = this.GetOriginalDataStream(); IBasePropertyBag partProperties = this.PartProperties; if (partProperties != null) { IBasePropertyBag bag2 = PipelineUtil.CopyPropertyBag(partProperties, factory); part.PartProperties = bag2; } return(part); }
/// <summary> /// Loads the transmit location adapter configuration /// and gets the value of the specified field /// </summary> /// <param name="propBag">PropertyBag</param> /// <param name="propname">Property name</param> /// <returns>The value</returns> public string GetAdapterConfigValue(IBasePropertyBag propBag, string propname) { string config = (string)propBag.Read("AdapterConfig", PROPNS); if (config == null) { return(null); } XPathDocument doc = new XPathDocument(new StringReader(config)); XPathNavigator nav = doc.CreateNavigator(); string xpath = string.Format("string(/CustomProps/{0})", propname); return((string)nav.Evaluate(xpath)); }
/// <summary> /// Reads all the context properties from the message context into the given dictionary. /// </summary> /// <param name="context">Message context.</param> /// <param name="contextProperties">Dictionary where the context properties will be copied to.</param> public static void ReadAll(this IBasePropertyBag context, Dictionary <string, object> contextProperties) { for (int i = 0; i < context.CountProperties; i++) { string propName = string.Empty; string propNamespace = string.Empty; string key = string.Empty; try { object val = context.ReadAt(i, out propName, out propNamespace); key = string.Format("{0}#{1}", propNamespace, propName); // add or update value contextProperties[key] = val; } catch (Exception ex) { TraceProvider.Logger.TraceError("Namespace: {0}\nName: {1}\n caused an exception:\n{2}\nThis item was not added to the collection.", propNamespace, propName, ex.Message); } } }
/// <summary> /// Reads property value from message context. /// </summary> /// <param name="context">Message context.</param> /// <param name="propertyName">Name of property.</param> /// <param name="propertyNamespace">Namespace of the property.</param> /// <param name="defaultValue">Default value returned if the conversion cannot be performed.</param> /// <returns>Value of the property.</returns> public static T Read <T>(this IBasePropertyBag context, string propertyName, string propertyNamespace, T defaultValue) { if (context == null) { throw new ArgumentNullException("context"); } if (string.IsNullOrEmpty(propertyName)) { throw new ArgumentNullException("propertyName"); } if (string.IsNullOrEmpty(propertyNamespace)) { throw new ArgumentNullException("propertyNamespace"); } try { object value = context.Read(propertyName, propertyNamespace); if (value != null) { if (typeof(T).IsEnum == true) { return((T)Enum.Parse(typeof(T), value.ToString())); } else { return((T)Convert.ChangeType(value, typeof(T))); } } return(defaultValue); } catch { // return default value, if property cannot be read return(defaultValue); } }
/// <summary> /// Loads the transmit location adapter configuration /// and gets the value of the specified field /// </summary> /// <param name="propBag">PropertyBag</param> /// <param name="propname">Property name</param> /// <returns>The value</returns> public string GetAdapterConfigValue(IBasePropertyBag propBag, string propname) { string config = (string)propBag.Read("AdapterConfig", PROPNS); if ( config == null ) return null; XPathDocument doc = new XPathDocument(new StringReader(config)); XPathNavigator nav = doc.CreateNavigator(); string xpath = string.Format("string(/CustomProps/{0})", propname); return (string)nav.Evaluate(xpath); }
void IDisassemblerComponent.Disassemble(IPipelineContext pContext, IBaseMessage pInMsg) { if (pContext == null) { throw new ArgumentNullException("context"); } if (pInMsg == null) { throw new ArgumentNullException("inMsg"); } bool isFault = false; object objFault = pInMsg.Context.Read("IsFault", "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties"); if (objFault != null) { isFault = (bool)objFault; } if (!isFault) { try { this._inputmessage = pInMsg; MultipartMessageDefinition netmsg = GetMessage(this._inputmessage); List <Part> partList = new List <Part>(netmsg.Parts); #region Obsolete /// Find body part //Part bodyPart = partList.Find(p => p.IsBodyPart == true); //if (bodyPart == null) //{ // partList[0].IsBodyPart = true; // bodyPart = partList[0]; //} #endregion //ContextProperty executePipeline = netmsg.PropertyBag.FirstOrDefault(prop => // prop.Namespace == BTSProperties.executePipeline.Name.Namespace // && prop.Name == BTSProperties.executePipeline.Name.Name); IBaseMessage sourceMessage = this.BuildBTSMessage(pContext, pInMsg.Context, partList); if (sourceMessage.BodyPart == null) { throw new Exception("No part was extracted from the mock message!"); } if (this.ExecutePipeline) { object tempInstance = Activator.CreateInstance(Type.GetType(this.PipelineToExecute)); Microsoft.BizTalk.PipelineOM.ReceivePipeline rcvPipeline = (Microsoft.BizTalk.PipelineOM.ReceivePipeline)tempInstance; IBasePropertyBag propBag = pContext.GetMessageFactory().CreatePropertyBag(); ExecutableRcvPipeline pipeline = new ExecutableRcvPipeline(rcvPipeline); pipeline.Run(pContext, sourceMessage); foreach (IBaseMessage outputMsg in pipeline.OutputMsgs) { this.attachPropetyBag(outputMsg, netmsg.PropertyBag); qOutputMsgs.Enqueue(outputMsg); } } else { this.attachPropetyBag(sourceMessage, netmsg.PropertyBag); qOutputMsgs.Enqueue(sourceMessage); } #region Obsolete //if (bodyPart.Data != null) //{ // string bodyType = bodyPart.Data.NamespaceURI + "#" + bodyPart.Data.LocalName; // XmlDocument xDoc = new System.Xml.XmlDocument(); // xDoc.LoadXml(bodyPart.Data.OuterXml); // System.IO.MemoryStream memStream = new MemoryStream(); // xDoc.PreserveWhitespace = true; // xDoc.Save(memStream); // memStream.Position = 0; // memStream.Seek(0, System.IO.SeekOrigin.Begin); // /// If Body part is an enveloppe, we have to split it // IDocumentSpec docSpec = pContext.GetDocumentSpecByType(bodyType); // XPathDocument xp = new XPathDocument(memStream); // if (!String.IsNullOrEmpty(docSpec.GetBodyPath())) // { // XPathNodeIterator xNI = xp.CreateNavigator().Select(docSpec.GetBodyPath()); // while (xNI.MoveNext()) // { // string nodeName = ""; // string nodeNamespace = ""; // if (xNI.Current.MoveToFirstChild()) // { // XmlDocument tempNode = new XmlDocument(); // tempNode.LoadXml(xNI.Current.OuterXml); // nodeName = tempNode.DocumentElement.LocalName; // nodeNamespace = tempNode.DocumentElement.NamespaceURI; // this.CreateMsg(pContext, pInMsg.Context, tempNode.OuterXml, bodyPart.PartName, netmsg.PropertyBag, partList.FindAll(p => p.IsBodyPart != true)); // } // while (xNI.Current.MoveToNext(nodeName, nodeNamespace)) // { // XmlDocument tempNode = new XmlDocument(); // tempNode.LoadXml(xNI.Current.OuterXml); // this.CreateMsg(pContext, pInMsg.Context, tempNode.OuterXml, bodyPart.PartName, netmsg.PropertyBag, partList.FindAll(p => p.IsBodyPart != true)); // } // } // } // else // { // this.CreateMsg(pContext, pInMsg.Context, bodyPart.Data.OuterXml, bodyPart.PartName, netmsg.PropertyBag, partList.FindAll(p => p.IsBodyPart != true)); // } //} //else //{ // this.CreateMsg(pContext, pInMsg.Context, bodyPart.RawData, bodyPart.PartName, netmsg.PropertyBag, partList.FindAll(p => p.IsBodyPart != true)); //} #endregion } catch (Exception e) { if (this.GetFault(pInMsg) != null) { qOutputMsgs.Enqueue(pInMsg); string faultText = this.GetFault(pInMsg).SelectSingleNode("/*[local-name()='Fault']/*[local-name()='faultstring']").InnerText; throw new Exception(faultText); } else { System.Diagnostics.EventLog.WriteEntry(Constants.EVENT_SOURCE, "IDisassemblerComponent.Disassemble : \n" + e.Message + "\n" + e.StackTrace, System.Diagnostics.EventLogEntryType.Error, 8000, 1); throw e; } } } else { qOutputMsgs.Enqueue(pInMsg); } }