internal static void UpdateConfigForSqlDbFileUpgrade(ConfigFileUtils configFileUtils, Project project, IVsUpgradeLogger logger) { try { var configXmlDoc = configFileUtils.LoadConfig(); if (configXmlDoc != null) // check config file exists { if (ConnectionManager.UpdateSqlDatabaseFileDataSourceInConnectionStrings(configXmlDoc)) { configFileUtils.SaveConfig(configXmlDoc); } } } catch (Exception ex) { // if there were errors above then do not try to change the files on disk - just log the message and return var errMsg = String.Format( CultureInfo.CurrentCulture, Resources.ErrorDuringSqlDatabaseFileUpgrade, configFileUtils.GetConfigPath(), ex.Message); logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, project.Name, configFileUtils.GetConfigPath(), errMsg); } }
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); } } } }