Ejemplo n.º 1
0
        // <summary>
        // Load stuff from xml readers - this now includes XmlReader instances created over embedded
        // resources. See the remarks section below for some useful information.
        // </summary>
        // <param name="xmlReaders"> A list of XmlReader instances </param>
        // <param name="dataModelOption"> whether this is a entity data model or provider data model </param>
        // <param name="providerManifest"> provider manifest from which the primitive type definition comes from </param>
        // <param name="itemCollection"> item collection to add the item after loading </param>
        internal static IList <EdmSchemaError> LoadItems(
            IEnumerable <XmlReader> xmlReaders,
            IEnumerable <string> sourceFilePaths,
            SchemaDataModelOption dataModelOption,
            DbProviderManifest providerManifest,
            ItemCollection itemCollection,
            bool throwOnError)
        {
            IList <Schema> schemaCollection = null;

            // Parse and validate all the schemas - since we support using now,
            // we need to parse them as a group
            var errorCollection = SchemaManager.ParseAndValidate(
                xmlReaders, sourceFilePaths,
                dataModelOption, providerManifest, out schemaCollection);

            // Try to initialize the metadata if there are no errors
            if (MetadataHelper.CheckIfAllErrorsAreWarnings(errorCollection))
            {
                var errors = LoadItems(providerManifest, schemaCollection, itemCollection);
                foreach (var error in errors)
                {
                    errorCollection.Add(error);
                }
            }
            if (!MetadataHelper.CheckIfAllErrorsAreWarnings(errorCollection) && throwOnError)
            {
                //Future Enhancement: if there is an error, we throw exception with error and warnings.
                //Otherwise the user has no clue to know about warnings.
                throw EntityUtil.InvalidSchemaEncountered(Helper.CombineErrorMessage(errorCollection));
            }
            return(errorCollection);
        }
Ejemplo n.º 2
0
 internal void ThrowOnNonWarningErrors()
 {
     if (!MetadataHelper.CheckIfAllErrorsAreWarnings(this._errors))
     {
         throw EntityUtil.InvalidSchemaEncountered(Helper.CombineErrorMessage((IEnumerable <EdmSchemaError>) this._errors));
     }
 }
Ejemplo n.º 3
0
 internal void ThrowOnNonWarningErrors()
 {
     if (!MetadataHelper.CheckIfAllErrorsAreWarnings(_errors))
     {
         //Future Enhancement: if there is an error, we throw exception with error and warnings.
         //Otherwise the user has no clue to know about warnings.
         throw EntityUtil.InvalidSchemaEncountered(Helper.CombineErrorMessage(_errors));
     }
 }
