Beispiel #1
0
        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);
 }
Beispiel #3
0
 /// <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 SchemaComplexType(Schema parentElement)
     : base(parentElement)
 {
     if (Schema.DataModel
         == SchemaDataModelOption.EntityDataModel)
     {
         OtherContent.Add(Schema.SchemaSource);
     }
 }
Beispiel #5
0
        /// <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;
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="parentElement"></param>
 internal UsingElement(Schema parentElement)
     : base(parentElement)
 {
 }
 /// <summary>
 /// </summary>
 /// <param name="parentElement"> </param>
 protected StructuredType(Schema parentElement)
     : base(parentElement)
 {
 }
Beispiel #9
0
        /// <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);
        }
Beispiel #10
0
 /// <summary>
 ///     ctor for a schema function
 /// </summary>
 public Function(Schema parentElement)
     : base(parentElement)
 {
 }
Beispiel #11
0
        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 != 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 (!ValidUndottedName(namePart))
                    {
                        schema.AddError(
                            ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                            Strings.InvalidName(name, reader.Name));
                        return false;
                    }
                }
            }
            return true;
        }
Beispiel #12
0
        /// <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);
        }
Beispiel #13
0
 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;
 }
Beispiel #14
0
        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];
                }

                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);
                    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;
        }
Beispiel #15
0
 /// <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;
 }
Beispiel #16
0
 public TypeElement(Schema parent)
     : base(parent)
 {
     _primitiveType.NamespaceName = Schema.Namespace;
 }
Beispiel #17
0
        /// <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
                == 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;
        }
Beispiel #18
0
        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
                == 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;
        }
Beispiel #19
0
        /// <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
                == 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;
        }
Beispiel #20
0
        /// <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
                == 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
                &&
                !ValidUndottedName(name))
            {
                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;
        }