Пример #1
0
        // <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);
            }
        }
Пример #2
0
        // <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;
            }
        }