Exemple #1
0
        internal static DesignerErrorList GetSingleDocErrorList(Uri uri)
        {
            DesignerErrorList errorList = null;

            var currentProject = VSHelpers.GetProjectForDocument(uri.LocalPath, PackageManager.Package);

            if (currentProject != null)
            {
                var hierarchy = VsUtils.GetVsHierarchy(currentProject, Services.ServiceProvider);
                if (hierarchy != null)
                {
                    var fileFinder = new VSFileFinder(uri.LocalPath);
                    fileFinder.FindInProject(hierarchy);

                    Debug.Assert(fileFinder.MatchingFiles.Count <= 1, "Unexpected count of matching files in project");

                    foreach (var vsFileInfo in fileFinder.MatchingFiles)
                    {
                        if (vsFileInfo.Hierarchy == VsUtils.GetVsHierarchy(currentProject, Services.ServiceProvider))
                        {
                            errorList = GetSingleDocErrorList(vsFileInfo.Hierarchy, vsFileInfo.ItemId);
                            break;
                        }
                    }
                }
            }

            return(errorList);
        }
        internal static bool LoadAndValidateAllFilesInProject(
            IVsHierarchy pHierProj, bool doEscherValidation, Func<EFArtifact, bool> shouldValidateArtifact)
        {
            // clear all errors for this project
            ErrorListHelper.ClearHierarchyErrors(pHierProj);

            var fileFinder = new VSFileFinder(EntityDesignArtifact.ExtensionEdmx);
            fileFinder.FindInProject(pHierProj);

            var edmxFilesToValidate = new List<VSFileFinder.VSFileInfo>(fileFinder.MatchingFiles);

            return LoadAndValidateFiles(edmxFilesToValidate, doEscherValidation, shouldValidateArtifact);
        }
Exemple #3
0
        internal static bool LoadAndValidateAllFilesInProject(
            IVsHierarchy pHierProj, bool doEscherValidation, Func <EFArtifact, bool> shouldValidateArtifact)
        {
            // clear all errors for this project
            ErrorListHelper.ClearHierarchyErrors(pHierProj);

            var fileFinder = new VSFileFinder(EntityDesignArtifact.ExtensionEdmx);

            fileFinder.FindInProject(pHierProj);

            var edmxFilesToValidate = new List <VSFileFinder.VSFileInfo>(fileFinder.MatchingFiles);

            return(LoadAndValidateFiles(edmxFilesToValidate, doEscherValidation, shouldValidateArtifact));
        }
Exemple #4
0
        internal static void ClearErrorsForDocAcrossLists(Uri uri)
        {
            var currentProject = VSHelpers.GetProjectForDocument(uri.LocalPath, PackageManager.Package);

            if (currentProject != null)
            {
                var hierarchy = VsUtils.GetVsHierarchy(currentProject, Services.ServiceProvider);
                if (hierarchy != null)
                {
                    var fileFinder = new VSFileFinder(uri.LocalPath);
                    fileFinder.FindInProject(hierarchy);

                    Debug.Assert(fileFinder.MatchingFiles.Count <= 1, "Unexpected count of matching files in project");
                    foreach (var vsFileInfo in fileFinder.MatchingFiles)
                    {
                        if (vsFileInfo.Hierarchy == hierarchy)
                        {
                            ClearErrorsForDocAcrossLists(vsFileInfo.Hierarchy, vsFileInfo.ItemId);
                            break;
                        }
                    }
                }
            }
        }
