Esempio n. 1
0
 private SchemaManager(SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded)
 {
     _dataModel            = dataModel;
     _providerNotification = providerNotification;
     _providerManifestTokenNotification = providerManifestTokenNotification;
     _providerManifestNeeded            = providerManifestNeeded;
 }
 private SchemaManager(SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded)
 {
     _dataModel = dataModel;
     _providerNotification = providerNotification;
     _providerManifestTokenNotification = providerManifestTokenNotification;
     _providerManifestNeeded = providerManifestNeeded;
 }
Esempio n. 3
0
        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);
            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;
        }
Esempio n. 5
0
        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);
        }