예제 #1
0
        [ResourceConsumption(ResourceScope.Machine)] //Temp file creation, and passing to InternalGenerateCode
        public IList <EdmSchemaError> GenerateCode(XmlReader sourceEdmSchema, TextWriter target, IEnumerable <XmlReader> additionalEdmSchemas, Version targetEntityFrameworkVersion)
        {
            EDesignUtil.CheckArgumentNull(sourceEdmSchema, "sourceEdmSchema");
            EDesignUtil.CheckArgumentNull(additionalEdmSchemas, "additionalEdmSchemas");
            EDesignUtil.CheckArgumentNull(target, "target");
            EDesignUtil.CheckTargetEntityFrameworkVersionArgument(targetEntityFrameworkVersion, "targetEntityFrameworkVersion");

            Version schemaVersion;

            if (!IsValidSchema(sourceEdmSchema, out schemaVersion))
            {
                return(new List <EdmSchemaError>()
                {
                    CreateSourceEdmSchemaNotValidError()
                });
            }

            using (TempFileCollection collection = new TempFileCollection())
            {
                string tempSourceEdmSchemaPath = collection.AddExtension(XmlConstants.CSpaceSchemaExtension);
                SaveXmlReaderToFile(sourceEdmSchema, tempSourceEdmSchemaPath);
                List <string> additionalTempPaths = new List <string>();
                foreach (XmlReader reader in additionalEdmSchemas)
                {
                    string temp = Path.GetTempFileName() + XmlConstants.CSpaceSchemaExtension;
                    SaveXmlReaderToFile(reader, temp);
                    additionalTempPaths.Add(temp);
                    collection.AddFile(temp, false);
                }
                return(InternalGenerateCode(tempSourceEdmSchemaPath, schemaVersion, new LazyTextWriterCreator(target), additionalTempPaths, targetEntityFrameworkVersion));
            }
        }
        /// <summary>
        /// Returns the stream of the XSD corresponding to the frameworkVersion, and dataSpace passed in.
        /// </summary>
        /// <param name="entityFrameworkVersion">The version of the EntityFramework that you want the Schema XSD for.</param>
        /// <param name="dataSpace">The data space of the schem XSD that you want.</param>
        /// <returns>Stream version of the XSD</returns>
        public static Stream GetSchemaXsd(Version entityFrameworkVersion, DataSpace dataSpace)
        {
            EDesignUtil.CheckTargetEntityFrameworkVersionArgument(entityFrameworkVersion, "entityFrameworkVersion");

            string resourceName = null;

            switch (dataSpace)
            {
            case DataSpace.CSpace:
                resourceName = GetEdmSchemaXsdResourceName(entityFrameworkVersion);
                break;

            case DataSpace.CSSpace:
                resourceName = GetMappingSchemaXsdResourceName(entityFrameworkVersion);
                break;

            case DataSpace.SSpace:
                resourceName = GetStoreSchemaXsdResourceName(entityFrameworkVersion);
                break;

            default:
                throw EDesignUtil.Argument("dataSpace");
            }

            Debug.Assert(!string.IsNullOrEmpty(resourceName), "Did you forget to map something new?");

            Assembly dataEntity = typeof(EdmItemCollection).Assembly;

            return(dataEntity.GetManifestResourceStream(resourceName));
        }
예제 #3
0
        [ResourceConsumption(ResourceScope.Machine)] // for InternalGenerateCode method call. But the path is not created in this method.
        public IList <EdmSchemaError> GenerateCode(string sourceEdmSchemaFilePath, string targetPath, Version targetEntityFrameworkVersion)
        {
            EntityUtil.CheckStringArgument(sourceEdmSchemaFilePath, "sourceEdmSchemaFilePath");
            EntityUtil.CheckStringArgument(targetPath, "targetPath");
            EDesignUtil.CheckTargetEntityFrameworkVersionArgument(targetEntityFrameworkVersion, "targetEntityFrameworkVersion");

            return(InternalGenerateCode(sourceEdmSchemaFilePath, new LazyTextWriterCreator(targetPath), null, targetEntityFrameworkVersion));
        }
 /// <summary>
 /// Create an StoreItemCollection with the passed in parameters.
 /// Add any errors caused during the ItemCollection creation
 /// to the error list passed in.
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="readers"></param>
 /// <param name="targetEntityFrameworkVersion"></param>
 /// <param name="errors"></param>
 /// <returns></returns>
 public static StoreItemCollection CreateStoreItemCollection(
     IEnumerable <XmlReader> readers,
     Version targetEntityFrameworkVersion,
     out IList <EdmSchemaError> errors)
 {
     EDesignUtil.CheckTargetEntityFrameworkVersionArgument(targetEntityFrameworkVersion, "targetEntityFrameworkVersion");
     return(CreateStoreItemCollection(readers, out errors));
 }
