private Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema GetXmlSchemaFromSchemaFile(Uri schemaFile, DocumentNode dataSource, out string errorMessage) { errorMessage = string.Empty; Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema xmlSchema = (Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema)null; try { bool isSchemaValid = true; using (XmlReader reader = XmlReader.Create(schemaFile.ToString())) { System.Xml.Schema.XmlSchema schema = System.Xml.Schema.XmlSchema.Read(reader, (ValidationEventHandler)((sender, e) => isSchemaValid = false)); if (schema != null) { if (isSchemaValid) { XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(schema); schemaSet.Compile(); xmlSchema = new Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema(schemaSet, dataSource); } } } } finally { if (xmlSchema == null) { errorMessage = StringTable.XmlDataSourceSchemaReadError; } } return(xmlSchema); }
private Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema InferXmlSchemaFromXmlFile(XmlReader xmlReader, DocumentNode dataSource, out string errorMessage) { errorMessage = string.Empty; Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema xmlSchema = (Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema)null; try { xmlSchema = new Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema(new XmlSchemaInference().InferSchema(xmlReader), dataSource); return(xmlSchema); } finally { if (xmlSchema == null) { errorMessage = StringTable.XmlDataSourceSchemaInferenceError; } } }
public ISchema GetSchemaForDataSourceInternal(DocumentNode dataSource, out string errorMessage) { errorMessage = string.Empty; ISchema schema = (ISchema)null; IProjectItem designDataFile = DesignDataHelper.GetDesignDataFile(dataSource); if (designDataFile != null) { return(this.GetSchemaForDesignDataFile(designDataFile)); } if (this.schemaCache.TryGetValue(dataSource, out schema)) { ClrObjectSchema clrObjectSchema = schema as ClrObjectSchema; if (clrObjectSchema != null && clrObjectSchema.Root.Type != DataContextHelper.GetDataType(clrObjectSchema.DataSource.DocumentNode).RuntimeType) { this.schemaCache.Remove(dataSource); schema = (ISchema)null; } if (schema != null) { return(schema); } } if (dataSource != null) { if (PlatformTypes.XmlDataProvider.IsAssignableFrom((ITypeId)dataSource.Type)) { Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema xmlSchema = (Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema)null; try { Uri uriPropertyValue1 = this.GetUriPropertyValue(dataSource, DesignTimeProperties.SchemaUriProperty); if (uriPropertyValue1 != (Uri)null) { xmlSchema = this.GetXmlSchemaFromSchemaFile(uriPropertyValue1, dataSource, out errorMessage); } else { Uri uriPropertyValue2 = this.GetUriPropertyValue(dataSource, XmlDataProviderSceneNode.SourceProperty); if (uriPropertyValue2 != (Uri)null) { using (XmlReader xmlReader = XmlReader.Create(uriPropertyValue2.AbsoluteUri)) xmlSchema = this.InferXmlSchemaFromXmlFile(xmlReader, dataSource, out errorMessage); } else { string inlineXmlData = this.GetInlineXmlData(dataSource); if (inlineXmlData != null) { using (StringReader stringReader = new StringReader(inlineXmlData)) { using (XmlReader xmlReader = XmlReader.Create((TextReader)stringReader)) xmlSchema = this.InferXmlSchemaFromXmlFile(xmlReader, dataSource, out errorMessage); } } } } } catch { } if (xmlSchema == null) { xmlSchema = new Microsoft.Expression.DesignSurface.UserInterface.DataPane.XmlSchema(dataSource); } schema = (ISchema)xmlSchema; } else { schema = SchemaManager.GetSchemaForType(this.GetTypeForDataSource(dataSource), dataSource); } } if (schema == null) { schema = (ISchema) new EmptySchema(); } if (dataSource.DocumentRoot != null) { this.schemaCache[dataSource] = schema; } return(schema); }