public IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage message) { var translationSet = BuildXmlTranslationSet(message); if (translationSet.Items.Any()) { message.BodyPart.WrapOriginalDataStream( originalStream => { var substitutionStream = new XmlTranslatorStream( new XmlTextReader(originalStream), Encoding, translationSet.Items, Modes); return(substitutionStream); }, pipelineContext.ResourceTracker); if (_logger.IsDebugEnabled) { _logger.DebugFormat("Trying to probe and promote translated XML output's message type."); } message.TryProbeAndPromoteMessageType(pipelineContext); } return(message); }
public IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage message) { if (pipelineContext == null) { throw new ArgumentNullException(nameof(pipelineContext)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } var translationSet = BuildXmlTranslationSet(message); if (translationSet.Items.Any()) { message.BodyPart.WrapOriginalDataStream( originalStream => { var substitutionStream = new XmlTranslatorStream( new XmlTextReader(originalStream) { DtdProcessing = DtdProcessing.Prohibit }, Encoding, translationSet.Items, Modes); return(substitutionStream); }, pipelineContext.ResourceTracker); if (_logger.IsDebugEnabled) { _logger.Debug("Trying to probe and promote translated XML output's message type."); } message.TryProbeAndPromoteMessageType(pipelineContext); } return(message); }
/// <summary> /// Transforms original stream using streaming scalable transformation from BizTalk API. /// </summary> /// <param name="inputStream"></param> /// <returns></returns> internal Stream TransformMessage(Stream inputStream, TransformMetaData map, IBaseMessage pInMsg) { XsltArgumentList args = null; Context ext = null; SchemaMetadata targetSchema = targetSchema = map.TargetSchemas[0]; string portname = String.Empty; //It is possible to add a param but then you you need to work arounds in the map // map.ArgumentList.AddParam //The statement bellow caused me some problems that was solved by creating the XsltArgumentList instead //args = map.ArgumentList; try { ext = new Context(); for (int i = 0; i < pInMsg.Context.CountProperties; i++) { string name; string ns; string value = pInMsg.Context.ReadAt(i, out name, out ns).ToString(); ext.Add(name, value, ns); if (m_portDirection == PortDirection.receive && name == "ReceivePortName") { portname = value; } else if (m_portDirection == PortDirection.send && name == "SPName") { portname = value; } } //It is possible to add any information that should be available from the map ext.Add("MessageID", pInMsg.MessageID.ToString()); args = new XsltArgumentList(); //args.AddExtensionObject("http://www.w3.org/1999/XSL/Transform", ext); strangely it seams i cannot use this namespace in vs 2012, but it worked in vs 2010 args.AddExtensionObject("urn:schemas-microsoft-com:xslt", ext); AddParameters(args); //2017-08-23 Added intermidiate stream as Transform kills the original stream, //this is a problem if the incomming message is a enveloped message. XmlTranslatorStream stm = new XmlTranslatorStream(XmlReader.Create(inputStream)); VirtualStream outputStream = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk); XmlTextReader xmlTextReader = new XmlTextReader((TextReader) new StringReader(map.XmlContent)); BTSXslTransform btsXslTransform = new BTSXslTransform(); btsXslTransform.Load((XmlReader)xmlTextReader, new MemoryResourceResolver(portname, m_portDirection), (System.Security.Policy.Evidence)null); btsXslTransform.Transform(stm, args, outputStream, null); outputStream.Seek(0, SeekOrigin.Begin); pInMsg.Context.Promote("MessageType", _systemPropertiesNamespace, targetSchema.SchemaName); pInMsg.Context.Promote("SchemaStrongName", _systemPropertiesNamespace, targetSchema.ReflectedType.AssemblyQualifiedName); //pInMsg.MessageID.ToString() return(outputStream); } catch (Exception ex) { throw new ApplicationException(string.Format("Error while trying to transform using MapType specification: {0}", _mapName), ex); } }