예제 #5
0
        public IList <EdmSchemaError> GenerateViews(StorageMappingItemCollection mappingCollection, TextWriter outputWriter, Version targetEntityFrameworkVersion)
        {
            EDesignUtil.CheckArgumentNull(mappingCollection, "mappingCollection");
            EDesignUtil.CheckArgumentNull(outputWriter, "outputWriter");

            EDesignUtil.CheckTargetEntityFrameworkVersionArgument(targetEntityFrameworkVersion, "targetEntityFrameworkVersion");
            CheckForCompatibleSchemaAndTarget(mappingCollection, targetEntityFrameworkVersion);

            TextWriter writer;

            return(InternalGenerateViews(mappingCollection, () => outputWriter, out writer));
        }
        public static EdmItemCollection CreateEdmItemCollection(IEnumerable <XmlReader> readers,
                                                                Version targetEntityFrameworkVersion,
                                                                out IList <EdmSchemaError> errors)
        {
            EDesignUtil.CheckTargetEntityFrameworkVersionArgument(targetEntityFrameworkVersion, "targetEntityFrameworkVersion");

            EdmItemCollection edmItemCollection = CreateEdmItemCollection(readers, out errors);

            if (!errors.Any(e => e.Severity == EdmSchemaErrorSeverity.Error))
            {
                ValidateActualVersionAgainstTarget(targetEntityFrameworkVersion, EntityFrameworkVersionsUtil.ConvertToVersion(edmItemCollection.EdmVersion), errors);
            }

            return(edmItemCollection);
        }
예제 #7
0
        public static IList <EdmSchemaError> Validate(StorageMappingItemCollection mappingCollection, Version targetEntityFrameworkVersion)
        {
            EDesignUtil.CheckTargetEntityFrameworkVersionArgument(targetEntityFrameworkVersion, "targetEntityFrameworkVersion");
            CheckForCompatibleSchemaAndTarget(mappingCollection, targetEntityFrameworkVersion);

            // purpose of this API is to validate the mappingCollection, it basically will call GetEntitySetViews

            EDesignUtil.CheckArgumentNull(mappingCollection, "mappingCollection");

            // we need a temp var to to pass it to GetViews (since we will directly invoke GetViews)
            Dictionary <EntitySetBase, string> generatedViews;
            // mappingCollection will be validated and schemaErrors will be returned from GetViews API
            IList <EdmSchemaError> schemaErrors;

            // Validate entity set views.
            GetEntitySetViews(mappingCollection, out schemaErrors, out generatedViews);

            // Validate function imports and their mapping.
            foreach (var containerMapping in mappingCollection.GetItems <StorageEntityContainerMapping>())
            {
                foreach (var functionImport in containerMapping.EdmEntityContainer.FunctionImports)
                {
                    FunctionImportMapping functionImportMapping;
                    if (containerMapping.TryGetFunctionImportMapping(functionImport, out functionImportMapping))
                    {
                        if (functionImport.IsComposableAttribute)
                        {
                            ((FunctionImportMappingComposable)functionImportMapping).ValidateFunctionView(schemaErrors);
                        }
                    }
                    else
                    {
                        schemaErrors.Add(new EdmSchemaError(
                                             Strings.UnmappedFunctionImport(functionImport.Identity),
                                             (int)StorageMappingErrorCode.UnmappedFunctionImport,
                                             EdmSchemaErrorSeverity.Warning));
                    }
                }
            }

            Debug.Assert(schemaErrors != null, "schemaErrors is null");
            return(HandleValidationErrors(schemaErrors));
        }
예제 #8
0
        [ResourceConsumption(ResourceScope.Machine)] // temp file creation, and passing to InternalGenerateCode
        public IList <EdmSchemaError> GenerateCode(XmlReader sourceEdmSchema, TextWriter target, Version targetEntityFrameworkVersion)
        {
            EDesignUtil.CheckArgumentNull(sourceEdmSchema, "sourceEdmSchema");
            EDesignUtil.CheckArgumentNull(target, "target");
            EDesignUtil.CheckTargetEntityFrameworkVersionArgument(targetEntityFrameworkVersion, "targetEntityFrameworkVersion");

            Version schemaVersion;

            if (!IsValidSchema(sourceEdmSchema, out schemaVersion))
            {
                return(new List <EdmSchemaError>()
                {
                    CreateSourceEdmSchemaNotValidError()
                });
            }

            using (TempFileCollection collection = new TempFileCollection())
            {
                string tempSourceEdmSchemaPath = collection.AddExtension(XmlConstants.CSpaceSchemaExtension);
                SaveXmlReaderToFile(sourceEdmSchema, tempSourceEdmSchemaPath);

                return(InternalGenerateCode(tempSourceEdmSchemaPath, schemaVersion, new LazyTextWriterCreator(target), null, targetEntityFrameworkVersion));
            }
        }
        public static StorageMappingItemCollection CreateStorageMappingItemCollection(
            EdmItemCollection edmCollection,
            StoreItemCollection storeCollection,
            IEnumerable <XmlReader> readers,
            Version targetEntityFrameworkVersion,
            out IList <EdmSchemaError> errors)
        {
            EDesignUtil.CheckArgumentNull(edmCollection, "edmCollection");
            EDesignUtil.CheckArgumentNull(storeCollection, "storeCollection");
            EDesignUtil.CheckArgumentNull(readers, "readers");
            EDesignUtil.CheckTargetEntityFrameworkVersionArgument(targetEntityFrameworkVersion, "targetEntityFrameworkVersion");
            if (EntityFrameworkVersionsUtil.ConvertToVersion(edmCollection.EdmVersion) > targetEntityFrameworkVersion)
            {
                throw EDesignUtil.Argument("edmCollection");
            }

            StorageMappingItemCollection storageMappingItemCollection = CreateStorageMappingItemCollection(edmCollection, storeCollection, readers, out errors);

            if (!errors.Any(e => e.Severity == EdmSchemaErrorSeverity.Error))
            {
                ValidateActualVersionAgainstTarget(targetEntityFrameworkVersion, EntityFrameworkVersionsUtil.ConvertToVersion(storageMappingItemCollection.MappingVersion), errors);
            }
            return(storageMappingItemCollection);
        }