public static IList<EdmSchemaError> LoadProviderManifest( XmlReader xmlReader, string location, bool checkForSystemNamespace, out Schema schema) { IList<Schema> schemaCollection = new List<Schema>(1); DbProviderManifest providerManifest = checkForSystemNamespace ? EdmProviderManifest.Instance : null; var errors = ParseAndValidate( new[] { xmlReader }, new[] { location }, SchemaDataModelOption.ProviderManifestModel, providerManifest, out schemaCollection); // In case of errors, there are no schema in the schema collection if (schemaCollection.Count != 0) { schema = schemaCollection[0]; } else { Debug.Assert(errors.Count != 0, "There must be some error encountered"); schema = null; } return errors; }
/// <summary> /// ctor for a schema function /// </summary> public ModelFunction(Schema parentElement) : base(parentElement) { _isComposable = true; _typeUsageBuilder = new TypeUsageBuilder(this); }
/// <summary> /// Initializes a new instance of the <see cref="SchemaEnumType"/> class. /// </summary> /// <param name="parentElement"> /// Parent element. /// </param> public SchemaEnumType(Schema parentElement) : base(parentElement) { if (Schema.DataModel == SchemaDataModelOption.EntityDataModel) { OtherContent.Add(Schema.SchemaSource); } }
/// <summary> /// /// </summary> /// <param name="parentElement"></param> internal SchemaComplexType(Schema parentElement) : base(parentElement) { if (Schema.DataModel == SchemaDataModelOption.EntityDataModel) { OtherContent.Add(Schema.SchemaSource); } }
/// <summary> /// Construct the LookUp table /// </summary> public AliasResolver(Schema schema) { _definingSchema = schema; // If there is an alias defined for the defining schema, // add it to the look up table if (!string.IsNullOrEmpty(schema.Alias)) { _aliasToNamespaceMap.Add(schema.Alias, schema.Namespace); } }
public ClientApiGenerator(Schema sourceSchema, EdmItemCollection edmItemCollection, EntityClassGenerator generator, List<EdmSchemaError> errors) { Debug.Assert(sourceSchema != null, "sourceSchema is null"); Debug.Assert(edmItemCollection != null, "edmItemCollection is null"); Debug.Assert(generator != null, "generator is null"); Debug.Assert(errors != null, "errors is null"); _edmItemCollection = edmItemCollection; _sourceSchema = sourceSchema; _generator = generator; _errors = errors; _attributeEmitter = new AttributeEmitter(_typeReference); }
internal static void GetElementLocationInfo(System.Data.EntityModel.SchemaObjectModel.Schema schema, string itemIdentity, out int lineNumber, out int linePosition) { System.Data.EntityModel.SchemaObjectModel.SchemaElement element = GetSchemaElement(schema, itemIdentity); if (null != element) { lineNumber = element.LineNumber; linePosition = element.LinePosition; } else { lineNumber = linePosition = -1; } }
/// <summary> /// Construct a Relationship object /// </summary> /// <param name="parent">the parent</param> /// <param name="kind">the kind of relationship</param> public Relationship(Schema parent, RelationshipKind kind) : base(parent) { RelationshipKind = kind; if (Schema.DataModel == SchemaDataModelOption.EntityDataModel) { _isForeignKey = false; OtherContent.Add(Schema.SchemaSource); } else if (Schema.DataModel == SchemaDataModelOption.ProviderDataModel) { _isForeignKey = true; } }
private static System.Data.EntityModel.SchemaObjectModel.SchemaElement GetSchemaElement( System.Data.EntityModel.SchemaObjectModel.Schema schema, string itemIdentity) { List <System.Data.EntityModel.SchemaObjectModel.SchemaType> schemaTypes = schema.SchemaTypes.Where(p => p.Identity == itemIdentity).ToList(); if (null != schemaTypes && schemaTypes.Count > 0) { return((System.Data.EntityModel.SchemaObjectModel.SchemaElement)schemaTypes.First()); } else { return(null); } }
internal static void GetElementLocationInfo(System.Data.EntityModel.SchemaObjectModel.Schema schema, string parentIdentity, string itemIdentity, out int lineNumber, out int linePosition) { lineNumber = linePosition = -1; System.Data.EntityModel.SchemaObjectModel.SchemaElement element = GetSchemaElement(schema, parentIdentity); System.Data.EntityModel.SchemaObjectModel.StructuredType elementWithProperty = element as System.Data.EntityModel.SchemaObjectModel.StructuredType; if (null != elementWithProperty && elementWithProperty.Properties.ContainsKey(itemIdentity)) { lineNumber = elementWithProperty.Properties[itemIdentity].LineNumber; linePosition = elementWithProperty.Properties[itemIdentity].LinePosition; } else if (null != element) { lineNumber = element.LineNumber; linePosition = element.LinePosition; } }
/// <summary> /// /// </summary> /// <param name="schema"></param> /// <param name="reader"></param> /// <param name="name"></param> /// <returns></returns> public static bool GetDottedName(Schema schema, XmlReader reader,out string name) { if (!GetString(schema, reader, out name)) { return false; } return ValidateDottedName(schema, reader, name); }
/// <summary> /// Construct an internal (not from schema) CDM scalar type /// </summary> /// <param name="parentElement">the owning schema</param> /// <param name="typeName">the naem of the type</param> /// <param name="primitiveType">the PrimitiveTypeKind of the type</param> internal ScalarType(Schema parentElement, string typeName, PrimitiveType primitiveType) : base(parentElement) { Name = typeName; _primitiveType = primitiveType; }
/// <summary> /// ctor for a schema function /// </summary> public Function(Schema parentElement) : base(parentElement) { }
internal static bool ValidateDottedName(Schema schema, XmlReader reader, string name) { Debug.Assert(schema != null, "schema parameter is null"); Debug.Assert(reader != null, "reader parameter is null"); Debug.Assert(!string.IsNullOrEmpty(name), "name parameter is null or empty"); Debug.Assert(reader.SchemaInfo.Validity != System.Xml.Schema.XmlSchemaValidity.Invalid, "This method should not be called when the schema is invalid"); if (schema.DataModel == SchemaDataModelOption.EntityDataModel) { // each part of the dotted name needs to be a valid name foreach (string namePart in name.Split('.')) { if (!ValidUndottedName(namePart)) { schema.AddError(ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.InvalidName(name, reader.Name)); return false; } } } return true; }
private static bool CheckIsSameVersion(Schema schemaToBeAdded, IEnumerable<Schema> schemaCollection, List<EdmSchemaError> errorCollection) { if (schemaToBeAdded.SchemaVersion != XmlConstants.UndefinedVersion && schemaCollection.Count() > 0) { if (schemaCollection.Any(s => s.SchemaVersion != XmlConstants.UndefinedVersion && s.SchemaVersion != schemaToBeAdded.SchemaVersion)) { errorCollection.Add( new EdmSchemaError( Strings.CannotLoadDifferentVersionOfSchemaInTheSameItemCollection, (int)ErrorCode.CannotLoadDifferentVersionOfSchemaInTheSameItemCollection, EdmSchemaErrorSeverity.Error)); } } return true; }
/// <summary> /// Add the namespace of the given schema to the namespace lookup table /// </summary> public void AddSchema(Schema schema) { Debug.Assert(schema.DataModel == _dataModel, "DataModel must match"); if (_namespaceLookUpTable.Count == 0 && schema.DataModel != SchemaDataModelOption.ProviderManifestModel) { // Add the primitive type namespace to the namespace look up table if (this.PrimitiveSchema.Namespace != null) { _namespaceLookUpTable.Add(this.PrimitiveSchema.Namespace); } } // Add the namespace to the namespaceLookUpTable. // Its okay to have multiple schemas with the same namespace _namespaceLookUpTable.Add(schema.Namespace); }
public TypeElement(Schema parent) : base(parent) { _primitiveType.NamespaceName = Schema.Namespace; }
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; }
/// <summary> /// /// </summary> /// <param name="schema"></param> /// <param name="reader"></param> /// <param name="value"></param> /// <returns></returns> public static bool GetBool(Schema schema, XmlReader reader, out bool value) { Debug.Assert(schema != null, "schema parameter is null"); Debug.Assert(reader != null, "reader parameter is null"); if ( reader.SchemaInfo.Validity == System.Xml.Schema.XmlSchemaValidity.Invalid ) { value = true; // we have to set the value to something before returning. return false; } // do this in a try catch, just in case the attribute wasn't validated against an xsd:boolean try { value = reader.ReadContentAsBoolean(); return true; } catch (System.Xml.XmlException) { // we already handled the valid and invalid cases, so it must be NotKnown now. Debug.Assert(reader.SchemaInfo.Validity == Xml.Schema.XmlSchemaValidity.NotKnown, "The schema validity must be NotKnown at this point"); schema.AddError(ErrorCode.BoolValueExpected, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.ValueNotUnderstood(reader.Value, reader.Name)); } value = true; // we have to set the value to something before returning. return false; }
/// <summary> /// /// </summary> /// <param name="schema"></param> /// <param name="reader"></param> /// <param name="name"></param> /// <returns></returns> public static bool GetUndottedName(Schema schema,XmlReader reader,out string name) { Debug.Assert(schema != null, "schema parameter is null"); Debug.Assert(reader != null, "reader parameter is null"); if (reader.SchemaInfo.Validity == System.Xml.Schema.XmlSchemaValidity.Invalid) { // the xsd already put in an error name = null; return false; } name = reader.Value; if (string.IsNullOrEmpty(name)) { schema.AddError( ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.EmptyName(reader.Name)); return false; } if (schema.DataModel == SchemaDataModelOption.EntityDataModel && !ValidUndottedName(name) ) { schema.AddError( ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.InvalidName(name,reader.Name)); return false; } Debug.Assert(!(schema.DataModel == SchemaDataModelOption.EntityDataModel && name.IndexOf('.') >= 0), string.Format(CultureInfo.CurrentCulture, "{1} ({0}) is not valid. {1} cannot be qualified.", name, reader.Name)); return true; }
/// <summary> /// /// </summary> /// <param name="parentElement"></param> protected StructuredType(Schema parentElement) : base(parentElement) { }
public static bool GetInt(Schema schema, XmlReader reader, out int value) { Debug.Assert(schema != null, "schema parameter is null"); Debug.Assert(reader != null, "reader parameter is null"); if (reader.SchemaInfo.Validity == XmlSchemaValidity.Invalid) { // an error has already been issued by the xsd validation value = 0; ; return false; } var text = reader.Value; value = int.MinValue; if (int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out value)) { return true; } schema.AddError( ErrorCode.IntegerExpected, EdmSchemaErrorSeverity.Error, reader, Strings.ValueNotUnderstood(reader.Value, reader.Name)); return false; }
public static bool GetByte(Schema schema,XmlReader reader,out byte value) { Debug.Assert(schema != null, "schema parameter is null"); Debug.Assert(reader != null, "reader parameter is null"); if (reader.SchemaInfo.Validity == System.Xml.Schema.XmlSchemaValidity.Invalid) { // an error has already been issued by the xsd validation value = 0; ; return false; } string text = reader.Value; value = byte.MinValue; if (byte.TryParse(text, NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out value)) { return true; } schema.AddError( ErrorCode.ByteValueExpected, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.ValueNotUnderstood(reader.Value, reader.Name)); return false; }
/// <summary> /// /// </summary> /// <param name="schema"></param> /// <param name="reader"></param> /// <param name="value"></param> /// <returns></returns> public static bool GetString(Schema schema, XmlReader reader, out string value) { Debug.Assert(schema != null, "schema parameter is null"); Debug.Assert(reader != null, "reader parameter is null"); if (reader.SchemaInfo.Validity == System.Xml.Schema.XmlSchemaValidity.Invalid) { // an error has already been issued by the xsd validation value = null; return false; } value = reader.Value; if ( string.IsNullOrEmpty(value) ) { schema.AddError( ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.InvalidName(value, reader.Name)); return false; } return true; }
/// <summary> /// /// </summary> /// <param name="parentElement"></param> internal UsingElement(Schema parentElement) : base(parentElement) { }
/// <summary> /// Constructs an EntityContainer /// </summary> /// <param name="parentElement">Reference to the schema element.</param> public EntityContainer(Schema parentElement) : base(parentElement) { if(Schema.DataModel == SchemaDataModelOption.EntityDataModel) OtherContent.Add(Schema.SchemaSource); }
/// <summary> /// /// </summary> /// <param name="parentElement"></param> internal SchemaType(Schema parentElement) : base(parentElement) { }