Exemplo n.º 1
0
        private void GenerateCodeCommon(MetadataArtifactLoader sourceLoader,
                                        List <MetadataArtifactLoader> loaders,
                                        LazyTextWriterCreator target,
                                        string sourceEdmSchemaFilePath,
                                        string targetFilePath,
                                        bool closeReaders,
                                        List <EdmSchemaError> errors)
        {
            MetadataArtifactLoaderComposite composite = new MetadataArtifactLoaderComposite(loaders);

            // create the schema manager from the xml readers
            Dictionary <MetadataArtifactLoader, XmlReader> readerSourceMap = new Dictionary <MetadataArtifactLoader, XmlReader>();
            IList <Schema>   schemas;
            List <XmlReader> readers = composite.GetReaders(readerSourceMap);

            try
            {
                IList <EdmSchemaError> schemaManagerErrors =
                    SchemaManager.ParseAndValidate(readers,
                                                   composite.GetPaths(),
                                                   SchemaDataModelOption.EntityDataModel,
                                                   EdmProviderManifest.Instance,
                                                   out schemas);
                errors.AddRange(schemaManagerErrors);
            }
            finally
            {
                if (closeReaders)
                {
                    MetadataUtil.DisposeXmlReaders(readers);
                }
            }
            ThrowOnAnyNonWarningErrors(errors);
            Debug.Assert(readerSourceMap.ContainsKey(sourceLoader), "the source loader didn't produce any of the xml readers...");
            XmlReader sourceReader = readerSourceMap[sourceLoader];


            // use the index of the "source" xml reader as the index of the "source" schema
            Debug.Assert(readers.Contains(sourceReader), "the source reader is not in the list of readers");
            int index = readers.IndexOf(sourceReader);

            Debug.Assert(index >= 0, "couldn't find the source reader in the list of readers");

            Debug.Assert(readers.Count == schemas.Count, "We have a different number of readers than schemas");
            Schema sourceSchema = schemas[index];

            Debug.Assert(sourceSchema != null, "sourceSchema is null");

            // create the EdmItemCollection from the schemas
            EdmItemCollection itemCollection = new EdmItemCollection(schemas);

            if (EntityFrameworkVersionsUtil.ConvertToVersion(itemCollection.EdmVersion) >= EntityFrameworkVersions.Version2)
            {
                throw EDesignUtil.InvalidOperation(Strings.TargetEntityFrameworkVersionToNewForEntityClassGenerator);
            }

            // generate code
            ClientApiGenerator generator = new ClientApiGenerator(sourceSchema, itemCollection, this, errors);

            generator.GenerateCode(target, targetFilePath);
        }
Exemplo n.º 2
0
        private void GenerateCodeCommon(MetadataArtifactLoader sourceLoader, 
            List<MetadataArtifactLoader> loaders,
            LazyTextWriterCreator target,
            string sourceEdmSchemaFilePath,
            string targetFilePath,
            bool closeReaders,
            List<EdmSchemaError> errors)
        {
            MetadataArtifactLoaderComposite composite = new MetadataArtifactLoaderComposite(loaders);
            
            // create the schema manager from the xml readers
            Dictionary<MetadataArtifactLoader, XmlReader> readerSourceMap = new Dictionary<MetadataArtifactLoader, XmlReader>();
            IList<Schema> schemas;
            List<XmlReader> readers = composite.GetReaders(readerSourceMap);

            try
            {
                IList<EdmSchemaError> schemaManagerErrors =
                    SchemaManager.ParseAndValidate(readers,
                        composite.GetPaths(),
                        SchemaDataModelOption.EntityDataModel,
                        EdmProviderManifest.Instance,
                        out schemas);
                errors.AddRange(schemaManagerErrors);
            }
            finally
            {
                if (closeReaders)
                {
                    MetadataUtil.DisposeXmlReaders(readers);
                }
            }
            ThrowOnAnyNonWarningErrors(errors);
            Debug.Assert(readerSourceMap.ContainsKey(sourceLoader), "the source loader didn't produce any of the xml readers...");
            XmlReader sourceReader = readerSourceMap[sourceLoader];


            // use the index of the "source" xml reader as the index of the "source" schema
            Debug.Assert(readers.Contains(sourceReader), "the source reader is not in the list of readers");
            int index = readers.IndexOf(sourceReader);
            Debug.Assert(index >= 0, "couldn't find the source reader in the list of readers");

            Debug.Assert(readers.Count == schemas.Count, "We have a different number of readers than schemas");
            Schema sourceSchema = schemas[index];
            Debug.Assert(sourceSchema != null, "sourceSchema is null");

            // create the EdmItemCollection from the schemas
            EdmItemCollection itemCollection = new EdmItemCollection(schemas);
            if (EntityFrameworkVersionsUtil.ConvertToVersion(itemCollection.EdmVersion) >= EntityFrameworkVersions.Version2)
            {
                throw EDesignUtil.InvalidOperation(Strings.TargetEntityFrameworkVersionToNewForEntityClassGenerator);  
            }

            // generate code
            ClientApiGenerator generator = new ClientApiGenerator(sourceSchema, itemCollection, this, errors);
            generator.GenerateCode(target, targetFilePath);
        }