Пример #1
0
        private void UpdateParametersXml(IEnumerable <WebConfigSetting> settings, string fileName)
        {
            var parameters      = ParametersXmlReader.GetParameters(fileName);
            var missingSettings = settings.Where(s => !parameters.Any(p => p.Key == s.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);
        }
Пример #2
0
        private IDictionary <string, string> ParseParameters(string fileName)
        {
            IDictionary <string, string> results = null;

            try
            {
                results = ParametersXmlReader.GetParameters(fileName);
            }
            catch (Exception ex)
            {
                ShowMessage("Parameters.xml Error", ex.Message);
            }
            return(results);
        }
Пример #3
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 allParameters      = ParametersXmlReader.GetParameters(ParametersXmlItem.FileNames[0]);
                var existingParameters = ParametersXmlReader.GetParameters(fileName);

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

                if (missingParameters.Count == 0)
                {
                    ShowMessage("Parameters Already Updated", "No missing parameters found.");
                }

                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.Key);
                    node.SetAttribute("value", parameter.Value);
                    parametersNode.AppendChild(node);
                }

                document.Save(fileName);
            }
            catch (Exception ex)
            {
                ShowMessage("Parameters Error", ex.Message);
            }
        }