public void ConfigFile_name_set_correctly()
        {
            var cases = new[]
            {
                new
                {
                    ApplicationType = VisualStudioProjectSystem.WebApplication,
                    ConfigFileName = "Web.Config"
                },
                new
                {
                    ApplicationType = VisualStudioProjectSystem.Website,
                    ConfigFileName = "Web.Config"
                },
                new
                {
                    ApplicationType = VisualStudioProjectSystem.WindowsApplication,
                    ConfigFileName = "App.Config"
                }
            };

            foreach (var testCase in cases)
            {
                var configFileUtils =
                    new ConfigFileUtils(Mock.Of<Project>(), Mock.Of<IServiceProvider>(), testCase.ApplicationType);

                Assert.Equal(testCase.ConfigFileName, configFileUtils.ConfigFileName);
            }
        }
        public void LoadConfig_loads_config_from_IVsTextLines()
        {
            var          configContents = "<config />";
            const string configFilePath = "configfilepath";
            var          mockTextLines  = new Mock <IVsTextLines>();

            mockTextLines.Setup(
                l => l.GetLineText(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), out configContents));

            var mockVsHelpers = new Mock <IVsHelpers>();

            mockVsHelpers
            .Setup(h => h.GetDocData(It.IsAny <IServiceProvider>(), It.IsAny <string>()))
            .Returns(mockTextLines.Object);

            var mockConfigProjectItem = new Mock <ProjectItem>();

            mockConfigProjectItem.Setup(i => i.get_FileNames(It.IsAny <short>())).Returns(configFilePath);

            var mockVsUtils = CreateMockVsUtils(LangEnum.CSharp, VisualStudioProjectSystem.WebApplication);

            mockVsUtils
            .Setup(u => u.FindFirstProjectItemWithName(It.IsAny <ProjectItems>(), It.IsAny <string>()))
            .Returns(mockConfigProjectItem.Object);

            var configFileUtils = new ConfigFileUtils(
                CreateMockProject(LangEnum.CSharp).Object,
                Mock.Of <IServiceProvider>(),
                null,
                mockVsUtils.Object,
                mockVsHelpers.Object);

            Assert.Equal(configContents, configFileUtils.LoadConfig().OuterXml);
            mockVsHelpers.Verify(h => h.GetDocData(It.IsAny <IServiceProvider>(), configFilePath), Times.Once());
        }
        public void ConfigFile_name_set_correctly()
        {
            var cases = new[]
            {
                new
                {
                    ApplicationType = VisualStudioProjectSystem.WebApplication,
                    ConfigFileName  = "Web.Config"
                },
                new
                {
                    ApplicationType = VisualStudioProjectSystem.Website,
                    ConfigFileName  = "Web.Config"
                },
                new
                {
                    ApplicationType = VisualStudioProjectSystem.WindowsApplication,
                    ConfigFileName  = "App.Config"
                }
            };

            foreach (var testCase in cases)
            {
                var configFileUtils =
                    new ConfigFileUtils(Mock.Of <Project>(), Mock.Of <IServiceProvider>(), testCase.ApplicationType);

                Assert.Equal(testCase.ConfigFileName, configFileUtils.ConfigFileName);
            }
        }
        public void LoadConfig_returns_null_if_config_does_not_exist()
        {
            var configFileUtils = new ConfigFileUtils(
                CreateMockProject(LangEnum.CSharp).Object,
                Mock.Of <IServiceProvider>(),
                vsUtils: CreateMockVsUtils(LangEnum.CSharp, VisualStudioProjectSystem.WebApplication).Object);

            Assert.Null(configFileUtils.LoadConfig());
        }
 // testing only
 internal OneEFWizard(ConfigFileUtils configFileUtils = null, IVsUtils vsUtils = null, IErrorListHelper errorListHelper = null, ModelGenErrorCache errorCache = null, 
     List<KeyValuePair<string, string>> generatedCode = null)
 {
     _configFileUtils = configFileUtils;
     _generatedCode = generatedCode ?? new List<KeyValuePair<string, string>>();
     _vsUtils = vsUtils;
     _errorListHelper = errorListHelper;
     _errorCache = errorCache;
 }
        internal WizardPageDbConfig(ModelBuilderWizardForm wizard)
            : base(wizard)
        {
            InitializeComponent();

            _configFileUtils =
                new ConfigFileUtils(wizard.Project, wizard.ServiceProvider, wizard.ModelBuilderSettings.VSApplicationType);

            _identifierUtil =
                new CodeIdentifierUtils(wizard.ModelBuilderSettings.VSApplicationType, VsUtils.GetLanguageForProject(wizard.Project));

            Headline = Resources.DbConfigPage_Title;
            Logo = Resources.PageIcon;
            Id = "WizardPageDbConfigId";
            ShowInfoPanel = false;

            sensitiveInfoTextBox.Text = Resources.SensitiveDataInfoText;
            disallowSensitiveInfoButton.Text = Resources.DisallowSensitiveDataInfoText;
            allowSensitiveInfoButton.Text = Resources.AllowSensitiveDataInfoText;
            if (VsUtils.IsWebProject(wizard.ModelBuilderSettings.VSApplicationType))
            {
                checkBoxSaveInAppConfig.Text = Resources.SaveConnectionLabelASP;
            }
            else
            {
                checkBoxSaveInAppConfig.Text = Resources.SaveConnectionLabel;
            }

            // make the App/Web.Config connection name entry non-editable for 'Update Model' and 'Generate Database' scenarios
            if (ModelBuilderWizardForm.WizardMode.PerformDatabaseConfigAndSelectTables == Wizard.Mode
                || ModelBuilderWizardForm.WizardMode.PerformDatabaseConfigAndDBGenSummary == Wizard.Mode
                || ModelBuilderWizardForm.WizardMode.PerformDBGenSummaryOnly == Wizard.Mode)
            {
                textBoxAppConfigConnectionName.Enabled = false;
            }

            newDBConnectionButton.Text = Resources.NewDatabaseConnectionBtn;
            lblEntityConnectionString.Text = Resources.ConnectionStringLabel;
            lblPagePrompt.Text = Resources.WhichDataConnectionLabel;
            lblPagePrompt.Font = LabelFont;

            sensitiveInfoTextBox.Enabled = false;
            disallowSensitiveInfoButton.Enabled = false;
            allowSensitiveInfoButton.Enabled = false;
            HelpKeyword = null;
        }
