/// <summary> /// ctor for a schema function /// </summary> public ModelFunction(Schema parentElement) : base(parentElement) { _isComposable = true; _typeUsageBuilder = new TypeUsageBuilder(this); }
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> /// </summary> /// <param name="parentElement"> </param> internal SchemaComplexType(Schema parentElement) : base(parentElement) { if (Schema.DataModel == SchemaDataModelOption.EntityDataModel) { OtherContent.Add(Schema.SchemaSource); } }
// <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> /// 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); } }
/// <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; } }
public static bool GetString(Schema schema, XmlReader reader, out string value) { DebugCheck.NotNull(schema); DebugCheck.NotNull(reader); if (reader.SchemaInfo.Validity == 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, Strings.InvalidName(value, reader.Name)); return false; } return true; }
// <summary> // ctor for a schema function // </summary> public Function(Schema parentElement) : base(parentElement) { }
public static bool GetDottedName(Schema schema, XmlReader reader, out string name) { if (!GetString(schema, reader, out name)) { return false; } return ValidateDottedName(schema, reader, name); }
public static bool GetByte(Schema schema, XmlReader reader, out byte value) { DebugCheck.NotNull(schema); DebugCheck.NotNull(reader); 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 = byte.MinValue; if (byte.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out value)) { return true; } schema.AddError( ErrorCode.ByteValueExpected, EdmSchemaErrorSeverity.Error, reader, Strings.ValueNotUnderstood(reader.Value, reader.Name)); return false; }
private static void ConvertSchema( Schema somSchema, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<SchemaElement, GlobalItem> newGlobalItems) { var funcsWithUnresolvedTypes = new List<Function>(); foreach (var element in somSchema.SchemaTypes) { if (null == LoadSchemaElement(element, providerManifest, convertedItemCache, newGlobalItems)) { var function = element as Function; if (function != null) { funcsWithUnresolvedTypes.Add(function); } } } foreach (var element in somSchema.SchemaTypes.OfType<SchemaEntityType>()) { LoadEntityTypePhase2(element, providerManifest, convertedItemCache, newGlobalItems); } foreach (var function in funcsWithUnresolvedTypes) { if (null == LoadSchemaElement(function, providerManifest, convertedItemCache, newGlobalItems)) { Debug.Fail("Could not load model function definition"); //this should never happen. } } if (convertedItemCache.ItemCollection.DataSpace == DataSpace.CSpace) { var edmCollection = (EdmItemCollection)convertedItemCache.ItemCollection; edmCollection.EdmVersion = somSchema.SchemaVersion; } else { Debug.Assert(convertedItemCache.ItemCollection.DataSpace == DataSpace.SSpace, "Did you add a new space?"); // when converting the ProviderManifest, the DataSpace is SSpace, but the ItemCollection is EmptyItemCollection, // not StoreItemCollection var storeCollection = convertedItemCache.ItemCollection as StoreItemCollection; if (storeCollection != null) { storeCollection.StoreSchemaVersion = somSchema.SchemaVersion; } } }
/// <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> /// </summary> /// <param name="parentElement"> </param> protected StructuredType(Schema parentElement) : base(parentElement) { }
/// <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 (PrimitiveSchema.Namespace != null) { _namespaceLookUpTable.Add(PrimitiveSchema.Namespace); } } // Add the namespace to the namespaceLookUpTable. // Its okay to have multiple schemas with the same namespace _namespaceLookUpTable.Add(schema.Namespace); }
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; }
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> /// Converts a schema from SOM into Metadata /// </summary> /// <param name="somSchema"> The SOM schema to convert </param> /// <param name="providerManifest"> The provider manifest to be used for conversion </param> /// <param name="itemCollection"> The item collection for currently existing metadata objects </param> internal static IEnumerable<GlobalItem> ConvertSchema( Schema somSchema, DbProviderManifest providerManifest, ItemCollection itemCollection) { var newGlobalItems = new Dictionary<SchemaElement, GlobalItem>(); ConvertSchema(somSchema, providerManifest, new ConversionCache(itemCollection), newGlobalItems); return newGlobalItems.Values; }
public TypeElement(Schema parent) : base(parent) { _primitiveType.NamespaceName = Schema.Namespace; }
internal static bool ValidateDottedName(Schema schema, XmlReader reader, string name) { DebugCheck.NotNull(schema); DebugCheck.NotNull(reader); DebugCheck.NotEmpty(name); Debug.Assert( reader.SchemaInfo.Validity != 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 (var namePart in name.Split('.')) { if (!namePart.IsValidUndottedName()) { schema.AddError( ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader, Strings.InvalidName(name, reader.Name)); return false; } } } return true; }
public static bool GetUndottedName(Schema schema, XmlReader reader, out string name) { DebugCheck.NotNull(schema); DebugCheck.NotNull(reader); if (reader.SchemaInfo.Validity == 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, Strings.EmptyName(reader.Name)); return false; } if (schema.DataModel == SchemaDataModelOption.EntityDataModel && !name.IsValidUndottedName()) { schema.AddError( ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader, 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; }
public static bool GetBool(Schema schema, XmlReader reader, out bool value) { DebugCheck.NotNull(schema); DebugCheck.NotNull(reader); if (reader.SchemaInfo.Validity == 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 (XmlException) { // we already handled the valid and invalid cases, so it must be NotKnown now. Debug.Assert(reader.SchemaInfo.Validity == XmlSchemaValidity.NotKnown, "The schema validity must be NotKnown at this point"); schema.AddError( ErrorCode.BoolValueExpected, EdmSchemaErrorSeverity.Error, reader, Strings.ValueNotUnderstood(reader.Value, reader.Name)); } value = true; // we have to set the value to something before returning. return false; }
/// <summary> /// </summary> /// <param name="parentElement"> </param> internal UsingElement(Schema parentElement) : base(parentElement) { }