コード例 #1
0
        /// <summary>
        /// Extract the CSDL, SSDL and MSL nodes from the EDMX file and store them
        /// as embedded resources
        /// </summary>
        /// <param name="assemblyBuilder"></param>
        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
            using (StreamReader edmxInputStream = new StreamReader(VirtualPathProvider.OpenFile(base.VirtualPath)))
            {
                // load up an XML document representing the edmx file
                XmlElement conceptualSchemaElement;
                XmlElement mappingElement;
                XmlElement storageSchemaElement;
                string     embedAsResourcePropertyValue;
                EntityDesignerUtils.ExtractConceptualMappingAndStorageNodes(edmxInputStream, out conceptualSchemaElement, out mappingElement, out storageSchemaElement, out embedAsResourcePropertyValue);

                if (null == conceptualSchemaElement)
                {
                    throw new XmlException("No Conceptual Schema node to embed as a resource", null, 0, 0);
                }

                if (null == storageSchemaElement)
                {
                    throw new XmlException("No Storage Schema node to embed as a resource", null, 0, 0);
                }

                if (null == mappingElement)
                {
                    throw new XmlException("No Mapping node to embed as a resource", null, 0, 0);
                }

                // construct output paths where the CSDL/MSL/SSDL resources will be placed
                string virtualPathPrefix = base.VirtualPath.Replace(EntityDesignerUtils._edmxFileExtension, String.Empty);
                string csdlResourceName  = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPathPrefix + XmlConstants.CSpaceSchemaExtension);
                string ssdlResourceName  = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPathPrefix + XmlConstants.SSpaceSchemaExtension);
                string mslResourceName   = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPathPrefix + XmlConstants.CSSpaceSchemaExtension);

                SetupEmbeddedResource(assemblyBuilder, this, conceptualSchemaElement, csdlResourceName);
                SetupEmbeddedResource(assemblyBuilder, this, storageSchemaElement, ssdlResourceName);
                SetupEmbeddedResource(assemblyBuilder, this, mappingElement, mslResourceName);
            }
        }
コード例 #2
0
ファイル: EntityDeploy.cs プロジェクト: mmitche/ef6
        // returns true if finished successfully
        private bool OutputFiles(DirectoryInfo topLevelOutputDir)
        {
            bool allFilesOutputSuccessfully = true;

            // Loop over all EDMX files passed in as Sources
            Log.LogMessage(string.Format(CultureInfo.CurrentCulture, Resources.ProcessingEdmxFiles, Sources.Length));
            for (int i = 0; i < Sources.Length; i++)
            {
                string inputFileRelativePath = Sources[i].ItemSpec;
                try
                {
                    FileInfo edmxFile = new FileInfo(inputFileRelativePath);

                    if (!edmxFile.Extension.Equals(XmlConstants.EdmxFileExtension, StringComparison.CurrentCultureIgnoreCase))
                    {
                        Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorNotAnEdmxFile, edmxFile.Name));
                        continue;
                    }

                    Log.LogMessage(string.Format(CultureInfo.CurrentCulture, Resources.StartingProcessingFile, inputFileRelativePath));

                    // Find the C/M/S nodes within the EDMX file and check for errors
                    using (StreamReader edmxInputStream = new StreamReader(edmxFile.FullName))
                    {
                        XmlElement conceptualSchemaElement;
                        XmlElement mappingElement;
                        XmlElement storageSchemaElement;
                        string     metadataArtifactProcessingValue;
                        EntityDesignerUtils.ExtractConceptualMappingAndStorageNodes(
                            edmxInputStream, out conceptualSchemaElement, out mappingElement, out storageSchemaElement, out metadataArtifactProcessingValue);

                        bool produceOutput = true;
                        if (null == conceptualSchemaElement)
                        {
                            Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.CouldNotFindConceptualSchema, edmxFile.FullName));
                            produceOutput = false;
                            allFilesOutputSuccessfully = false;
                        }

                        if (null == storageSchemaElement)
                        {
                            Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.CouldNotFindStorageSchema, edmxFile.FullName));
                            produceOutput = false;
                            allFilesOutputSuccessfully = false;
                        }

                        if (null == mappingElement)
                        {
                            Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.CouldNotFindMapping, edmxFile.FullName));
                            produceOutput = false;
                            allFilesOutputSuccessfully = false;
                        }

                        // Output the set of C/M/S files corresponding to this EDMX file
                        if (produceOutput)
                        {
                            // if the given edmx file is a link we should output the files using
                            // the directory relative to the link rather than to the original file
                            string inputFileRelativePathFromMetadata = EntityDeploySplit.EntityDeployMetadataRelativePath(Sources[i]);
                            if (!OutputCMS(inputFileRelativePathFromMetadata, topLevelOutputDir, conceptualSchemaElement, mappingElement, storageSchemaElement))
                            {
                                allFilesOutputSuccessfully = false;
                            }
                        }
                    }
                }
                catch (ArgumentException ae)
                {
                    Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, inputFileRelativePath));
                    Log.LogErrorFromException(ae, false);
                    allFilesOutputSuccessfully = false;
                }
                catch (IOException ioe)
                {
                    Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, inputFileRelativePath));
                    Log.LogErrorFromException(ioe, false);
                    allFilesOutputSuccessfully = false;
                }
                catch (SecurityException se)
                {
                    Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, inputFileRelativePath));
                    Log.LogErrorFromException(se, false);
                    allFilesOutputSuccessfully = false;
                }
                catch (NotSupportedException nse)
                {
                    Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, inputFileRelativePath));
                    Log.LogErrorFromException(nse, false);
                    allFilesOutputSuccessfully = false;
                }
                catch (UnauthorizedAccessException uae)
                {
                    Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, inputFileRelativePath));
                    Log.LogErrorFromException(uae, false);
                    allFilesOutputSuccessfully = false;
                }
                catch (XmlException xe)
                {
                    Log.LogError(String.Empty,
                                 String.Empty,
                                 String.Empty,
                                 inputFileRelativePath,
                                 xe.LineNumber,
                                 xe.LinePosition,
                                 xe.LineNumber,
                                 xe.LinePosition,
                                 xe.Message);
                    allFilesOutputSuccessfully = false;
                }

                Log.LogMessage(string.Format(CultureInfo.CurrentCulture, Resources.FinishedProcessingFile, inputFileRelativePath));
            }

            Log.LogMessage(string.Format(CultureInfo.CurrentCulture, Resources.FinishedProcessingEdmxFiles, Sources.Length));
            return(allFilesOutputSuccessfully);
        }
