/// <summary> /// Initializes a new instance of the <see cref="IniFileModifier"/> class. /// </summary> /// <param name="file">The file.</param> /// <param name="targetFile">The target file.</param> /// <param name="log">The log.</param> /// <param name="breakOnNoMatch">if set to <c>true</c> [break on no match].</param> public IniFileModifier(IniTargetFile file, string targetFile, IRenderConfigLogger log, RenderConfigConfig config) { this.file = file; this.log = log; this.config = config; this.targetFile = targetFile; }
/// <summary> /// Initializes a new instance of the <see cref="IniFileModifier"/> class. /// </summary> /// <param name="file">The file.</param> /// <param name="targetFile">The target file.</param> /// <param name="log">The log.</param> /// <param name="breakOnNoMatch">if set to <c>true</c> [break on no match].</param> public IniFileModifier(IniTargetFile file, string targetFile, IRenderConfigLogger log, RenderConfigConfig config) { this.file = file; this.log = log; this.config = config; this.targetFile = targetFile; }
/// <summary> /// Applies the specified config by passing through each set of modifications (in order, deterministic). /// </summary> /// <param name="config">The config.</param> /// <param name="inputLog">The input log.</param> /// <returns></returns> public Boolean Apply(RenderConfigConfig config, IRenderConfigLogger inputLog) { log = inputLog; Boolean returnCode = true; foreach (XmlTargetFile file in TargetFiles.XML) { CheckAndModifySourceAndDestination(config, file); //If we arent doing anything else, we are doing a straight copy... if (file.Add == null & file.Delete == null && file.Update == null && file.Replace == null) { log.LogMessage(MessageImportance.High, "TYPE = ".PadLeft(27) + "substitute"); RenderConfigEngine.Substitute(file, config.OutputDirectory); } else { IFileModifier fileModifier = new XmlFileModifier(file, RenderConfigEngine.ResolveAndCopyDestinationFilename(file, config.OutputDirectory, true), log, config); fileModifier.Run(); } } foreach (IniTargetFile file in TargetFiles.INI) { CheckAndModifySourceAndDestination(config, file); //If we arent doing anything else, we are doing a straight copy... //TODO possibly add all these checks as a boolean get{} on the partial class..so if (file.IsSimpleCopy) if (file.Add == null & file.Delete == null && file.Update == null && file.Replace == null) { log.LogMessage(MessageImportance.High, "TYPE = ".PadLeft(27) + "substitute"); RenderConfigEngine.Substitute(file, config.OutputDirectory); } else { IFileModifier fileModifier = new IniFileModifier(file, RenderConfigEngine.ResolveAndCopyDestinationFilename(file, config.OutputDirectory, true), log, config); fileModifier.Run(); } } foreach (TxtTargetFile file in TargetFiles.TXT) { CheckAndModifySourceAndDestination(config, file); //If we arent doing anything else, we are doing a straight copy... if (file.Replace == null) { log.LogMessage(MessageImportance.High, "TYPE = ".PadLeft(27) + "substitute"); RenderConfigEngine.Substitute(file, config.OutputDirectory); } else { IFileModifier fileModifier = new TxtFileModifier(file, RenderConfigEngine.ResolveAndCopyDestinationFilename(file, config.OutputDirectory, true), log, config); fileModifier.Run(); } } return(returnCode); }
/// <summary> /// Applies the specified config by passing through each set of modifications (in order, deterministic). /// </summary> /// <param name="config">The config.</param> /// <param name="inputLog">The input log.</param> /// <returns></returns> public Boolean Apply(RenderConfigConfig config, IRenderConfigLogger inputLog) { log = inputLog; Boolean returnCode = true; foreach (XmlTargetFile file in TargetFiles.XML) { CheckAndModifySourceAndDestination(config, file); //If we arent doing anything else, we are doing a straight copy... if (file.Add == null & file.Delete == null && file.Update == null && file.Replace == null) { log.LogMessage(MessageImportance.High, "TYPE = ".PadLeft(27) + "substitute"); RenderConfigEngine.Substitute(file, config.OutputDirectory); } else { IFileModifier fileModifier = new XmlFileModifier(file, RenderConfigEngine.ResolveAndCopyDestinationFilename(file, config.OutputDirectory, true), log, config); fileModifier.Run(); } } foreach (IniTargetFile file in TargetFiles.INI) { CheckAndModifySourceAndDestination(config, file); //If we arent doing anything else, we are doing a straight copy... //TODO possibly add all these checks as a boolean get{} on the partial class..so if (file.IsSimpleCopy) if (file.Add == null & file.Delete == null && file.Update == null && file.Replace == null) { log.LogMessage(MessageImportance.High, "TYPE = ".PadLeft(27) + "substitute"); RenderConfigEngine.Substitute(file, config.OutputDirectory); } else { IFileModifier fileModifier = new IniFileModifier(file, RenderConfigEngine.ResolveAndCopyDestinationFilename(file, config.OutputDirectory, true), log, config); fileModifier.Run(); } } foreach (TxtTargetFile file in TargetFiles.TXT) { CheckAndModifySourceAndDestination(config, file); //If we arent doing anything else, we are doing a straight copy... if (file.Replace == null) { log.LogMessage(MessageImportance.High, "TYPE = ".PadLeft(27) + "substitute"); RenderConfigEngine.Substitute(file, config.OutputDirectory); } else { IFileModifier fileModifier = new TxtFileModifier(file, RenderConfigEngine.ResolveAndCopyDestinationFilename(file, config.OutputDirectory, true), log, config); fileModifier.Run(); } } return returnCode; }
/// <summary> /// Logs the RenderConfigConfig settings provided to the IRenderConfigLogger instance passed in. /// </summary> /// <param name="config">The config.</param> /// <param name="log">The log.</param> public static void LogSettings(RenderConfigConfig config, IRenderConfigLogger log) { log.LogMessage("--------------------------------------------------------"); log.LogMessage(string.Concat("Config File = ".PadLeft(30) + config.ConfigFile)); log.LogMessage(string.Concat("Configuration = ".PadLeft(30) + config.Configuration)); log.LogMessage(string.Concat("Input Directory = ".PadLeft(30) + config.InputDirectory)); log.LogMessage(string.Concat("Output Directory = ".PadLeft(30) + config.OutputDirectory)); log.LogMessage(string.Concat("Delete Output Directory = ".PadLeft(30) + config.DeleteOutputDirectory)); log.LogMessage(string.Concat("Break On No Match = ".PadLeft(30) + config.BreakOnNoMatch)); log.LogMessage(string.Concat("Clean XML Output = ".PadLeft(30) + config.CleanOutput)); log.LogMessage(string.Concat("Preserve Source Structure = ".PadLeft(30) + config.PreserveSourceStructure)); log.LogMessage(string.Concat("Subdirectory per Config = ".PadLeft(30) + config.SubDirectoryEachConfiguration)); log.LogMessage("--------------------------------------------------------"); }
/// <summary> /// Logs the RenderConfigConfig settings provided to the IRenderConfigLogger instance passed in. /// </summary> /// <param name="config">The config.</param> /// <param name="log">The log.</param> public static void LogSettings(RenderConfigConfig config, IRenderConfigLogger log) { log.LogMessage("--------------------------------------------------------"); log.LogMessage(string.Concat("Config File = ".PadLeft(30) + config.ConfigFile)); log.LogMessage(string.Concat("Configuration = ".PadLeft(30) + config.Configuration)); log.LogMessage(string.Concat("Input Directory = ".PadLeft(30) + config.InputDirectory)); log.LogMessage(string.Concat("Output Directory = ".PadLeft(30) + config.OutputDirectory)); log.LogMessage(string.Concat("Delete Output Directory = ".PadLeft(30) + config.DeleteOutputDirectory)); log.LogMessage(string.Concat("Break On No Match = ".PadLeft(30) + config.BreakOnNoMatch)); log.LogMessage(string.Concat("Clean XML Output = ".PadLeft(30) + config.CleanOutput)); log.LogMessage(string.Concat("Preserve Source Structure = ".PadLeft(30) + config.PreserveSourceStructure)); log.LogMessage(string.Concat("Subdirectory per Config = ".PadLeft(30) + config.SubDirectoryEachConfiguration)); log.LogMessage("--------------------------------------------------------"); }
/// <summary> /// Initializes a new instance of the <see cref="XmlFileModifier"/> class. /// </summary> public XmlFileModifier(XmlTargetFile file, string targetFile, IRenderConfigLogger log, RenderConfigConfig config) { this.file = file; this.log = log; this.config = config; this.targetFile = targetFile; //Get the document and set up the XmlReaderSettings document = new XmlDocument(); settings = GetXmlReaderSettings(config.CleanOutput, document); using (XmlReader xml = XmlReader.Create(targetFile, settings)) { document.Load(xml); } }
/// <summary> /// Initializes a new instance of the <see cref="XmlFileModifier"/> class. /// </summary> public XmlFileModifier(XmlTargetFile file, string targetFile, IRenderConfigLogger log, RenderConfigConfig config) { this.file = file; this.log = log; this.config = config; this.targetFile = targetFile; //Get the document and set up the XmlReaderSettings document = new XmlDocument(); settings = GetXmlReaderSettings(config.CleanOutput, document); using (XmlReader xml = XmlReader.Create(targetFile, settings)) { document.Load(xml); } }
/// <summary> /// Check and modify source and destination file based on input and output directory existence, and a set of configuration values /// </summary> /// <param name="config">The config.</param> /// <param name="file">The file.</param> private void CheckAndModifySourceAndDestination(RenderConfigConfig config, ITargetFile file) { //Check to see if we want to preserve the directory structure.... file.source = CleansePlatformSpecificDirectoryMarkers(file.source); FileInfo t = new FileInfo(file.source); if (config.PreserveSourceStructure) { if (file.destination == null) { file.destination = file.source; } else { //TODO This is broken if (file.source.IndexOf(t.Name) != Path.DirectorySeparatorChar) { char badSep = file.source[file.source.IndexOf(t.Name)]; file.source.Replace(badSep, Path.DirectorySeparatorChar); } file.destination = Path.Combine(file.source.Replace(t.Name, string.Empty), file.destination); } } //Now check to see if the input directory has been provided, and modify the file object to represent the change of relative path if so if (config.InputDirectory != null) { file.source = Path.Combine(config.InputDirectory, file.source); } else { file.source = t.FullName; } LogUtilities.LogTargetFileHeader(file.source, file.destination, config.InputDirectory, config.OutputDirectory, log); //Check if it exists now... if (!File.Exists(file.source)) { throw new Exception("Could not find source file " + file.source); } }
public static Boolean RunAllConfigurations(RenderConfigConfig config, IRenderConfigLogger log) { Boolean returnBool = false; if (config.Configuration.Contains(",")) { string[] configs = config.Configuration.Split(','); foreach (string configToRun in configs) { RenderConfigConfig newConfig = (RenderConfigConfig)config.Clone(); newConfig.Configuration = configToRun; if (config.SubDirectoryEachConfiguration) { newConfig.OutputDirectory = Path.Combine(newConfig.OutputDirectory, configToRun); } RenderConfigEngine engine = new RenderConfigEngine(newConfig, log); returnBool = engine.Render(); } } else { if (config.SubDirectoryEachConfiguration) { if (!String.IsNullOrEmpty(config.OutputDirectory)) { config.OutputDirectory = Path.Combine(config.OutputDirectory, config.Configuration); } else { config.OutputDirectory = config.Configuration; } } RenderConfigEngine engine = new RenderConfigEngine(config, log); return(engine.Render()); } return(returnBool); }
/// <summary> /// When overridden in a derived class, executes the task. /// </summary> /// <returns> /// true if the task successfully executed; otherwise, false. /// </returns> public override bool Execute() { RenderConfigConfig config = new RenderConfigConfig(); config.BreakOnNoMatch = breakOnNoMatch; config.CleanOutput = cleanOutput; config.ConfigFile = configFile; config.Configuration = configuration; config.DeleteOutputDirectory = deleteOutputDirectory; config.OutputDirectory = outputDirectory; config.InputDirectory = inputDirectory; config.SubDirectoryEachConfiguration = SubDirectoryEachConfiguration; config.PreserveSourceStructure = PreserveSourceStructure; IRenderConfigLogger log = new MSBuildLogger(Log); Boolean returnVal = true; try { RenderConfigEngine.RunAllConfigurations(config, log); } catch (Exception i) { log.LogError("Failed to render configuration : " + i.Message); return false; } return returnVal; }
/// <summary> /// Initializes a new instance of the <see cref="RenderConfigEngine"/> class. /// </summary> /// <param name="config">The config.</param> /// <param name="log">The IRenderConfigLogger to use.</param> public RenderConfigEngine(RenderConfigConfig config, IRenderConfigLogger log) { this.log = log; this.config = config; }
/// <summary> /// Main application entry point. /// </summary> /// <param name="args">The args.</param> static void Main(string[] args) { Boolean showHelp = false; Boolean showVersion = false; //Boolean verbose = false; RenderConfigConfig config = new RenderConfigConfig(); config.DeleteOutputDirectory = false; config.CleanOutput = false; config.BreakOnNoMatch = false; config.PreserveSourceStructure = false; config.SubDirectoryEachConfiguration = false; OptionSet options = null; try { options = new OptionSet() //.Add("v|verbose", "Not yet implemented", delegate(string v) { if (v != null) verbose = true; }) .Add("?|h|help", "Show this message and exit", delegate(string v) { if (v != null) showHelp = true; }) .Add("f=|file=", "File containing configuration", delegate(string v) { if (v != null) { config.ConfigFile = v; } else { throw new OptionException("Missing Configuration File", "f|file"); } }) .Add("c=|configuration=", "Target configuration", delegate(string v) { if (v != null) config.Configuration = v; else throw new OptionException("Missing Configuration", "c|configuration"); }) .Add("o=|output=", "Target output directory", delegate(string v) { if (v != null) { config.OutputDirectory = v; } else { throw new OptionException("Missing Output Directory", "o|output"); } }) .Add("i=|input=", "The input directory to use as the base for all relative source file paths", delegate(string v) { if (v != null) config.InputDirectory = v; }) .Add("d|deleteoutput", "Delete target output directory", delegate(string v) { if (v != null) config.DeleteOutputDirectory = true; }) .Add("l|clean", "Clean XML output files", delegate(string v) { if (v != null) config.CleanOutput = true; }) .Add("b|break", "Break on no match", delegate(string v) { if (v != null) config.BreakOnNoMatch = true; }) .Add("p|preserve", "Preserve source directory structure when outputting", delegate(string v) { if (v != null) config.PreserveSourceStructure = true; }) .Add("v|version", "Output the version", delegate(string v) { if (v != null) showVersion = true; }) .Add("s|subdirperconfig", "Output each configuration to a sub-directory under the output directory.", delegate(string v) { if (v != null) config.SubDirectoryEachConfiguration = true; }); options.Parse(args); } catch (OptionException e) { System.Console.WriteLine(); System.Console.WriteLine(e.Message); System.Console.WriteLine(); options.WriteOptionDescriptions(System.Console.Out); System.Console.ResetColor(); System.Environment.Exit(1); } if (showVersion) { ReportExeAndVersion(); System.Console.ResetColor(); System.Environment.Exit(1); } if (showHelp || args.Length == 0) { ReportExeAndVersion(); System.Console.WriteLine("Renders stuff"); options.WriteOptionDescriptions(System.Console.Out); System.Console.ResetColor(); System.Environment.Exit(1); } //HACK This is not right, shouldnt NDesk.Options be hanlding this shit???? if (config.OutputDirectory == null && !config.SubDirectoryEachConfiguration) { OutputArgumentError(options, "Please provide either an output directory or specify -s for a subdirectory per configuration"); } if (config.Configuration == null) { OutputArgumentError(options, "Please provide a target configuration"); } if (config.ConfigFile == null) { OutputArgumentError(options, "Please provide a config file to parse"); } try { IRenderConfigLogger log = new ConsoleLogger(); RenderConfigEngine.RunAllConfigurations(config, log); } catch (Exception i) { System.Console.WriteLine(); System.Console.WriteLine("Encountered error: " + i.Message); System.Console.WriteLine(); } System.Console.ResetColor(); }
/// <summary> /// Check and modify source and destination file based on input and output directory existence, and a set of configuration values /// </summary> /// <param name="config">The config.</param> /// <param name="file">The file.</param> private void CheckAndModifySourceAndDestination(RenderConfigConfig config, ITargetFile file) { //Check to see if we want to preserve the directory structure.... file.source = CleansePlatformSpecificDirectoryMarkers(file.source); FileInfo t = new FileInfo(file.source); if (config.PreserveSourceStructure) { if (file.destination == null) { file.destination = file.source; } else { //TODO This is broken if (file.source.IndexOf(t.Name) != Path.DirectorySeparatorChar) { char badSep = file.source[file.source.IndexOf(t.Name)]; file.source.Replace(badSep,Path.DirectorySeparatorChar); } file.destination = Path.Combine(file.source.Replace(t.Name, string.Empty), file.destination); } } //Now check to see if the input directory has been provided, and modify the file object to represent the change of relative path if so if (config.InputDirectory != null) { file.source = Path.Combine(config.InputDirectory, file.source); } else { file.source = t.FullName; } LogUtilities.LogTargetFileHeader(file.source, file.destination, config.InputDirectory,config.OutputDirectory, log); //Check if it exists now... if (!File.Exists(file.source)) { throw new Exception("Could not find source file " + file.source); } }
public static Boolean RunAllConfigurations(RenderConfigConfig config, IRenderConfigLogger log) { Boolean returnBool = false; if (config.Configuration.Contains(",")) { string[] configs = config.Configuration.Split(','); foreach (string configToRun in configs) { RenderConfigConfig newConfig = (RenderConfigConfig)config.Clone(); newConfig.Configuration = configToRun; if (config.SubDirectoryEachConfiguration) { newConfig.OutputDirectory = Path.Combine(newConfig.OutputDirectory, configToRun); } RenderConfigEngine engine = new RenderConfigEngine(newConfig, log); returnBool = engine.Render(); } } else { if (config.SubDirectoryEachConfiguration) { if (!String.IsNullOrEmpty(config.OutputDirectory)) { config.OutputDirectory = Path.Combine(config.OutputDirectory, config.Configuration); } else { config.OutputDirectory = config.Configuration; } } RenderConfigEngine engine = new RenderConfigEngine(config, log); return engine.Render(); } return returnBool; }
/// <summary> /// Initializes a new instance of the <see cref="RenderConfigEngine"/> class. /// </summary> /// <param name="config">The config.</param> /// <param name="log">The IRenderConfigLogger to use.</param> public RenderConfigEngine(RenderConfigConfig config, IRenderConfigLogger log) { this.log = log; this.config = config; }