private SchemaManager(SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded) { _dataModel = dataModel; _providerNotification = providerNotification; _providerManifestTokenNotification = providerManifestTokenNotification; _providerManifestNeeded = providerManifestNeeded; }
// <summary> // Load stuff from xml readers - this now includes XmlReader instances created over embedded // resources. See the remarks section below for some useful information. // </summary> // <param name="xmlReaders"> A list of XmlReader instances </param> // <param name="dataModelOption"> whether this is a entity data model or provider data model </param> // <param name="providerManifest"> provider manifest from which the primitive type definition comes from </param> // <param name="itemCollection"> item collection to add the item after loading </param> internal static IList <EdmSchemaError> LoadItems( IEnumerable <XmlReader> xmlReaders, IEnumerable <string> sourceFilePaths, SchemaDataModelOption dataModelOption, DbProviderManifest providerManifest, ItemCollection itemCollection, bool throwOnError) { IList <Schema> schemaCollection = null; // Parse and validate all the schemas - since we support using now, // we need to parse them as a group var errorCollection = SchemaManager.ParseAndValidate( xmlReaders, sourceFilePaths, dataModelOption, providerManifest, out schemaCollection); // Try to initialize the metadata if there are no errors if (MetadataHelper.CheckIfAllErrorsAreWarnings(errorCollection)) { var errors = LoadItems(providerManifest, schemaCollection, itemCollection); foreach (var error in errors) { errorCollection.Add(error); } } if (!MetadataHelper.CheckIfAllErrorsAreWarnings(errorCollection) && throwOnError) { //Future Enhancement: if there is an error, we throw exception with error and warnings. //Otherwise the user has no clue to know about warnings. throw EntityUtil.InvalidSchemaEncountered(Helper.CombineErrorMessage(errorCollection)); } return(errorCollection); }
internal static List <string> GetPrimarySchemaNamespaces(SchemaDataModelOption dataModel) { List <string> stringList = new List <string>(); switch (dataModel) { case SchemaDataModelOption.EntityDataModel: stringList.Add("http://schemas.microsoft.com/ado/2006/04/edm"); stringList.Add("http://schemas.microsoft.com/ado/2007/05/edm"); stringList.Add("http://schemas.microsoft.com/ado/2008/09/edm"); stringList.Add("http://schemas.microsoft.com/ado/2009/11/edm"); break; case SchemaDataModelOption.ProviderDataModel: stringList.Add("http://schemas.microsoft.com/ado/2006/04/edm/ssdl"); stringList.Add("http://schemas.microsoft.com/ado/2009/02/edm/ssdl"); stringList.Add("http://schemas.microsoft.com/ado/2009/11/edm/ssdl"); break; default: stringList.Add("http://schemas.microsoft.com/ado/2006/04/edm/providermanifest"); break; } return(stringList); }
public static IList <EdmSchemaError> ParseAndValidate( IEnumerable <XmlReader> xmlReaders, IEnumerable <string> sourceFilePaths, SchemaDataModelOption dataModel, DbProviderManifest providerManifest, out IList <Schema> schemaCollection) { return(SchemaManager.ParseAndValidate(xmlReaders, sourceFilePaths, dataModel, new AttributeValueNotification(SchemaManager.NoOpAttributeValueNotification), new AttributeValueNotification(SchemaManager.NoOpAttributeValueNotification), (ProviderManifestNeeded)(error => providerManifest ?? (DbProviderManifest)MetadataItem.EdmProviderManifest), out schemaCollection)); }
public static IList <EdmSchemaError> ParseAndValidate( IEnumerable <XmlReader> xmlReaders, IEnumerable <string> sourceFilePaths, SchemaDataModelOption dataModel, DbProviderManifest providerManifest, out IList <Schema> schemaCollection) { return(ParseAndValidate( xmlReaders, sourceFilePaths, dataModel, NoOpAttributeValueNotification, NoOpAttributeValueNotification, delegate { return providerManifest == null ? MetadataItem.EdmProviderManifest : providerManifest; }, out schemaCollection)); }
private static XmlSchemaSet ComputeSchemaSet(SchemaDataModelOption dataModel) { List <string> schemaNamespaces = System.Data.Entity.Core.SchemaObjectModel.Schema.SomSchemaSetHelper.GetPrimarySchemaNamespaces(dataModel); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.XmlResolver = (XmlResolver)null; Dictionary <string, XmlSchemaResource> schemaResourceMap = XmlSchemaResource.GetMetadataSchemaResourceMap(3.0); HashSet <string> schemasAlreadyAdded = new HashSet <string>(); foreach (string index in schemaNamespaces) { XmlSchemaResource schemaResource = schemaResourceMap[index]; System.Data.Entity.Core.SchemaObjectModel.Schema.SomSchemaSetHelper.AddXmlSchemaToSet(schemaSet, schemaResource, schemasAlreadyAdded); } schemaSet.Compile(); return(schemaSet); }
internal static List <string> GetPrimarySchemaNamespaces(SchemaDataModelOption dataModel) { var namespaces = new List <string>(); if (dataModel == SchemaDataModelOption.EntityDataModel) { namespaces.Add(XmlConstants.ModelNamespace_1); namespaces.Add(XmlConstants.ModelNamespace_1_1); namespaces.Add(XmlConstants.ModelNamespace_2); namespaces.Add(XmlConstants.ModelNamespace_3); } else if (dataModel == SchemaDataModelOption.ProviderDataModel) { namespaces.Add(XmlConstants.TargetNamespace_1); namespaces.Add(XmlConstants.TargetNamespace_2); namespaces.Add(XmlConstants.TargetNamespace_3); } else { Debug.Assert(dataModel == SchemaDataModelOption.ProviderManifestModel, "Unknown SchemaDataModelOption did you add one?"); namespaces.Add(XmlConstants.ProviderManifestNamespace); } return(namespaces); }
private static XmlSchemaSet ComputeSchemaSet(SchemaDataModelOption dataModel) { var namespaceNames = GetPrimarySchemaNamespaces(dataModel); Debug.Assert(namespaceNames.Count > 0, "Unknown Datamodel"); var schemaSet = new XmlSchemaSet(); // remove the default XmlResolver which will look on // disk for the referenced schemas that we already provided schemaSet.XmlResolver = null; var schemaResourceMap = XmlSchemaResource.GetMetadataSchemaResourceMap(XmlConstants.SchemaVersionLatest); var schemasAlreadyAdded = new HashSet <string>(); foreach (var namespaceName in namespaceNames) { Debug.Assert(schemaResourceMap.ContainsKey(namespaceName), "the namespace name is not one we have a schema set for"); var schemaResource = schemaResourceMap[namespaceName]; AddXmlSchemaToSet(schemaSet, schemaResource, schemasAlreadyAdded); } schemaSet.Compile(); return(schemaSet); }
internal static IList <EdmSchemaError> LoadItems( IEnumerable <XmlReader> xmlReaders, IEnumerable <string> sourceFilePaths, SchemaDataModelOption dataModelOption, DbProviderManifest providerManifest, ItemCollection itemCollection, bool throwOnError) { IList <Schema> schemaCollection = (IList <Schema>)null; IList <EdmSchemaError> andValidate = SchemaManager.ParseAndValidate(xmlReaders, sourceFilePaths, dataModelOption, providerManifest, out schemaCollection); if (MetadataHelper.CheckIfAllErrorsAreWarnings(andValidate)) { foreach (EdmSchemaError loadItem in EdmItemCollection.LoadItems(providerManifest, schemaCollection, itemCollection)) { andValidate.Add(loadItem); } } if (!MetadataHelper.CheckIfAllErrorsAreWarnings(andValidate) && throwOnError) { throw EntityUtil.InvalidSchemaEncountered(Helper.CombineErrorMessage((IEnumerable <EdmSchemaError>)andValidate)); } return(andValidate); }
internal static XmlSchemaSet GetSchemaSet(SchemaDataModelOption dataModel) { return(_cachedSchemaSets.Evaluate(dataModel)); }
internal static string ExtractTypeName(SchemaDataModelOption dataModel, string qualifiedTypeName) { Debug.Assert(!string.IsNullOrEmpty(qualifiedTypeName), "qualifiedTypeName parameter is null or empty"); return(GetEverythingAfterLastPeriod(qualifiedTypeName)); }
internal static void ExtractNamespaceAndName(SchemaDataModelOption dataModel, string qualifiedTypeName, out string namespaceName, out string name) { Debug.Assert(!string.IsNullOrEmpty(qualifiedTypeName), "qualifiedTypeName parameter is null"); GetBeforeAndAfterLastPeriod(qualifiedTypeName, out namespaceName, out name); }
public static IList<EdmSchemaError> ParseAndValidate( IEnumerable<XmlReader> xmlReaders, IEnumerable<string> sourceFilePaths, SchemaDataModelOption dataModel, DbProviderManifest providerManifest, out IList<Schema> schemaCollection) { return ParseAndValidate( xmlReaders, sourceFilePaths, dataModel, NoOpAttributeValueNotification, NoOpAttributeValueNotification, error => providerManifest ?? MetadataItem.EdmProviderManifest, out schemaCollection); }
public static IList <EdmSchemaError> ParseAndValidate(IEnumerable <XmlReader> xmlReaders, IEnumerable <string> sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, out IList <Schema> schemaCollection) { SchemaManager schemaManager = new SchemaManager(dataModel, providerNotification, providerManifestTokenNotification, providerManifestNeeded); var errorCollection = new List <EdmSchemaError>(); schemaCollection = new List <Schema>(); bool errorEncountered = false; List <string> filePathList; if (sourceFilePaths != null) { filePathList = new List <string>(sourceFilePaths); } else { filePathList = new List <string>(); } int index = 0; foreach (XmlReader xmlReader in xmlReaders) { string location = null; if (filePathList.Count <= index) { TryGetBaseUri(xmlReader, out location); } else { location = filePathList[index]; } Schema schema; schema = new Schema(schemaManager); var errorsForCurrentSchema = schema.Parse(xmlReader, location); CheckIsSameVersion(schema, schemaCollection, errorCollection); // If the number of errors exceeded the max error count, then return if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, errorsForCurrentSchema, ref errorEncountered)) { return(errorCollection); } // Add the schema to the collection if there are no errors. There are errors in which schema do not have any namespace. // Also if there is an error encountered in one of the schema, we do not need to add the remaining schemas since // we will never go to the resolve phase. if (!errorEncountered) { schemaCollection.Add(schema); schemaManager.AddSchema(schema); var currentSchemaVersion = schema.SchemaVersion; Debug.Assert(schemaCollection.All(s => s.SchemaVersion == currentSchemaVersion || s.SchemaVersion != XmlConstants.UndefinedVersion)); } index++; } // If there are no errors encountered in the parsing stage, we can proceed to the // parsing and validating phase if (!errorEncountered) { foreach (Schema schema in schemaCollection) { if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, schema.Resolve(), ref errorEncountered)) { return(errorCollection); } } // If there are no errors encountered in the parsing stage, we can proceed to the // parsing and validating phase if (!errorEncountered) { foreach (Schema schema in schemaCollection) { if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, schema.ValidateSchema(), ref errorEncountered)) { return(errorCollection); } } } } return(errorCollection); }
public static IList <EdmSchemaError> ParseAndValidate( IEnumerable <XmlReader> xmlReaders, IEnumerable <string> sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, out IList <Schema> schemaCollection) { SchemaManager schemaManager = new SchemaManager(dataModel, providerNotification, providerManifestTokenNotification, providerManifestNeeded); List <EdmSchemaError> errorCollection = new List <EdmSchemaError>(); schemaCollection = (IList <Schema>) new List <Schema>(); bool errorEncountered = false; List <string> stringList = sourceFilePaths == null ? new List <string>() : new List <string>(sourceFilePaths); int index = 0; foreach (XmlReader xmlReader in xmlReaders) { string location = (string)null; if (stringList.Count <= index) { SchemaManager.TryGetBaseUri(xmlReader, out location); } else { location = stringList[index]; } Schema schema = new Schema(schemaManager); IList <EdmSchemaError> newErrors = schema.Parse(xmlReader, location); SchemaManager.CheckIsSameVersion(schema, (IEnumerable <Schema>)schemaCollection, errorCollection); if (SchemaManager.UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, newErrors, ref errorEncountered)) { return((IList <EdmSchemaError>)errorCollection); } if (!errorEncountered) { schemaCollection.Add(schema); schemaManager.AddSchema(schema); } ++index; } if (!errorEncountered) { foreach (Schema schema in (IEnumerable <Schema>)schemaCollection) { if (SchemaManager.UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, schema.Resolve(), ref errorEncountered)) { return((IList <EdmSchemaError>)errorCollection); } } if (!errorEncountered) { foreach (Schema schema in (IEnumerable <Schema>)schemaCollection) { if (SchemaManager.UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, schema.ValidateSchema(), ref errorEncountered)) { return((IList <EdmSchemaError>)errorCollection); } } } } return((IList <EdmSchemaError>)errorCollection); }
public static IList<EdmSchemaError> ParseAndValidate(IEnumerable<XmlReader> xmlReaders, IEnumerable<string> sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, out IList<Schema> schemaCollection) { SchemaManager schemaManager = new SchemaManager(dataModel, providerNotification, providerManifestTokenNotification, providerManifestNeeded); var errorCollection = new List<EdmSchemaError>(); schemaCollection = new List<Schema>(); bool errorEncountered = false; List<string> filePathList; if (sourceFilePaths != null) { filePathList = new List<string>(sourceFilePaths); } else { filePathList = new List<string>(); } int index = 0; foreach (XmlReader xmlReader in xmlReaders) { string location = null; if (filePathList.Count <= index) { TryGetBaseUri(xmlReader, out location); } else { location = filePathList[index]; } Schema schema; schema = new Schema(schemaManager); var errorsForCurrentSchema = schema.Parse(xmlReader, location); CheckIsSameVersion(schema, schemaCollection, errorCollection); // If the number of errors exceeded the max error count, then return if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, errorsForCurrentSchema, ref errorEncountered)) { return errorCollection; } // Add the schema to the collection if there are no errors. There are errors in which schema do not have any namespace. // Also if there is an error encountered in one of the schema, we do not need to add the remaining schemas since // we will never go to the resolve phase. if (!errorEncountered) { schemaCollection.Add(schema); schemaManager.AddSchema(schema); var currentSchemaVersion = schema.SchemaVersion; Debug.Assert(schemaCollection.All(s => s.SchemaVersion == currentSchemaVersion || s.SchemaVersion != XmlConstants.UndefinedVersion)); } index++; } // If there are no errors encountered in the parsing stage, we can proceed to the // parsing and validating phase if (!errorEncountered) { foreach (Schema schema in schemaCollection) { if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, schema.Resolve(), ref errorEncountered)) { return errorCollection; } } // If there are no errors encountered in the parsing stage, we can proceed to the // parsing and validating phase if (!errorEncountered) { foreach (Schema schema in schemaCollection) { if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, schema.ValidateSchema(), ref errorEncountered)) { return errorCollection; } } } } return errorCollection; }
private static XmlSchemaSet ComputeSchemaSet(SchemaDataModelOption dataModel) { var namespaceNames = GetPrimarySchemaNamespaces(dataModel); Debug.Assert(namespaceNames.Count > 0, "Unknown Datamodel"); var schemaSet = new XmlSchemaSet(); // remove the default XmlResolver which will look on // disk for the referenced schemas that we already provided schemaSet.XmlResolver = null; var schemaResourceMap = XmlSchemaResource.GetMetadataSchemaResourceMap(XmlConstants.SchemaVersionLatest); var schemasAlreadyAdded = new HashSet<string>(); foreach (var namespaceName in namespaceNames) { Debug.Assert(schemaResourceMap.ContainsKey(namespaceName), "the namespace name is not one we have a schema set for"); var schemaResource = schemaResourceMap[namespaceName]; AddXmlSchemaToSet(schemaSet, schemaResource, schemasAlreadyAdded); } schemaSet.Compile(); return schemaSet; }
internal static XmlSchemaSet GetSchemaSet(SchemaDataModelOption dataModel) { return _cachedSchemaSets.Evaluate(dataModel); }
internal static List<string> GetPrimarySchemaNamespaces(SchemaDataModelOption dataModel) { var namespaces = new List<string>(); if (dataModel == SchemaDataModelOption.EntityDataModel) { namespaces.Add(XmlConstants.ModelNamespace_1); namespaces.Add(XmlConstants.ModelNamespace_1_1); namespaces.Add(XmlConstants.ModelNamespace_2); namespaces.Add(XmlConstants.ModelNamespace_3); } else if (dataModel == SchemaDataModelOption.ProviderDataModel) { namespaces.Add(XmlConstants.TargetNamespace_1); namespaces.Add(XmlConstants.TargetNamespace_2); namespaces.Add(XmlConstants.TargetNamespace_3); } else { Debug.Assert(dataModel == SchemaDataModelOption.ProviderManifestModel, "Unknown SchemaDataModelOption did you add one?"); namespaces.Add(XmlConstants.ProviderManifestNamespace); } return namespaces; }
/// <summary> /// Load stuff from xml readers - this now includes XmlReader instances created over embedded /// resources. See the remarks section below for some useful information. /// </summary> /// <param name="xmlReaders">A list of XmlReader instances</param> /// <param name="dataModelOption">whether this is a entity data model or provider data model</param> /// <param name="providerManifest">provider manifest from which the primitive type definition comes from</param> /// <param name="itemCollection">item collection to add the item after loading</param> /// <param name="computeFilePaths">Indicates whether the method should bother with the file paths; see remarks below</param> /// <remarks> /// In order to accommodate XmlReaders over artifacts embedded as resources in assemblies, the /// notion of a filepath had to be abstracted into a URI. In reality, however, a res:// URI that /// points to an embedded resource does not constitute a valid URI (i.e., one that can be parsed /// by the System.Uri class in the .NET framework). In such cases, we need to supply a list of /// "filepaths" (which includes res:// URIs), instead of having this method create the collection. /// This distinction is made by setting the 'computeFilePaths' flags appropriately. /// </remarks> internal static IList<EdmSchemaError> LoadItems(IEnumerable<XmlReader> xmlReaders, IEnumerable<string> sourceFilePaths, SchemaDataModelOption dataModelOption, DbProviderManifest providerManifest, ItemCollection itemCollection, bool throwOnError) { IList<Schema> schemaCollection = null; // Parse and validate all the schemas - since we support using now, // we need to parse them as a group var errorCollection = SchemaManager.ParseAndValidate(xmlReaders, sourceFilePaths, dataModelOption, providerManifest, out schemaCollection); // Try to initialize the metadata if there are no errors if (MetadataHelper.CheckIfAllErrorsAreWarnings(errorCollection)) { List<EdmSchemaError> errors = LoadItems(providerManifest, schemaCollection, itemCollection); foreach (var error in errors) { errorCollection.Add(error); } } if (!MetadataHelper.CheckIfAllErrorsAreWarnings(errorCollection) && throwOnError) { //Future Enhancement: if there is an error, we throw exception with error and warnings. //Otherwise the user has no clue to know about warnings. throw EntityUtil.InvalidSchemaEncountered(Helper.CombineErrorMessage(errorCollection)); } return errorCollection; }
internal static string ExtractTypeName(SchemaDataModelOption dataModel, string qualifiedTypeName) { Debug.Assert(!string.IsNullOrEmpty(qualifiedTypeName), "qualifiedTypeName parameter is null or empty"); return GetEverythingAfterLastPeriod(qualifiedTypeName); }
public static IList<EdmSchemaError> ParseAndValidate(IEnumerable<XmlReader> xmlReaders, IEnumerable<string> sourceFilePaths, SchemaDataModelOption dataModel, DbProviderManifest providerManifest, out IList<Schema> schemaCollection) { return ParseAndValidate(xmlReaders, sourceFilePaths, dataModel, NoOpAttributeValueNotification, NoOpAttributeValueNotification, delegate(Action<string, ErrorCode, EdmSchemaErrorSeverity> addError) { return providerManifest == null ? MetadataItem.EdmProviderManifest : providerManifest; }, out schemaCollection); }
internal static XmlSchemaSet GetSchemaSet(SchemaDataModelOption dataModel) { return(System.Data.Entity.Core.SchemaObjectModel.Schema.SomSchemaSetHelper._cachedSchemaSets.Evaluate(dataModel)); }