コード例 #3
0
        // Task returns true if finishes successfully
        public override bool Execute()
        {
            List <ITaskItem> embeddedEdmxItems    = new List <ITaskItem>();
            List <ITaskItem> nonEmbeddedEdmxItems = new List <ITaskItem>();

            // Loop over all EDMX files passed in as Sources
            for (int i = 0; i < Sources.Length; i++)
            {
                ITaskItem currentSource         = Sources[i];
                string    inputFileRelativePath = currentSource.ItemSpec;
                try
                {
                    FileInfo edmxFile = new FileInfo(inputFileRelativePath);

                    if (!edmxFile.Extension.Equals(XmlConstants.EdmxFileExtension, StringComparison.CurrentCultureIgnoreCase))
                    {
                        Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorNotAnEdmxFile, edmxFile.Name));
                        continue;
                    }

                    // Using the metadataArtifactProcessingValue split up TaskItems
                    using (StreamReader edmxInputStream = new StreamReader(edmxFile.FullName))
                    {
                        XmlElement conceptualSchemaElement;
                        XmlElement mappingElement;
                        XmlElement storageSchemaElement;
                        string     metadataArtifactProcessingValue;
                        EntityDesignerUtils.ExtractConceptualMappingAndStorageNodes(
                            edmxInputStream, out conceptualSchemaElement, out mappingElement, out storageSchemaElement, out metadataArtifactProcessingValue);

                        // set up the EntityDeployRelativeDir metadata on the output item
                        // so that the metadata can be used to determine the correct output
                        // path independent on whether the input file is a link or not
                        AssignMetadata(currentSource);

                        // add to the appropriate output item list
                        if ("EmbedInOutputAssembly".Equals(metadataArtifactProcessingValue, StringComparison.OrdinalIgnoreCase))
                        {
                            embeddedEdmxItems.Add(currentSource);
                        }
                        else
                        {
                            nonEmbeddedEdmxItems.Add(currentSource);
                        }
                    }
                }
                catch (ArgumentException ae)
                {
                    Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, inputFileRelativePath));
                    Log.LogErrorFromException(ae, false);
                }
                catch (IOException ioe)
                {
                    Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, inputFileRelativePath));
                    Log.LogErrorFromException(ioe, false);
                }
                catch (SecurityException se)
                {
                    Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, inputFileRelativePath));
                    Log.LogErrorFromException(se, false);
                }
                catch (NotSupportedException nse)
                {
                    Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, inputFileRelativePath));
                    Log.LogErrorFromException(nse, false);
                }
                catch (UnauthorizedAccessException uae)
                {
                    Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, inputFileRelativePath));
                    Log.LogErrorFromException(uae, false);
                }
                catch (XmlException xe)
                {
                    Log.LogError(String.Empty,
                                 String.Empty,
                                 String.Empty,
                                 inputFileRelativePath,
                                 xe.LineNumber,
                                 xe.LinePosition,
                                 xe.LineNumber,
                                 xe.LinePosition,
                                 xe.Message);
                }
            }

            // set output parameters
            _edmxItemsToBeEmbedded    = embeddedEdmxItems.ToArray();
            _edmxItemsToNotBeEmbedded = nonEmbeddedEdmxItems.ToArray();

            return(true);
        }