Ejemplo n.º 4
0
 private static bool UpdateErrorCollectionAndCheckForMaxErrors(
     List <EdmSchemaError> errorCollection,
     IList <EdmSchemaError> newErrors,
     ref bool errorEncountered)
 {
     if (!errorEncountered && !MetadataHelper.CheckIfAllErrorsAreWarnings(newErrors))
     {
         errorEncountered = true;
     }
     errorCollection.AddRange((IEnumerable <EdmSchemaError>)newErrors);
     return(errorEncountered && errorCollection.Where <EdmSchemaError>((Func <EdmSchemaError, bool>)(e => e.Severity == EdmSchemaErrorSeverity.Error)).Count <EdmSchemaError>() > 100);
 }
        /// <summary>
        /// This helper method loads items based on contents of in-memory XmlReader instances.
        /// Assumption: This method is called only from the constructor because m_extentMappingViews is not thread safe.
        /// </summary>
        /// <param name="xmlReaders">A list of XmlReader instances</param>
        /// <param name="mappingSchemaUris">A list of URIs</param>
        /// <returns>A list of schema errors</returns>
        private List <EdmSchemaError> LoadItems(IEnumerable <XmlReader> xmlReaders,
                                                List <string> mappingSchemaUris,
                                                Dictionary <EntitySetBase, GeneratedView> userDefinedQueryViewsDict,
                                                Dictionary <OfTypeQVCacheKey, GeneratedView> userDefinedQueryViewsOfTypeDict,
                                                double expectedVersion)
        {
            Debug.Assert(m_memberMappings.Count == 0, "Assumption: This method is called only once, and from the constructor because m_extentMappingViews is not thread safe.");

            List <EdmSchemaError> errors = new List <EdmSchemaError>();

            int index = -1;

            foreach (XmlReader xmlReader in xmlReaders)
            {
                index++;
                string location = null;
                if (mappingSchemaUris == null)
                {
                    som.SchemaManager.TryGetBaseUri(xmlReader, out location);
                }
                else
                {
                    location = mappingSchemaUris[index];
                }

                StorageMappingItemLoader mapLoader = new StorageMappingItemLoader(
                    xmlReader,
                    this,
                    location,                                          // ASSUMPTION: location is only used for generating error-messages
                    m_memberMappings);
                errors.AddRange(mapLoader.ParsingErrors);

                CheckIsSameVersion(expectedVersion, mapLoader.MappingVersion, errors);

                // Process container mapping.
                StorageEntityContainerMapping containerMapping = mapLoader.ContainerMapping;
                if (mapLoader.HasQueryViews && containerMapping != null)
                {
                    // Compile the query views so that we can report the errors in the user specified views.
                    CompileUserDefinedQueryViews(containerMapping, userDefinedQueryViewsDict, userDefinedQueryViewsOfTypeDict, errors);
                }
                // Add container mapping if there are no errors and entity container mapping is not already present.
                if (MetadataHelper.CheckIfAllErrorsAreWarnings(errors) && !this.Contains(containerMapping))
                {
                    AddInternal(containerMapping);
                }
            }

            CheckForDuplicateItems(EdmItemCollection, StoreItemCollection, errors);

            return(errors);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add the given list of newErrors to the error collection. If there is a error in the new errors,
        /// it sets the errorEncountered to true. Returns true if the number of errors encountered is more
        /// than max errors
        /// </summary>
        /// <returns></returns>
        private static bool UpdateErrorCollectionAndCheckForMaxErrors(List <EdmSchemaError> errorCollection,
                                                                      IList <EdmSchemaError> newErrors, ref bool errorEncountered)
        {
            // If we have encountered error already in one of the schemas, then we don't need to check for errors in the remaining schemas.
            // Just keep aggregating the errors and throw them at the end.
            if (!errorEncountered)
            {
                if (!MetadataHelper.CheckIfAllErrorsAreWarnings(newErrors))
                {
                    errorEncountered = true;
                }
            }

            // Add the new errors to the error collection
            errorCollection.AddRange(newErrors);

            if (errorEncountered &&
                errorCollection.Where(e => e.Severity == EdmSchemaErrorSeverity.Error).Count() > MaxErrorCount)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        internal static IList <EdmSchemaError> LoadItems(
            IEnumerable <XmlReader> xmlReaders,
            IEnumerable <string> sourceFilePaths,
            SchemaDataModelOption dataModelOption,
            DbProviderManifest providerManifest,
            ItemCollection itemCollection,
            bool throwOnError)
        {
            IList <Schema>         schemaCollection = (IList <Schema>)null;
            IList <EdmSchemaError> andValidate      = SchemaManager.ParseAndValidate(xmlReaders, sourceFilePaths, dataModelOption, providerManifest, out schemaCollection);

            if (MetadataHelper.CheckIfAllErrorsAreWarnings(andValidate))
            {
                foreach (EdmSchemaError loadItem in EdmItemCollection.LoadItems(providerManifest, schemaCollection, itemCollection))
                {
                    andValidate.Add(loadItem);
                }
            }
            if (!MetadataHelper.CheckIfAllErrorsAreWarnings(andValidate) && throwOnError)
            {
                throw EntityUtil.InvalidSchemaEncountered(Helper.CombineErrorMessage((IEnumerable <EdmSchemaError>)andValidate));
            }
            return(andValidate);
        }