public XPathStream(XmlReader reader, Encoding encoding, SchemaMetaData schemaMetaData,IBaseMessageContext context) { m_context = context; m_schemaMetaData = schemaMetaData; xPathCollection = new XPathCollection(); foreach (var item in m_schemaMetaData.Properties) { xPathCollection.Add(item.Key); } m_bodyPath = new LinkedList<string>(); m_outputStream = new MemoryStream(); this.m_reader = new XPathReader(reader, xPathCollection); this.m_writer = XmlWriter.Create(this.m_outputStream); }
private static void ProcessPropertySchemas(XmlSchema schema, SchemaMetaData schemaMetaData) { XmlSchemaAnnotation annotation = null; if (schema != null && schemaMetaData != null) { if (schema.Items[0] is XmlSchemaAnnotation) { annotation = (XmlSchemaAnnotation)schema.Items[0]; } IEnumerator enumerator = (IEnumerator)annotation.Items.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current is XmlSchemaAppInfo) { XmlNode[] markup = ((XmlSchemaAppInfo)enumerator.Current).Markup; for (int index = 0; index < markup.Length; ++index) { if (markup[index].NamespaceURI == "http://schemas.microsoft.com/BizTalk/2003" && string.Compare(markup[index].LocalName, "imports", StringComparison.Ordinal) == 0) { XmlNode imports = markup[index]; foreach (XmlNode import in imports.ChildNodes) { XmlNode uri = import.Attributes.GetNamedItem("uri"); XmlNode location = import.Attributes.GetNamedItem("location"); Schema propSchema = GetPropertySchema(location.InnerText, uri.InnerText); foreach (DictionaryEntry item in propSchema.Properties) { foreach (var prop in schemaMetaData.Properties) { if (prop.Value.Namespace == propSchema.TargetNameSpace) { if (item.Key.ToString().EndsWith("." + prop.Value.Name)) { prop.Value.TypeCode = TypeFromXmlSchemaType(item.Value.ToString()); } } if (schemaMetaData.IsComplete) { break; } } } } } } break; } } } }
/* public static XmlSchema GetSchema(string SchemaStrongName) * { * ####not used * string ass = SchemaStrongName.Substring(SchemaStrongName.IndexOf(',') + 1).TrimStart(); * string ass_class = SchemaStrongName.Substring(0, SchemaStrongName.IndexOf(',')).TrimEnd(); * * Assembly schema_ass = null; * * try * { * schema_ass = Assembly.Load(ass); * } * catch (FileNotFoundException) * { * * throw new ArgumentException("Schema assembly not found!"); * } * * Type type = schema_ass.GetType(ass_class); * * if (type == null) * throw new ArgumentException("Schema type not found!"); * * dynamic dyn_schema = Activator.CreateInstance(type); * * string schema_data = null; * * try * { * schema_data = dyn_schema.XmlContent; * } * catch (RuntimeBinderException) * { * * throw new ArgumentException("Schema content could not be loaded!"); * } * * XmlSchema schema = XmlSchema.Read(new StringReader(schema_data), null); * * return schema; * }*/ public static SchemaMetaData GetSchemaMetaData(string SchemaStrongName) { //AssemblyFullName does not use the first space //AssemblyFullName BizTalkComponents.PipelineComponents.Schema_Transform_Source, BizTalkComponents.PipelineComponents.XSLTransform.Schema, Version=1.0.0.0, Culture=neutral, PublicKeyToken=47190f56632fbc76 //FullName used in Microsoft.BizTalk.ExplorerOM BizTalkComponents.PipelineComponents.Schema_Transform_Source,BizTalkComponents.PipelineComponents.XSLTransform.Schema, Version=1.0.0.0, Culture=neutral, PublicKeyToken=47190f56632fbc76 SchemaStrongName = SchemaStrongName.Remove(SchemaStrongName.IndexOf(" "), 1); SchemaMetaData _propSchema = null; lock (_propertySchemaCache) { if (_propertySchemaCache.TryGetValue(SchemaStrongName, out _propSchema)) { return(_propSchema); } } //Check schema assembly name when run in BTS if there is any space between class and assembly Microsoft.BizTalk.ExplorerOM.Schema schema = GetSchema(SchemaStrongName); if (schema == null) { return(_propSchema); } XmlSchema xmlSchema = XmlSchema.Read(new StringReader(schema.XmlContent), null); _propSchema = CreateSchemaMetaData(xmlSchema, schema); if (_propSchema != null) { ProcessPropertySchemas(xmlSchema, _propSchema); lock (_propertySchemaCache) { _propertySchemaCache.Add(SchemaStrongName, _propSchema); } } return(_propSchema); }
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg) { string name = String.Empty; string ns = String.Empty; /* * for (int i = 0; i < pInMsg.Context.CountProperties; i++) * { * object obj = pInMsg.Context.ReadAt(i, out name, out ns); * * } */ Stream orig_stream = pInMsg.BodyPart.GetOriginalDataStream(); if (orig_stream == null) { return(pInMsg); } var assembly = pInMsg.Context.Read("SchemaStrongName", ns_system); if (assembly == null) { throw new ArgumentException("Schema StrongName is not promoted!"); } SchemaMetaData schemaMetaData = SchemaRetriever.GetSchemaMetaData((string)assembly); if (schemaMetaData != null) { pInMsg.BodyPart.Data = new XPathStream(orig_stream, schemaMetaData, pInMsg.Context); } return(pInMsg); }
public XPathStream(XmlReader reader, SchemaMetaData schemaMetaData,IBaseMessageContext context) : this(reader, Encoding.UTF8, schemaMetaData,context) { }
public XPathStream(Stream stream, SchemaMetaData schemaMetaData, IBaseMessageContext context) : this(XmlReader.Create(stream), Encoding.UTF8, schemaMetaData,context) { }
private static SchemaMetaData CreateSchemaMetaData(XmlSchema xmlSchema, Schema Schema) { SchemaMetaData _propSchema = null; if (xmlSchema != null) { _propSchema = new SchemaMetaData(); _propSchema.FullName = Schema.AssemblyQualifiedName; XmlQualifiedName[] namespaces = xmlSchema.Namespaces.ToArray(); IEnumerator enumerator = (IEnumerator)xmlSchema.Items.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current is XmlSchemaElement) { XmlSchemaElement elm = (XmlSchemaElement)enumerator.Current; if (elm.Name != Schema.RootName) { continue; } XmlNode appInfo = GetAppInfoXmlNode(elm); if (appInfo == null) { return((SchemaMetaData)null); } foreach (XmlNode property in appInfo.ChildNodes) { XmlNode name = property.Attributes.GetNamedItem("name"); XmlNode xpath = property.Attributes.GetNamedItem("xpath"); string[] _name = name.InnerText.Split(new char[] { ':' }); for (int i = 0; i < namespaces.Length; i++) { XmlQualifiedName qn = namespaces[i]; if (qn.Name == _name[0]) { if (_propSchema.Properties.ContainsKey(xpath.InnerText) == false) { SchemaMetaDataProperty dataProperty = new SchemaMetaDataProperty(); dataProperty.Name = _name[1]; dataProperty.Namespace = qn.Namespace; _propSchema.Properties.Add(xpath.InnerText, dataProperty); } break; } } } } } } return(_propSchema); }