public static void Main(string[] args) { try { Options commandLineOptions = new Options(); ICommandLineParser commandParser = new CommandLineParser(); if (commandParser.ParseArguments(args, commandLineOptions, Console.Error)) { if (ValidateOptions(commandLineOptions)) { RequestProcessor duplicateProcessor = new RequestProcessor(); duplicateProcessor.FindDuplicates(commandLineOptions); } } else { // Command line params could not be parsed, // or help was requested Environment.ExitCode = -1; } } catch { // Something totally unexpected happened - // catch the exception so the whole process // doesn't come crashing down if this is // being run in a batch file Console.Error.WriteLine(messageUnexpectedInternalError); Environment.ExitCode = -2; } }
public void FindDuplicates(Options commandLineOptions) { CloneFinderCore.DirectoryWalker duplicateWalker = new CloneFinderCore.DirectoryWalker(commandLineOptions.Items[0]); if (commandLineOptions.progressIndicator) { duplicateWalker.FileProcessed += new EventHandler<CloneFinderCore.DirectoryWalkEventArgs>(duplicateWalker_FileProcessed); duplicateWalker.DirectoryWalkComplete += new EventHandler<CloneFinderCore.DirectoryWalkEventArgs>(duplicateWalker_DirectoryWalkComplete); } Collection<CloneFinderCore.ProcessedFileInfo> duplicateFiles = duplicateWalker.WalkDirectory(); WriteResults(duplicateFiles, commandLineOptions.csvOutput); }
private static bool ValidateOptions(Options commandLineOptions) { bool validatedOK = true; StringBuilder errorMessage = new StringBuilder(); // Make sure we've been passed valid path(s), // and that we have read permissions if (commandLineOptions.Items.Count > 0) { // only going to run the loop once - // leaving this here for future enhancement which // will allow multiple paths to be specified for (int loop = 0; loop < 1; loop++) { if (!Directory.Exists(commandLineOptions.Items[loop])) { validatedOK = false; errorMessage.AppendFormat(messagePathNotFound, commandLineOptions.Items[loop]); errorMessage.AppendLine(); } } } else { // No path to search was specified validatedOK = false; errorMessage.AppendLine(); errorMessage.Append(messageNoPathSpecified); } if (!validatedOK) { // Tell the user there was a problem // and we're not going to find // their precious duplicates Console.Error.WriteLine(errorMessage.ToString()); Environment.ExitCode = 1; } return validatedOK; }