Exemple #1
0
        // 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);
        }
Exemple #2
0
        public override bool Execute()
        {
            bool allFilesCleaned = true;

            // the source's itemspec will mirror the metadata locations
            // in the bin directory exactly.
            foreach (ITaskItem source in this.Sources)
            {
                // combine the output path and the edmx file location to create a location that points to where the
                // output files exist
                string          relativePath            = EntityDeploySplit.EntityDeployMetadataRelativePath(source);
                string          resourceOutputModelPath = (null != this.ResourceOutputPath) ? Path.Combine(this.ResourceOutputPath, relativePath) : null;
                string          outputModelPath         = Path.Combine(this.OutputPath, relativePath);
                List <FileInfo> filesToDelete           = new List <FileInfo>();
                try
                {
                    // translate the 'fake' model path into the assumed locations of the csdl, ssdl, and msl locations
                    // under either ResourceOutputPath or OutputPath - file will be deleted if present under either one
                    // if resourceOutputModelPath is null then follow the v3.5 behavior
                    if (null != resourceOutputModelPath)
                    {
                        filesToDelete.Add(new FileInfo(Path.ChangeExtension(resourceOutputModelPath, XmlConstants.CSpaceSchemaExtension)));
                        filesToDelete.Add(new FileInfo(Path.ChangeExtension(resourceOutputModelPath, XmlConstants.SSpaceSchemaExtension)));
                        filesToDelete.Add(new FileInfo(Path.ChangeExtension(resourceOutputModelPath, XmlConstants.CSSpaceSchemaExtension)));
                    }

                    filesToDelete.Add(new FileInfo(Path.ChangeExtension(outputModelPath, XmlConstants.CSpaceSchemaExtension)));
                    filesToDelete.Add(new FileInfo(Path.ChangeExtension(outputModelPath, XmlConstants.SSpaceSchemaExtension)));
                    filesToDelete.Add(new FileInfo(Path.ChangeExtension(outputModelPath, XmlConstants.CSSpaceSchemaExtension)));
                }
                catch (Exception ex)
                {
                    // there are lots of possible exceptions here (Security, NotSupported, Argument, Unauthorized, etc.)
                    Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorProcessingInputFile, source.ItemSpec));
                    Log.LogErrorFromException(ex, false);
                    allFilesCleaned = false;
                    continue;
                }

                // if each CSDL, SSDL, and MSL file exists, then delete it
                foreach (FileInfo fileToDelete in filesToDelete)
                {
                    if (fileToDelete.Exists)
                    {
                        try
                        {
                            fileToDelete.Delete();
                            Log.LogMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, Resources.FinishedCleaningFile, fileToDelete.FullName));
                        }
                        catch (Exception e)
                        {
                            Log.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ErrorCleaningFile, fileToDelete.FullName));
                            Log.LogErrorFromException(e, false);
                            allFilesCleaned = false;
                        }
                    }
                }

                Log.LogMessage(string.Format(CultureInfo.CurrentCulture, Resources.FinishedCleaningEdmxFile, source.ItemSpec));
            }

            if (allFilesCleaned)
            {
                Log.LogMessage(string.Format(CultureInfo.CurrentCulture, Resources.FinishedCleaningAllFiles, this.Sources.Length));
            }

            return(allFilesCleaned);
        }