Exemple #5
0
        internal static void SqlCeUpgradeService_OnUpgradeProject(IVsHierarchy hierarchy, IVsUpgradeLogger logger)
        {
            if (PackageManager.Package != null
                && PackageManager.Package.ModelManager != null)
            {
                // since this is about retargeting EDMX files on disk, no need to process other file extensions from any converters
                var fileFinder = new VSFileFinder(EntityDesignArtifact.ExtensionEdmx);
                fileFinder.FindInProject(hierarchy);

                var project = VSHelpers.GetProject(hierarchy);

                // skip the step if it is a miscellaneous project.
                if (project != null
                    && !VsUtils.IsMiscellaneousProject(project))
                {
                    IDictionary<string, object> documentMap = new Dictionary<string, object>();
                    foreach (var vsFileInfo in fileFinder.MatchingFiles)
                    {
                        try
                        {
                            var projectItem = VsUtils.GetProjectItem(hierarchy, vsFileInfo.ItemId);

                            // Dev 10 bug 648969: skip the process for astoria edmx file.
                            if (EdmUtils.IsDataServicesEdmx(projectItem.get_FileNames(1)))
                            {
                                continue;
                            }

                            // Check whether project item is a linked item
                            var isLinkItem = VsUtils.IsLinkProjectItem(projectItem);

                            if (!isLinkItem)
                            {
                                var doc = MetadataConverterDriver.SqlCeInstance.Convert(SafeLoadXmlFromPath(vsFileInfo.Path));
                                if (doc != null)
                                {
                                    documentMap.Add(vsFileInfo.Path, doc);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            var errMsg = String.Format(
                                CultureInfo.CurrentCulture, Resources.ErrorDuringSqlCeUpgrade, vsFileInfo.Path, ex.Message);
                            logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, project.Name, vsFileInfo.Path, errMsg);
                            return;
                        }
                    }

                    if (documentMap.Count > 0)
                    {
                        VsUtils.WriteCheckoutXmlFilesInProject(documentMap);
                    }

                    // now update the config file as needed
                    var configFileUtils = new ConfigFileUtils(project, PackageManager.Package);
                    try
                    {
                        var configXmlDoc = configFileUtils.LoadConfig();
                        if (configXmlDoc != null) // check config file exists
                        {
                            if (ConnectionManager.UpdateSqlCeProviderInConnectionStrings(configXmlDoc))
                            {
                                configFileUtils.SaveConfig(configXmlDoc);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var errMsg = String.Format(
                            CultureInfo.CurrentCulture, Resources.ErrorDuringSqlCeUpgrade, configFileUtils.GetConfigPath(), ex.Message);
                        logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, project.Name, configFileUtils.GetConfigPath(), errMsg);
                    }
                }
            }
        }
Exemple #6
0
        internal static void SqlCeUpgradeService_OnUpgradeProject(IVsHierarchy hierarchy, IVsUpgradeLogger logger)
        {
            if (PackageManager.Package != null &&
                PackageManager.Package.ModelManager != null)
            {
                // since this is about retargeting EDMX files on disk, no need to process other file extensions from any converters
                var fileFinder = new VSFileFinder(EntityDesignArtifact.ExtensionEdmx);
                fileFinder.FindInProject(hierarchy);

                var project = VSHelpers.GetProject(hierarchy);

                // skip the step if it is a miscellaneous project.
                if (project != null &&
                    !VsUtils.IsMiscellaneousProject(project))
                {
                    IDictionary <string, object> documentMap = new Dictionary <string, object>();
                    foreach (var vsFileInfo in fileFinder.MatchingFiles)
                    {
                        try
                        {
                            var projectItem = VsUtils.GetProjectItem(hierarchy, vsFileInfo.ItemId);

                            // Dev 10 bug 648969: skip the process for astoria edmx file.
                            if (EdmUtils.IsDataServicesEdmx(projectItem.get_FileNames(1)))
                            {
                                continue;
                            }

                            // Check whether project item is a linked item
                            var isLinkItem = VsUtils.IsLinkProjectItem(projectItem);

                            if (!isLinkItem)
                            {
                                var doc = MetadataConverterDriver.SqlCeInstance.Convert(SafeLoadXmlFromPath(vsFileInfo.Path));
                                if (doc != null)
                                {
                                    documentMap.Add(vsFileInfo.Path, doc);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            var errMsg = String.Format(
                                CultureInfo.CurrentCulture, Resources.ErrorDuringSqlCeUpgrade, vsFileInfo.Path, ex.Message);
                            logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, project.Name, vsFileInfo.Path, errMsg);
                            return;
                        }
                    }

                    if (documentMap.Count > 0)
                    {
                        VsUtils.WriteCheckoutXmlFilesInProject(documentMap);
                    }

                    // now update the config file as needed
                    var configFileUtils = new ConfigFileUtils(project, PackageManager.Package);
                    try
                    {
                        var configXmlDoc = configFileUtils.LoadConfig();
                        if (configXmlDoc != null) // check config file exists
                        {
                            if (ConnectionManager.UpdateSqlCeProviderInConnectionStrings(configXmlDoc))
                            {
                                configFileUtils.SaveConfig(configXmlDoc);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var errMsg = String.Format(
                            CultureInfo.CurrentCulture, Resources.ErrorDuringSqlCeUpgrade, configFileUtils.GetConfigPath(), ex.Message);
                        logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, project.Name, configFileUtils.GetConfigPath(), errMsg);
                    }
                }
            }
        }
 private static bool ValidateArtifactAndWriteErrors(EFArtifact artifact, VSFileFinder.VSFileInfo vsFileInfo, bool doEscherValidation)
 {
     return ValidateArtifactAndWriteErrors(artifact, vsFileInfo.Hierarchy, vsFileInfo.ItemId, doEscherValidation);
 }
        private bool IsDependentTTFile(VSFileFinder.VSFileInfo fileInfo)
        {
            string contents = null;
            var docData = VSHelpers.GetDocData(ServiceProvider, fileInfo.Path);
            if (docData == null)
            {
                // load file from disk
                try
                {
                    contents = File.ReadAllText(fileInfo.Path);
                }
                catch (Exception e)
                {
                    var errorMsg = String.Format(CultureInfo.CurrentCulture, Resources.ErrorOccurredLoadingFile, fileInfo.Path, e.Message);
                    VsUtils.LogOutputWindowPaneMessage(VSHelpers.GetProject(Hierarchy), errorMsg);
                    contents = null;
                }
            }
            else
            {
                // read buffer contents
                var tl = VSHelpers.GetVsTextLinesFromDocData(docData);
                Debug.Assert(tl != null, "Couldn't get text lines from doc data for .tt file");
                if (tl != null)
                {
                    contents = VSHelpers.GetTextFromVsTextLines(tl);
                }
            }

            //
            // BUGBUG 592011:  replace this with something smarter.  Use T4 parser to identify all input files.
            //
            if (contents != null)
            {
                var fi = new FileInfo(FileName);
                return contents.Contains(fi.Name);
            }
            else
            {
                return false;
            }
        }
        private void ProcessDependentTTFiles()
        {
            // check if template processing was turned off via designer options
            var processTemplates = true;
            var artifact = PackageManager.Package.ModelManager.GetArtifact(Utils.FileName2Uri(FileName));
            if (artifact != null)
            {
                DesignerInfo designerInfo;
                if (artifact.DesignerInfo().TryGetDesignerInfo(OptionsDesignerInfo.ElementName, out designerInfo))
                {
                    var optionsDesignerInfo = designerInfo as OptionsDesignerInfo;
                    Debug.Assert(
                        optionsDesignerInfo != null,
                        "DesignerInfo associated with " + OptionsDesignerInfo.ElementName + "must be of type OptionsDesignerInfo");
                    if (optionsDesignerInfo != null
                        && optionsDesignerInfo.ProcessDependentTemplatesOnSave != null
                        && optionsDesignerInfo.ProcessDependentTemplatesOnSave.ValueAttr != null)
                    {
                        bool.TryParse(optionsDesignerInfo.ProcessDependentTemplatesOnSave.ValueAttr.Value, out processTemplates);
                    }
                }
            }

            // if template processing was turned off, return
            if (processTemplates == false)
            {
                return;
            }

            // Find all .tt files in the project and invoke custom Tool 
            var fileFinder = new VSFileFinder(".tt");
            fileFinder.FindInProject(Hierarchy);
            foreach (var vsFileInfo in fileFinder.MatchingFiles)
            {
                if (IsDependentTTFile(vsFileInfo))
                {
                    var pi = VsUtils.GetProjectItem(vsFileInfo.Hierarchy, vsFileInfo.ItemId);
                    Debug.Assert(pi != null, "Couldn't find project item, but file was discovered by VSFileFinder");
                    if (pi != null)
                    {
                        try
                        {
                            VsUtils.RunCustomTool(pi);
                        }
                        catch (Exception e)
                        {
                            // Swallow exceptions here, since we don't want a custom tool to interfere with the file save.
                            var errorMsg = String.Format(
                                CultureInfo.CurrentCulture, Resources.ErrorOccurredRunningCustomTool, vsFileInfo.Path, e.Message);
                            VsUtils.LogOutputWindowPaneMessage(VSHelpers.GetProject(Hierarchy), errorMsg);
                        }
                    }
                }
            }
        }