public PrimitiveSchema(SchemaManager schemaManager) : base(schemaManager) { Schema = this; var providerManifest = ProviderManifest; if (providerManifest == null) { AddError( new EdmSchemaError( Strings.FailedToRetrieveProviderManifest, (int)ErrorCode.FailedToRetrieveProviderManifest, EdmSchemaErrorSeverity.Error)); } else { IList<PrimitiveType> primitiveTypes = providerManifest.GetStoreTypes(); // EDM Spatial types are only available to V3 and above CSDL. if (schemaManager.DataModel == SchemaDataModelOption.EntityDataModel && schemaManager.SchemaVersion < XmlConstants.EdmVersionForV3) { primitiveTypes = primitiveTypes.Where(t => !Helper.IsSpatialType(t)) .ToList(); } foreach (var entry in primitiveTypes) { TryAddType(new ScalarType(this, entry.Name, entry), false /*doNotAddErrorForEmptyName*/); } } }
public Schema(SchemaManager schemaManager) : base(null) { DebugCheck.NotNull(schemaManager); _schemaManager = schemaManager; _errors = new List<EdmSchemaError>(); }
public static IList <EdmSchemaError> LoadProviderManifest( XmlReader xmlReader, string location, bool checkForSystemNamespace, out Schema schema) { IList <Schema> schemaCollection = (IList <Schema>) new List <Schema>(1); DbProviderManifest providerManifest = checkForSystemNamespace ? (DbProviderManifest)EdmProviderManifest.Instance : (DbProviderManifest)null; IList <EdmSchemaError> andValidate = SchemaManager.ParseAndValidate((IEnumerable <XmlReader>) new XmlReader[1] { xmlReader }, (IEnumerable <string>) new string[1] { location }, SchemaDataModelOption.ProviderManifestModel, providerManifest, out schemaCollection); schema = schemaCollection.Count == 0 ? (Schema)null : schemaCollection[0]; return(andValidate); }
internal static bool TryGetSchemaVersion( XmlReader reader, out double version, out DataSpace dataSpace) { if (!reader.EOF && reader.NodeType != XmlNodeType.Element) { while (reader.Read() && reader.NodeType != XmlNodeType.Element) { ; } } if (!reader.EOF && (reader.LocalName == "Schema" || reader.LocalName == "Mapping")) { return(SchemaManager.TryGetSchemaVersion(reader.NamespaceURI, out version, out dataSpace)); } version = 0.0; dataSpace = DataSpace.OSpace; return(false); }
public PrimitiveSchema(SchemaManager schemaManager) : base(schemaManager) { this.Schema = (Schema)this; DbProviderManifest providerManifest = this.ProviderManifest; if (providerManifest == null) { this.AddError(new EdmSchemaError(Strings.FailedToRetrieveProviderManifest, 168, EdmSchemaErrorSeverity.Error)); } else { IList <PrimitiveType> source = (IList <PrimitiveType>)providerManifest.GetStoreTypes(); if (schemaManager.DataModel == SchemaDataModelOption.EntityDataModel && schemaManager.SchemaVersion < 3.0) { source = (IList <PrimitiveType>)source.Where <PrimitiveType>((Func <PrimitiveType, bool>)(t => !Helper.IsSpatialType(t))).ToList <PrimitiveType>(); } foreach (PrimitiveType primitiveType in (IEnumerable <PrimitiveType>)source) { this.TryAddType((SchemaType) new ScalarType((Schema)this, primitiveType.Name, primitiveType), false); } } }
public Schema(SchemaManager schemaManager) : base((SchemaElement)null, (IDbDependencyResolver)null) { this._schemaManager = schemaManager; this._errors = new List <EdmSchemaError>(); }
public static IList <EdmSchemaError> ParseAndValidate( IEnumerable <XmlReader> xmlReaders, IEnumerable <string> sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, out IList <Schema> schemaCollection) { var schemaManager = new SchemaManager( dataModel, providerNotification, providerManifestTokenNotification, providerManifestNeeded); var errorCollection = new List <EdmSchemaError>(); schemaCollection = new List <Schema>(); var errorEncountered = false; List <string> filePathList; if (sourceFilePaths != null) { filePathList = new List <string>(sourceFilePaths); } else { filePathList = new List <string>(); } var index = 0; foreach (var xmlReader in xmlReaders) { string location = null; if (filePathList.Count <= index) { TryGetBaseUri(xmlReader, out location); } else { location = filePathList[index]; } var 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); Debug.Assert( schemaCollection.All( s => s.SchemaVersion == schema.SchemaVersion || 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 (var 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 (var schema in schemaCollection) { if (UpdateErrorCollectionAndCheckForMaxErrors(errorCollection, schema.ValidateSchema(), ref errorEncountered)) { return(errorCollection); } } } } return(errorCollection); }
// <summary> // Look up a fully qualified type name reference. // </summary> // <param name="usingElement"> element containing the reference </param> // <param name="typeName"> the fully qualified type name </param> // <param name="type"> the referenced schema type </param> // <returns> false if there was an error </returns> internal bool ResolveTypeName(SchemaElement usingElement, string typeName, out SchemaType type) { DebugCheck.NotNull(usingElement); DebugCheck.NotNull(typeName); type = null; // get the schema(s) that match the namespace/alias string actualQualification; string unqualifiedTypeName; Utils.ExtractNamespaceAndName(typeName, out actualQualification, out unqualifiedTypeName); var definingQualification = actualQualification; if (definingQualification == null) { definingQualification = ProviderManifest == null ? _namespaceName : ProviderManifest.NamespaceName; } string namespaceName; // First check if there is an alias defined by this name. For primitive type namespace, we do not need to resolve // any alias, since that's a reserved keyword and we don't allow alias with that name if (actualQualification == null || !AliasResolver.TryResolveAlias(definingQualification, out namespaceName)) { namespaceName = definingQualification; } // Resolve the type name if (!SchemaManager.TryResolveType(namespaceName, unqualifiedTypeName, out type)) { // it must be an undefined type. if (actualQualification == null) { // Every type except the primitive type must be qualified usingElement.AddError(ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, Strings.NotNamespaceQualified(typeName)); } else if (!SchemaManager.IsValidNamespaceName(namespaceName)) { usingElement.AddError( ErrorCode.BadNamespace, EdmSchemaErrorSeverity.Error, Strings.BadNamespaceOrAlias(actualQualification)); } else { // if the type name was alias qualified if (namespaceName != definingQualification) { usingElement.AddError( ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, Strings.NotInNamespaceAlias(unqualifiedTypeName, namespaceName, definingQualification)); } else { usingElement.AddError( ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, Strings.NotInNamespaceNoAlias(unqualifiedTypeName, namespaceName)); } } return(false); } // For ssdl and provider manifest, make sure that the type is present in this schema or primitive schema else if (DataModel != SchemaDataModelOption.EntityDataModel && type.Schema != this && type.Schema != SchemaManager.PrimitiveSchema) { Debug.Assert(type.Namespace != Namespace, "Using element is not allowed in the schema of ssdl and provider manifest"); usingElement.AddError( ErrorCode.InvalidNamespaceOrAliasSpecified, EdmSchemaErrorSeverity.Error, Strings.InvalidNamespaceOrAliasSpecified(actualQualification)); return(false); } return(true); }
public static IList<EdmSchemaError> ParseAndValidate( IEnumerable<XmlReader> xmlReaders, IEnumerable<string> sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, out IList<Schema> schemaCollection) { var schemaManager = new SchemaManager( dataModel, providerNotification, providerManifestTokenNotification, providerManifestNeeded); var errorCollection = new List<EdmSchemaError>(); schemaCollection = new List<Schema>(); var errorEncountered = false; List<string> filePathList; if (sourceFilePaths != null) { filePathList = new List<string>(sourceFilePaths); } else { filePathList = new List<string>(); } var index = 0; foreach (var xmlReader in xmlReaders) { string location = null; if (filePathList.Count <= index) { TryGetBaseUri(xmlReader, out location); } else { location = filePathList[index]; } var 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); Debug.Assert( schemaCollection.All( s => s.SchemaVersion == schema.SchemaVersion || 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 (var 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 (var 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); }