Exemple #7
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);
                    }
                }
            }
        }
        internal static Dictionary<string, string> GetExistingConnectionStrings(ConfigFileUtils configFileUtils)
        {
            var configXml = configFileUtils.LoadConfig();

            var existingConnectionStrings = new Dictionary<string, string>();
            if (configXml == null)
            {
                // can be null if config does not exist in which case there are no connection strings
                return existingConnectionStrings;
            }

            // note we return all the connection string names to support CodeFirst scenarios
            foreach (var addElement in 
                configXml.SelectNodes(XpathConnectionStringsAdd).OfType<XmlElement>())
            {
                var name = addElement.GetAttribute(XmlAttrNameName);
                if (!string.IsNullOrEmpty(name))
                {
                    existingConnectionStrings.Add(name, addElement.GetAttribute(XmlAttrNameConnectionString));
                }
            }

            return existingConnectionStrings;
        }
        // computes a unique connection string name based on the input base name
        internal static string GetUniqueConnectionStringName(ConfigFileUtils configFileUtils, string baseConnectionStringName)
        {
            var connectionStringNames = GetExistingConnectionStrings(configFileUtils).Keys;

            var i = 1;
            var uniqueConnectionStringName = baseConnectionStringName;
            while (connectionStringNames.Contains(uniqueConnectionStringName))
            {
                uniqueConnectionStringName = baseConnectionStringName + i++;
            }

            return uniqueConnectionStringName;
        }
        // <summary>
        //     Takes our local hash and destructively updates the .config file.
        // </summary>
        // <param name="project">DTE Project that owns the .config file we want to look at.</param>
        private void InsertConnStringsFromHash(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            if (project.UniqueName.Equals(Constants.vsMiscFilesProjectUniqueName, StringComparison.Ordinal))
            {
                return;
            }

            InitializeConnectionStringsHash();


            var configFileUtils = new ConfigFileUtils(project, PackageManager.Package);
            configFileUtils.GetOrCreateConfigFile();
            var configXmlDoc = configFileUtils.LoadConfig();

            Dictionary<string, ConnectionString> hash;
            if (!ConnStringsByProjectHash.TryGetValue(project, out hash))
            {
                var s = String.Format(CultureInfo.CurrentCulture, Resources.ConnectionManager_GetConfigError);
                VsUtils.LogOutputWindowPaneMessage(project, s);
                return;
            }

            if (hash.Any())
            {
                UpdateEntityConnectionStringsInConfig(configXmlDoc, hash);
                configFileUtils.SaveConfig(configXmlDoc);
            }
        }
        // <summary>
        //     Takes our Xml .config file and destructively updates our local hash.
        // </summary>
        // <param name="project">DTE Project that owns App.Config we want to look at.</param>
        internal void ExtractConnStringsIntoHash(Project project, bool createConfig)
        {
            if (VsUtils.IsMiscellaneousProject(project))
            {
                return;
            }

            var configFileUtils = new ConfigFileUtils(project, PackageManager.Package);
            if (createConfig)
            {
                configFileUtils.GetOrCreateConfigFile();
            }

            var configXmlDoc = configFileUtils.LoadConfig();
            if (configXmlDoc != null)
            {
                var xmlNodeList = configXmlDoc.SelectNodes(XpathConnectionStringsAddEntity);

                var stringHash = new Dictionary<string, ConnectionString>();
                foreach (XmlNode node in xmlNodeList)
                {
                    var connStringObj = new ConnectionString(node.Attributes.GetNamedItem(XmlAttrNameConnectionString).Value);
                    stringHash.Add(node.Attributes.GetNamedItem(XmlAttrNameName).Value, connStringObj);
                }

                // from msdn: UniqueName: This [property] returns a temporary, unique string value that you can use to 
                // differentiate one project from another.
                ConnStringsByProjectHash[project] = stringHash;
            }
        }
        public WizardPageStart(ModelBuilderWizardForm wizard, ConfigFileUtils configFileUtils = null)
            : base(wizard)
        {
            InitializeComponent();

            _codeFirstAllowed = CodeFirstAllowed(Wizard.ModelBuilderSettings);
            _configFileUtils = configFileUtils
                               ?? new ConfigFileUtils(wizard.Project, wizard.ServiceProvider, wizard.ModelBuilderSettings.VSApplicationType);

            components = new Container();

            Logo = Resources.PageIcon;
            Headline = Resources.StartPage_Title;
            Id = "WizardPageStartId";
            ShowInfoPanel = false;

            labelPrompt.Text = Resources.StartPage_PromptLabelText;
            labelPrompt.Font = LabelFont;

            // Load new ImageList with glyphs from resources
            var imageList = new ImageList(components)
            {
                ColorDepth = ColorDepth.Depth32Bit,
                ImageSize = new Size(32, 32),
                TransparentColor = Color.Magenta
            };

            imageList.Images.Add("database.png", Resources.Database);
            imageList.Images.Add("EmptyModel.png", Resources.EmptyModel);
            imageList.Images.Add("EmptyModelCodeFirst.png", Resources.EmptyModelCodeFirst);
            imageList.Images.Add("CodeFirstFromDatabase.png", Resources.CodeFirstFromDatabase);

#if VS12ORNEWER
            // scale images as appropriate for screen resolution
            DpiHelper.LogicalToDeviceUnits(ref imageList);
#endif

            // Re-create ListView and add the list items so we are sure to use our string resources)
            listViewModelContents.Clear();
            listViewModelContents.ShowItemToolTips = true;
            listViewModelContents.LargeImageList = imageList;

            listViewModelContents.Items.AddRange(
                new[]
                {
                    new ListViewItem(Resources.GenerateFromDatabaseOption, "database.png"),
                    new ListViewItem(Resources.EmptyModelOption, "EmptyModel.png"),
                });

            if (NetFrameworkVersioningHelper.TargetNetFrameworkVersion(wizard.ModelBuilderSettings.Project, Wizard.ServiceProvider) >=
                NetFrameworkVersioningHelper.NetFrameworkVersion4)
            {
                listViewModelContents.Items.Add(new ListViewItem(Resources.EmptyModelCodeFirstOption, "EmptyModelCodeFirst.png"));
                listViewModelContents.Items.Add(new ListViewItem(Resources.CodeFirstFromDatabaseOption, "CodeFirstFromDatabase.png"));
            }

            // Always select the first item
            listViewModelContents.MultiSelect = false;
            listViewModelContents.Items[0].Selected = true;

            listViewModelContents.Focus();
        }
