Ejemplo n.º 1
0
        /// <summary>
        /// Applies the xml changes to this instance.
        /// </summary>
        /// <returns></returns>
        public Boolean Run()
        {
            //Add them in a specific order
            foreach (XmlAdd mod in file.Add)
            {
                mod.Value = RenderConfigEngine.ReplaceEnvironmentVariables(mod.Value);
                LogUtilities.LogKeyValue("TYPE", "ADD", 27, MessageImportance.High, log);
                LogModificationDetails(mod.xpath, mod.attribute, mod.Value, string.Empty, log);

                Add(mod);
            }

            foreach (XmlUpdate mod in file.Update)
            {
                mod.Value = RenderConfigEngine.ReplaceEnvironmentVariables(mod.Value);
                LogUtilities.LogKeyValue("TYPE", "UPDATE", 27, MessageImportance.High, log);
                LogModificationDetails(mod.xpath, string.Empty, mod.Value, string.Empty, log);

                Update(mod);
            }

            foreach (XmlReplace mod in file.Replace)
            {
                //HACK: This is not pretty...anytime I use out I swear a puppy dies somewhere...
                mod.Value = RenderConfigEngine.ReplaceEnvironmentVariables(mod.Value);
                LogUtilities.LogKeyValue("TYPE", "REPLACE", 27, MessageImportance.High, log);
                LogModificationDetails(string.Empty, string.Empty, mod.Value, mod.regex, log);

                int count = 0;
                document.LoadXml(RenderConfigEngine.RegExParseAndReplace(out count, mod.regex, mod.Value, document.OuterXml.ToString()));
                LogUtilities.LogCount(count, log);
            }

            foreach (XmlDelete mod in file.Delete)
            {
                LogUtilities.LogKeyValue("TYPE", "DELETE", 27, MessageImportance.High, log);
                LogModificationDetails(mod.xpath, string.Empty, mod.Value, string.Empty, log);

                Delete(mod);
            }

            //TODO: Make sure that we stamp the renderconfig data if required
            if (config.StampRenderData)
            {
                XmlComment comment = document.CreateComment("Test Comment");
                document.FirstChild.AppendChild(comment);
            }

            //HACK Why oh why are XmlWriterSettings and XmlReaderSettings SOOO SIMILAR, and yet....
            XmlWriterSettings writerSettings = GetXmlWriterSettings(config.CleanOutput, document);

            using (XmlWriter writer = XmlWriter.Create(targetFile, writerSettings))
            {
                document.Save(writer);
            }
            //HACK BAD
            returnCode = true;
            return(returnCode);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Logs the modification details.
        /// </summary>
        /// <param name="section">The section.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <param name="regex">The regex.</param>
        /// <param name="log">The log.</param>
        private static void LogModificationDetails(string section, string key, string value, string regex, IRenderConfigLogger log)
        {
            if (String.IsNullOrEmpty(section))
            {
                LogUtilities.LogKeyValue("SECTION", section, 27, MessageImportance.Normal, log);
            }

            if (String.IsNullOrEmpty(key))
            {
                LogUtilities.LogKeyValue("KEY", key, 27, MessageImportance.Normal, log);
            }

            //Dont output if we are deleting a key, it just doesnt make sense
            if (!String.IsNullOrEmpty(value))
            {
                LogUtilities.LogKeyValue("VALUE", value.Trim(), 27, MessageImportance.Normal, log);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs this modification.
        /// </summary>
        /// <returns></returns>
        public bool Run()
        {
            if (config.StampRenderData)
            {
                //TODO:  Nini doesnt seem to do comments for us, need to do this by hand.
            }
            //Add them in a specific order
            foreach (IniAdd mod in file.Add)
            {
                mod.Value = RenderConfigEngine.ReplaceEnvironmentVariables(mod.Value);
                LogUtilities.LogKeyValue("TYPE", "ADD", 27, MessageImportance.High, log);
                LogModificationDetails(mod.section, mod.key, mod.Value, string.Empty, log);

                Add(mod);
            }

            foreach (IniUpdate mod in file.Update)
            {
                mod.Value = RenderConfigEngine.ReplaceEnvironmentVariables(mod.Value);
                LogUtilities.LogKeyValue("TYPE", "Update", 27, MessageImportance.High, log);
                LogModificationDetails(mod.section, mod.key, mod.Value, string.Empty, log);
                Update(mod);
            }

            foreach (IniReplace mod in file.Replace)
            {
                mod.Value = RenderConfigEngine.ReplaceEnvironmentVariables(mod.Value);
                LogUtilities.LogKeyValue("TYPE", "ADD", 27, MessageImportance.High, log);
                LogModificationDetails(string.Empty, string.Empty, mod.Value, mod.regex, log);
                LogUtilities.LogCount(RenderConfigEngine.ReplaceTokenInFile(mod.regex, mod.Value, targetFile), log);
            }

            foreach (IniDelete mod in file.Delete)
            {
                LogUtilities.LogKeyValue("TYPE", "DELETE", 27, MessageImportance.High, log);
                LogModificationDetails(mod.section, mod.key, string.Empty, string.Empty, log);
                Delete(mod);
            }

            //HACK BAd
            returnCode = true;
            return(returnCode);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Logs the modification details.
 /// </summary>
 /// <param name="xpath">The xpath.</param>
 /// <param name="attribute">The attribute.</param>
 /// <param name="value">The value.</param>
 /// <param name="regex">The regex.</param>
 /// <param name="log">The log.</param>
 private static void LogModificationDetails(string xpath, string attribute, string value, string regex, IRenderConfigLogger log)
 {
     if (!String.IsNullOrEmpty(xpath))
     {
         LogUtilities.LogKeyValue("XPATH", xpath, 27, MessageImportance.Normal, log);
     }
     if (!String.IsNullOrEmpty(attribute))
     {
         LogUtilities.LogKeyValue("ATTRIBUTE", attribute, 27, MessageImportance.Normal, log);
     }
     if (!String.IsNullOrEmpty(value))
     {
         LogUtilities.LogKeyValue("VALUE", value, 27, MessageImportance.Normal, log);
     }
     if (!String.IsNullOrEmpty(regex))
     {
         LogUtilities.LogKeyValue("REGEX", regex, 27, MessageImportance.Normal, log);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Runs this instance.
        /// </summary>
        /// <returns></returns>
        public bool Run()
        {
            int count = 0;

            foreach (IniReplace mod in file.Replace)
            {
                mod.Value = RenderConfigEngine.ReplaceEnvironmentVariables(mod.Value);
                LogUtilities.LogKeyValue("TYPE", "REPLACE", 27, MessageImportance.High, log);
                LogUtilities.LogKeyValue("REGEX", mod.regex, 27, MessageImportance.Normal, log);
                LogUtilities.LogKeyValue("VALUE", mod.Value, 27, MessageImportance.Normal, log);
                count = RenderConfigEngine.ReplaceTokenInFile(mod.regex, mod.Value, targetFile);
                LogUtilities.LogCount(count, log);
            }
            //TODO
            if (config.BreakOnNoMatch && count == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }