private static void ApplyXsltExtensionObjectOverridesToXsltArguments(XsltArgumentList transformArgs, IEnumerable <XsltExtensionObjectDescriptor> xsltExtensionObjectOverrides, TransformBase map) { var xsltArgumentListContent = XElement.Parse(map.XsltArgumentListContent); foreach (var item in xsltExtensionObjectOverrides) { var name = FindNamespaceForXsltExtensionObjectType(xsltArgumentListContent, item.ClassType); transformArgs.RemoveExtensionObject(name); transformArgs.AddExtensionObject(name, item.Instance); } }
private void FillExtentionsToXsltArguments(XsltArgumentList args, ExtentionElementCollection extensions) { if (extensions != null) { foreach (ExtentionElement ext in extensions) { args.RemoveExtensionObject(ext.Namespace); Type t = Type.GetType(ext.Type, false); if (t != null) { object obj = null; if (!t.IsAbstract) { obj = Activator.CreateInstance(t); } args.AddExtensionObject(ext.Namespace, obj); } } } }
/// <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(pInMsg.Context, pInMsg.MessageID.ToString()); args = map.ArgumentList;//Include BizTalk extensions //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.RemoveExtensionObject("urn:schemas-microsoft-com:xslt"); 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)); //Opted to use non disposable stream instead NonDisposableStream stm = new NonDisposableStream(inputStream); VirtualStream outputStream = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk); //TODO test to add declaration and see what happens with params!!!!!!!!!!!!!!!!!!!!!!!! BTSXslTransform btsXslTransform = null; if (Transforms.ContainsKey(map)) { btsXslTransform = Transforms[map]; } else { btsXslTransform = new BTSXslTransform(); XmlTextReader xmlTextReader = new XmlTextReader((TextReader) new StringReader(map.XmlContent)); btsXslTransform.Load((XmlReader)xmlTextReader, new MemoryResourceResolver(map.Assembly), (System.Security.Policy.Evidence)null); Transforms.TryAdd(map, btsXslTransform); } btsXslTransform.Transform(stm, args, outputStream, null); outputStream.Seek(0, SeekOrigin.Begin); if (_dynamicMap) { pInMsg.Context.Write("XSLTransform", "PipelineComponents.XSLTransform", map.AssemblyQualifiedName); } pInMsg.Context.Promote("MessageType", _systemPropertiesNamespace, targetSchema.SchemaName); //Changed to Write as SchemaStrongName could exceed 255 chars pInMsg.Context.Write("SchemaStrongName", _systemPropertiesNamespace, targetSchema.ReflectedType.AssemblyQualifiedName); //pInMsg.MessageID.ToString() return(outputStream); } catch (Exception ex) { throw new ApplicationException($"Error while trying to transform using MapType specification: {_mapName}\nMap Assembly {map.AssemblyQualifiedName} used\nError {ex.Message}", ex); } }