Exemple #13
0
        internal static void SqlDatabaseFileUpgradeService_OnUpgradeProject(
            IVsHierarchy hierarchy, string databaseFile, string newConnectionString, IVsUpgradeLogger logger)
        {
            if (PackageManager.Package != null
                && PackageManager.Package.ModelManager != null)
            {
                var project = VSHelpers.GetProject(hierarchy);

                // skip the step if it is a miscellaneous project or if the project is using IIS
                // (projects using IIS should not be upgraded - see bug 812074)
                if (project != null
                    && !VsUtils.IsMiscellaneousProject(project)
                    && !IsUsingIIS(project))
                {
                    // update the config file as needed
                    var configFileUtils = new ConfigFileUtils(project, PackageManager.Package);
                    UpdateConfigForSqlDbFileUpgrade(configFileUtils, project, logger);
                }
            }
        }
        public void CreateConfigFile_uses_correct_item_template_to_add_config_file()
        {
            var testCases = new[]
            {
                new
                {
                    ApplicationType            = VisualStudioProjectSystem.WebApplication,
                    ProjectLanguage            = LangEnum.CSharp,
                    ExpectedConfigItemTemplate = "WebConfig.zip",
                    ExpectedLanguage           = "{349C5853-65DF-11DA-9384-00065B846F21}"
                },
                new
                {
                    ApplicationType            = VisualStudioProjectSystem.WebApplication,
                    ProjectLanguage            = LangEnum.VisualBasic,
                    ExpectedConfigItemTemplate = "WebConfig.zip",
                    ExpectedLanguage           = "{349C5854-65DF-11DA-9384-00065B846F21}"
                },

                new
                {
                    ApplicationType            = VisualStudioProjectSystem.Website,
                    ProjectLanguage            = LangEnum.CSharp,
                    ExpectedConfigItemTemplate = "WebConfig.zip",
                    ExpectedLanguage           = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" // PrjKind.prjKindCSharpProject
                },
                new
                {
                    ApplicationType            = VisualStudioProjectSystem.Website,
                    ProjectLanguage            = LangEnum.VisualBasic,
                    ExpectedConfigItemTemplate = "WebConfig.zip",
                    ExpectedLanguage           = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" // PrjKind.prjKindVBProject
                },
                new
                {
                    ApplicationType            = VisualStudioProjectSystem.WindowsApplication,
                    ProjectLanguage            = LangEnum.CSharp,
                    ExpectedConfigItemTemplate = "AppConfigInternal.zip",
                    ExpectedLanguage           = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" // PrjKind.prjKindCSharpProject
                },
                new
                {
                    ApplicationType            = VisualStudioProjectSystem.WindowsApplication,
                    ProjectLanguage            = LangEnum.VisualBasic,
                    ExpectedConfigItemTemplate = "AppConfigurationInternal.zip",
                    ExpectedLanguage           = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" // PrjKind.prjKindVBProject
                },
            };

            foreach (var testCase in testCases)
            {
                var mockVsUtils = CreateMockVsUtils(testCase.ProjectLanguage, testCase.ApplicationType);
                var project     = CreateMockProject(testCase.ProjectLanguage).Object;

                var configFileUtils =
                    new ConfigFileUtils(project, Mock.Of <IServiceProvider>(), vsUtils: mockVsUtils.Object);

                configFileUtils.CreateConfigFile();

                Mock.Get((Solution2)project.DTE.Solution)
                .Verify(s => s.GetProjectItemTemplate(testCase.ExpectedConfigItemTemplate, testCase.ExpectedLanguage), Times.Once());
            }
        }
        private static Mock<WizardPageStart> CreateMockWizardPageStart(ModelBuilderWizardForm mockWizard, int itemIndex, 
            ConfigFileUtils configFileUtils = null)
        {
            var mockWizardPageStart = new Mock<WizardPageStart>(mockWizard, configFileUtils) { CallBase = true };
            mockWizardPageStart
                .Protected()
                .Setup<bool>("AnyItemSelected")
                .Returns(true);

            mockWizardPageStart
                .Protected()
                .Setup<bool>("VerifyModelFilePath", ItExpr.IsAny<string>())
                .Returns(true);

            mockWizardPageStart
                .Protected()
                .Setup<int>("GetSelectedOptionIndex")
                .Returns(itemIndex);
            return mockWizardPageStart;
        }
        public void LoadConfig_loads_config_from_IVsTextLines()
        {
            var configContents = "<config />";
            const string configFilePath = "configfilepath";
            var mockTextLines = new Mock<IVsTextLines>();
            mockTextLines.Setup(
                l => l.GetLineText(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<int>(), out configContents));

            var mockVsHelpers = new Mock<IVsHelpers>();
            mockVsHelpers
                .Setup(h => h.GetDocData(It.IsAny<IServiceProvider>(), It.IsAny<string>()))
                .Returns(mockTextLines.Object);

            var mockConfigProjectItem = new Mock<ProjectItem>();
            mockConfigProjectItem.Setup(i => i.get_FileNames(It.IsAny<short>())).Returns(configFilePath);

            var mockVsUtils = CreateMockVsUtils(LangEnum.CSharp, VisualStudioProjectSystem.WebApplication);
            mockVsUtils
                .Setup(u => u.FindFirstProjectItemWithName(It.IsAny<ProjectItems>(), It.IsAny<string>()))
                .Returns(mockConfigProjectItem.Object);

            var configFileUtils = new ConfigFileUtils(
                CreateMockProject(LangEnum.CSharp).Object,
                Mock.Of<IServiceProvider>(),
                null,
                mockVsUtils.Object,
                mockVsHelpers.Object);

            Assert.Equal(configContents, configFileUtils.LoadConfig().OuterXml);
            mockVsHelpers.Verify(h => h.GetDocData(It.IsAny<IServiceProvider>(), configFilePath), Times.Once());
        }
        public void CreateConfigFile_uses_correct_item_template_to_add_config_file()
        {
            var testCases = new[]
            {
                new
                {
                    ApplicationType = VisualStudioProjectSystem.WebApplication,
                    ProjectLanguage = LangEnum.CSharp,
                    ExpectedConfigItemTemplate = "WebConfig.zip",
                    ExpectedLanguage = "{349C5853-65DF-11DA-9384-00065B846F21}"
                },
                new
                {
                    ApplicationType = VisualStudioProjectSystem.WebApplication,
                    ProjectLanguage = LangEnum.VisualBasic,
                    ExpectedConfigItemTemplate = "WebConfig.zip",
                    ExpectedLanguage = "{349C5854-65DF-11DA-9384-00065B846F21}"
                },

                new
                {
                    ApplicationType = VisualStudioProjectSystem.Website,
                    ProjectLanguage = LangEnum.CSharp,
                    ExpectedConfigItemTemplate = "WebConfig.zip",
                    ExpectedLanguage = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" // PrjKind.prjKindCSharpProject
                },
                new
                {
                    ApplicationType = VisualStudioProjectSystem.Website,
                    ProjectLanguage = LangEnum.VisualBasic,
                    ExpectedConfigItemTemplate = "WebConfig.zip",
                    ExpectedLanguage = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" // PrjKind.prjKindVBProject
                },
                new
                {
                    ApplicationType = VisualStudioProjectSystem.WindowsApplication,
                    ProjectLanguage = LangEnum.CSharp,
                    ExpectedConfigItemTemplate = "AppConfigInternal.zip",
                    ExpectedLanguage = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" // PrjKind.prjKindCSharpProject
                },
                new
                {
                    ApplicationType = VisualStudioProjectSystem.WindowsApplication,
                    ProjectLanguage = LangEnum.VisualBasic,
                    ExpectedConfigItemTemplate = "AppConfigurationInternal.zip",
                    ExpectedLanguage = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" // PrjKind.prjKindVBProject
                },
            };

            foreach (var testCase in testCases)
            {
                var mockVsUtils = CreateMockVsUtils(testCase.ProjectLanguage, testCase.ApplicationType);
                var project = CreateMockProject(testCase.ProjectLanguage).Object;

                var configFileUtils =
                    new ConfigFileUtils(project, Mock.Of<IServiceProvider>(), vsUtils: mockVsUtils.Object);

                configFileUtils.CreateConfigFile();

                Mock.Get((Solution2)project.DTE.Solution)
                    .Verify(s => s.GetProjectItemTemplate(testCase.ExpectedConfigItemTemplate, testCase.ExpectedLanguage), Times.Once());
            }
        }
        public void LoadConfig_returns_null_if_config_does_not_exist()
        {
            var configFileUtils = new ConfigFileUtils(
                CreateMockProject(LangEnum.CSharp).Object,
                Mock.Of<IServiceProvider>(),
                vsUtils: CreateMockVsUtils(LangEnum.CSharp, VisualStudioProjectSystem.WebApplication).Object);

            Assert.Null(configFileUtils.LoadConfig());
        }
Exemple #19
0
 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 for testing, settings parameter to allow testing without messing with the static variable
        internal void RunFinished(ModelBuilderSettings settings, string targetDirectory)
        {
            // null indicates an error when generating code
            if (_generatedCode == null)
            {
                return;
            }

            var project = settings.Project;

            var filesToSave = _generatedCode.Skip(1)
                .ToDictionary(kvp => Path.Combine(targetDirectory, kvp.Key), kvp => (object)kvp.Value);

            try
            {
                _vsUtils.WriteCheckoutTextFilesInProject(filesToSave);
            }
            finally
            {
                // even if saving fails we actually might have created some files
                // and we should add them to the project
                AddFilesToProject(project, filesToSave.Keys);
            }

            _configFileUtils =
                _configFileUtils ??
                    new ConfigFileUtils(
                    project,
                    PackageManager.Package,
                    settings.VSApplicationType);

            UpdateConfigFile(settings);
        }