public void ReadReturnsExpectedValuesWhenUsingEmptySettings()
        {
            var expected   = GetBasicParameters(false);
            var reader     = new ParametersXmlReader(Properties.Resources.BasicParameters, defaultProjectName, Properties.Resources.EmptySettings);
            var parameters = reader.Read();

            parameters.AssertHasSameItems(expected);
        }
        private IEnumerable <WebDeployParameter> ParseParameters(string fileName)
        {
            IEnumerable <WebDeployParameter> results = null;

            try
            {
                var projectName = VSPackage.DteInstance.Solution.FindProjectItem(fileName).ContainingProject.Name;
                var reader      = new ParametersXmlReader(fileName, projectName);
                results = reader.Read();
            }
            catch (Exception ex)
            {
                ShowMessage("Parameters.xml Error", ex.Message);
            }
            return(results);
        }
        private void UpdateParametersXml(IEnumerable <WebConfigSetting> settings, string fileName)
        {
            var projectName = VSPackage.DteInstance.Solution.FindProjectItem(fileName).ContainingProject.Name;
            var reader      = new ParametersXmlReader(fileName, projectName);
            var parameters  = reader.Read();
            var matches     = new List <string>();

            foreach (var parameter in parameters)
            {
                if (parameter.Entries != null)
                {
                    matches.AddRange(parameter.Entries.Select(e => e.Match));
                }
            }
            var missingSettings = settings.Where(s => !matches.Any(p => p == s.NodePath)).ToList();

            EnsureUniqueSettingsNames(missingSettings, parameters.Select(p => p.Name).ToList());

            var document = new XmlDocument();

            document.Load(fileName);

            var builder = new StringBuilder();
            var writer  = XmlWriter.Create(builder, new XmlWriterSettings()
            {
                Indent = true, OmitXmlDeclaration = true, ConformanceLevel = ConformanceLevel.Fragment
            });

            try
            {
                WriteParameters(missingSettings, writer);
            }
            finally
            {
                writer.Close();
            }

            var missingParametersNodes = document.CreateDocumentFragment();

            missingParametersNodes.InnerXml = builder.ToString();

            var parametersNode = document.SelectSingleNode("/parameters");

            parametersNode.AppendChild(missingParametersNodes);

            document.Save(fileName);
        }
Beispiel #4
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                var fileName = SolutionExplorerExtensions.SelectedItemPath;

                var projectName        = VSPackage.DteInstance.Solution.FindProjectItem(fileName).ContainingProject.Name;
                var reader             = new ParametersXmlReader(ParametersXmlItem.FileNames[0], projectName);
                var allParameters      = reader.Read();
                var existingParameters = SetParametersXmlReader.GetParameters(fileName);

                var missingParameters = allParameters.Where(p => !existingParameters.Keys.Contains(p.Name)).ToList();

                if (missingParameters.Count == 0)
                {
                    ShowMessage("Parameters Already Updated", "No missing parameters found.");
                }
                else
                {
                    var document = new XmlDocument();
                    document.Load(SolutionExplorerExtensions.SelectedItemPath);

                    var parametersNode = document.SelectSingleNode("/parameters");

                    foreach (var parameter in missingParameters)
                    {
                        var node = document.CreateElement("setParameter");
                        node.SetAttribute("name", parameter.Name);
                        node.SetAttribute("value", parameter.DefaultValue);
                        parametersNode.AppendChild(node);
                    }

                    document.Save(fileName);
                    VSPackage.DteInstance.Solution.FindProjectItem(fileName).Open().Visible = true;
                }
            }
            catch (Exception ex)
            {
                ShowMessage("Parameters Error", ex.Message);
            }
        }
        public void ReadThrowsExceptionIfRootElementNotParameters()
        {
            var reader = new ParametersXmlReader("<?xml version=\"1.0\" encoding=\"utf-8\" ?><configuration></configuration>", defaultProjectName, null);

            reader.Read();
        }