src/Misc/EFTools/EntityDesign/VisualStudio/EdmUtils.cs
// <summary>
//     Called when a SQL CE database is upgraded from 3.5 to 4.0.
//     1. Check the project type, return immediately if project is misc project.
//     2. Find all the EDMX files in the project.
//     3. For each EDMX file in the project replace the SSDL Provider and ProviderManifestToken
//     attributes if needed and update the config file if needed; skip all linked edmx files
// </summary>
// <param name="hierarchy">hierarchy for project</param>
// <param name="logger">log error messages here</param>
Called when a SQL CE database is upgraded from 3.5 to 4.0.
1. Check the project type, return immediately if project is misc project.
2. Find all the EDMX files in the project.
3. For each EDMX file in the project replace the SSDL Provider and ProviderManifestToken
attributes if needed and update the config file if needed; skip all linked edmx files
Called when a SQL CE database is upgraded from 3 . 5 to 4 . 0 . 1 . Check the project type return immediately if project is misc project . 2 . Find all the EDMX files in the project . 3 . For each EDMX file in the project replace the SSDL Provider and ProviderManifestToken attributes if needed and update the config file if needed ; skip all linked edmx files
[SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "Microsoft.VisualStudio.Shell.Interop.IVsUpgradeLogger.LogMessage(System.UInt32,System.String,System.String,System.String)")]
        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
        internal static void SqlCeUpgradeService_OnUpgradeProject(IVsHierarchy hierarchy, IVsUpgradeLogger logger)
        {
            if (PackageManager.Package != null
                && PackageManager.Package.ModelManager != null)
            {
                var fileFinder = new VSFileFinder(EntityDesignArtifact.ExtensionEdmx);
                fileFinder.FindInProject(hierarchy);
                var project = VSHelpers.GetProject(hierarchy);
                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);
                            if (EdmUtils.IsDataServicesEdmx(projectItem.get_FileNames(1)))
                            {
                                continue;
                            }
                            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);
                    }
                    var configFileUtils = new ConfigFileUtils(project, PackageManager.Package);
                    try
                    {
                        var configXmlDoc = configFileUtils.LoadConfig();
                        if (configXmlDoc != null) 
                        {
                            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);
                    }
                }
            }
        }
[ SuppressMessage ( " " , " " , MessageId = " " ) ] [ SuppressMessage ( " " , " " ) ] internal static void SqlCeUpgradeService_OnUpgradeProject ( IVsHierarchy hierarchy , IVsUpgradeLogger logger ) { if ( PackageManager . Package != null && PackageManager . Package . ModelManager != null ) { var fileFinder = new VSFileFinder ( EntityDesignArtifact . ExtensionEdmx ) ; fileFinder . FindInProject ( hierarchy ) ; var project = VSHelpers . GetProject ( hierarchy ) ; 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 ) ; if ( EdmUtils . IsDataServicesEdmx ( projectItem . get_FileNames ( 1 ) ) ) { continue ; } 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 ) ; } var configFileUtils = new ConfigFileUtils ( project , PackageManager . Package ) ; try { var configXmlDoc = configFileUtils . LoadConfig ( ) ; if ( configXmlDoc != null ) { 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 ) ; } } } }
Called when a SQL CE database is upgraded from 3.5 to 4.0.
Called when a SQL CE database is upgraded from 3 . 5 to 4 . 0 .
// since this is about retargeting EDMX files on disk, no need to process other file extensions from any converters // skip the step if it is a miscellaneous project. // Dev 10 bug 648969: skip the process for astoria edmx file. // Check whether project item is a linked item // now update the config file as needed // check config file exists
hierarchy
IVsHierarchy
hierarchy for project
hierarchy for project
logger
IVsUpgradeLogger
log error messages here
log error messages here