/// <summary> /// Runs the specified args. /// </summary> /// <param name="args">The args.</param> public void Run(string[] args) { // Parse command line args: CommandLineArgsParser parser = new CommandLineArgsParser(); string errorMessage; if (!parser.ParseArguments(args, out errorMessage)) { if (!string.IsNullOrWhiteSpace(errorMessage)) { System.Console.WriteLine(@"ERROR: " + errorMessage); System.Console.WriteLine(); } parser.PrintHelp(); return; } try { // Read Project File: Stream openFileStream = new FileStream(parser.ProjectPath, FileMode.Open); XmlSerializer serializer = new XmlSerializer(typeof (ReplacerProject)); XmlReader reader = new XmlTextReader(openFileStream); if (!serializer.CanDeserialize(reader)) { System.Console.WriteLine(@"Invalid Project file"); openFileStream.Close(); return; } ReplacerProject project = (ReplacerProject) serializer.Deserialize(reader); openFileStream.Close(); // Setup logging: this.logToConsole = parser.LogToConsole; if (!string.IsNullOrWhiteSpace(parser.LogFilePath)) { this.logFile = new StreamWriter(parser.LogFilePath, true, Encoding.UTF8); } // Process: // Create replace parameters: ReplaceParameters parameters = new ReplaceParameters { FileCrawlerParameters = {PathInfoList = project.FileFolderPaths.ToList()}, ReplacePatterns = project.PatternList.ToList() }; // Initialize replacer: Business.Engine.Replacer replacer = new Business.Engine.Replacer(); replacer.AddObserver(this); // Start process: replacer.Replace(parameters); } catch (Exception exc) { if (!this.logToConsole) System.Console.WriteLine(exc); this.Log(new LogMessage { TimeStamp = DateTime.Now, Message = exc.ToString() }); } finally { if (this.logFile != null) this.logFile.Close(); } }
/// <summary> /// Runs the specified args. /// </summary> /// <param name="args">The args.</param> public void Run(string[] args) { // Parse command line args: CommandLineArgsParser parser = new CommandLineArgsParser(); string errorMessage; if (!parser.ParseArguments(args, out errorMessage)) { if (!string.IsNullOrWhiteSpace(errorMessage)) { System.Console.WriteLine(@"ERROR: " + errorMessage); System.Console.WriteLine(); } parser.PrintHelp(); return; } try { // Read Project File: Stream openFileStream = new FileStream(parser.ProjectPath, FileMode.Open); XmlSerializer serializer = new XmlSerializer(typeof(ReplacerProject)); XmlReader reader = new XmlTextReader(openFileStream); if (!serializer.CanDeserialize(reader)) { System.Console.WriteLine(@"Invalid Project file"); openFileStream.Close(); return; } ReplacerProject project = (ReplacerProject)serializer.Deserialize(reader); openFileStream.Close(); // Setup logging: this.logToConsole = parser.LogToConsole; if (!string.IsNullOrWhiteSpace(parser.LogFilePath)) { this.logFile = new StreamWriter(parser.LogFilePath, true, Encoding.UTF8); } // Process: // Create replace parameters: ReplaceParameters parameters = new ReplaceParameters { FileCrawlerParameters = { PathInfoList = project.FileFolderPaths.ToList() }, ReplacePatterns = project.PatternList.ToList() }; // Initialize replacer: Business.Engine.Replacer replacer = new Business.Engine.Replacer(); replacer.AddObserver(this); // Start process: replacer.Replace(parameters); } catch (Exception exc) { if (!this.logToConsole) { System.Console.WriteLine(exc); } this.Log(new LogMessage { TimeStamp = DateTime.Now, Message = exc.ToString() }); } finally { if (this.logFile != null) { this.logFile.Close(); } } }