Пример #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);
        }
Пример #2
0
 /// <summary>
 /// Logs the node count.
 /// </summary>
 /// <param name="nodes">The nodes.</param>
 /// <param name="breakOnNoMatch">if set to <c>true</c> [break on no match].</param>
 private void LogNodeCount(XmlNodeList nodes, Boolean breakOnNoMatch)
 {
     LogUtilities.LogCount(nodes.Count, log);
     if (breakOnNoMatch)
     {
         throw new Exception("Could not find match");
     }
 }
Пример #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);
        }
Пример #4
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);
            }
        }
Пример #5
0
 /// <summary>
 /// Logs the count of applied modifications.
 /// </summary>
 /// <param name="log">The log.</param>
 private void LogCount(IRenderConfigLogger log)
 {
     LogUtilities.LogCount(1, log);
 }