/// <summary> /// Creates a ConfigManager instance from given xml settings file. /// </summary> /// <param name="logger">The logger instance, so errors can be logged.</param> /// <param name="xml">The XML document to parse.</param> /// <returns>An instance of teh ConfigManager.</returns> public static ConfigManager CreateFromXML(ILogger logger, XmlDocument xml) { string reportFolder = "", sampleFolder = "", resultFolder = "", ccextractorLocation = "", ffmpeg = ""; CompareType compare = CompareType.Diffplex; bool useThreading = false, breakErrors = false; foreach (XmlNode n in xml.SelectNodes("configuration/appSettings/add")) { string key = n.Attributes["key"].Value; string value = n.Attributes["value"].Value; switch (key) { case "ReportFolder": reportFolder = value; break; case "SampleFolder": sampleFolder = value; break; case "CorrectResultFolder": resultFolder = value; break; case "CCExtractorLocation": ccextractorLocation = value; break; case "FFMpegLocation": ffmpeg = value; break; case "Comparer": try { compare = CompareTypeParser.parseString(value); } catch (ArgumentOutOfRangeException) { logger.Warn("Could not parse the Comparer value from the xml. Will be using the default setting"); } break; case "UseThreading": useThreading = bool.Parse(value); break; case "BreakOnErrors": breakErrors = bool.Parse(value); break; default: logger.Warn("Unknown key " + key + " encountered; ignoring."); break; } } return(new ConfigManager(reportFolder, sampleFolder, resultFolder, ccextractorLocation, compare, useThreading, breakErrors, ffmpeg)); }
/// <summary> /// Creates a ConfigManager instance from the app.config file (if it exists). /// </summary> /// <param name="logger">The logger instance, so errors can be logged.</param> /// <returns>An instance of teh ConfigManager.</returns> public static ConfigManager CreateFromAppSettings(ILogger logger) { Configuration c = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string reportFolder = "", sampleFolder = "", resultFolder = "", ccextractorLocation = "", ffmpeg = ""; CompareType compare = CompareType.Diffplex; bool useThreading = false, breakErrors = false; foreach (KeyValueConfigurationElement kce in c.AppSettings.Settings) { switch (kce.Key) { case "ReportFolder": reportFolder = kce.Value; break; case "SampleFolder": sampleFolder = kce.Value; break; case "CorrectResultFolder": resultFolder = kce.Value; break; case "CCExtractorLocation": ccextractorLocation = kce.Value; break; case "FFMpegLocation": ffmpeg = kce.Value; break; case "Comparer": try { compare = CompareTypeParser.parseString(kce.Value); } catch (ArgumentOutOfRangeException) { logger.Warn("Could not parse the Comparer value from the config. Will be using the default setting"); } break; case "UseThreading": useThreading = bool.Parse(kce.Value); break; case "BreakOnErrors": breakErrors = bool.Parse(kce.Value); break; default: logger.Warn("Unknown key " + kce.Key + " encountered; ignoring."); break; } } return(new ConfigManager(reportFolder, sampleFolder, resultFolder, ccextractorLocation, compare, useThreading, breakErrors, ffmpeg)); }
/// <summary> /// The entry point of the program, where the program control starts and ends. /// </summary> /// <param name="args">The command-line arguments.</param> public static void Main(string[] args) { Assembly a = Assembly.GetExecutingAssembly(); String location = a.Location; location = location.Remove(location.LastIndexOf(Path.DirectorySeparatorChar)); Logger = new ConsoleFileLogger(Path.Combine(location, "logs")); var options = new Options(); if (Parser.Default.ParseArguments(args, options)) { Logger.Info("Starting test suite for CCExtractor - If you encounter any issues using this program, don't hesitate to ask questions or report problems on GitHub. Please don't forget to attach logs (enable extensive logging using the -debug flag)."); Logger.Info("Test suite version: " + a.GetName().Version.ToString()); if (options.Debug) { Logger.ActivateDebug(); Logger.Debug("Debug activated"); } Logger.Info(""); Logger.Info("If you want to see the available flags, run this program with --help. Press ctrl-c to abort if necessary."); Logger.Info(""); // Loading configuration ConfigManager config = null; if (!String.IsNullOrEmpty(options.ConfigFile) && options.ConfigFile.EndsWith(".xml") && File.Exists(options.ConfigFile)) { Logger.Info("Loading provided configuration (" + options.ConfigFile + ")"); XmlDocument doc = new XmlDocument(); doc.Load(options.ConfigFile); config = ConfigManager.CreateFromXML(Logger, doc); } else { Logger.Warn("Provided no config or an invalid one; reverting to default config (" + a.GetName().Name + ".exe.config)"); config = ConfigManager.CreateFromAppSettings(Logger); } if (config == null || !config.IsValidConfig()) { Logger.Error("Fatal error - config not valid. Please check. Exiting application"); return; } String temporaryFolder = Path.Combine(location, "tmpFiles"); if (!String.IsNullOrEmpty(options.TempFolder) && IsValidDirectory(options.TempFolder)) { temporaryFolder = options.TempFolder; } else { if (!Directory.Exists(temporaryFolder)) { Logger.Warn(temporaryFolder + " does not exist; trying to create it"); DirectoryInfo di = Directory.CreateDirectory(temporaryFolder); if (!di.Exists) { Logger.Error("Failed to create the directory! Exiting"); return; } } } config.TemporaryFolder = temporaryFolder; Logger.Info("Generated result files will be stored in " + temporaryFolder + "(when running multiple tests after another, files might be overwritten)"); // See what overrides are specified if (!String.IsNullOrEmpty(options.CCExtractorExecutable)) { if (File.Exists(options.CCExtractorExecutable)) { config.CCExctractorLocation = options.CCExtractorExecutable; Logger.Info("Overriding CCExtractorLocation with given version (located at: " + options.CCExtractorExecutable + ")"); } else { Logger.Error("Given CCExtractor executable path does not exist. Exiting application"); return; } } if (options.TimeOut > 60 && options.TimeOut != 180) { config.TimeOut = options.TimeOut; Logger.Info("Overriding timeout with: " + options.TimeOut); } if (!String.IsNullOrEmpty(options.Comparer)) { try { config.Comparer = CompareTypeParser.parseString(options.Comparer); Logger.Info("Overriding Comparer with: " + options.Comparer); } catch (ArgumentOutOfRangeException) { Logger.Warn("Provided value for comparer invalid; ignoring it."); } } if (!String.IsNullOrEmpty(options.ReportFolder)) { config.ReportFolder = options.ReportFolder; Logger.Info("Overriding ReportFolder with: " + options.ReportFolder); } if (!String.IsNullOrEmpty(options.ResultFolder)) { config.ResultFolder = options.ResultFolder; Logger.Info("Overriding ResultFolder with: " + options.ResultFolder); } if (!String.IsNullOrEmpty(options.SampleFolder)) { config.SampleFolder = options.SampleFolder; Logger.Info("Overriding SampleFolder with: " + options.SampleFolder); } config.BreakOnChanges = options.BreakOnChanges; if (config.BreakOnChanges) { Logger.Info("If there's a sample that doesn't match, we will exit instead of running them all."); } if (!String.IsNullOrEmpty(options.FFMpegExecutable)) { if (File.Exists(options.FFMpegExecutable)) { config.FFMpegLocation = options.FFMpegExecutable; Logger.Info("Overriding FFMpeg executable with given version (located at: " + options.FFMpegExecutable + ")"); } else { Logger.Error("Given CCExtractor executable path does not exist. Exiting application"); return; } } config.TestType = options.RunMethod; if (options.UseValgrind) { Logger.Info("Valgrind will be used to run tests with."); config.UseValgrind = true; } // Continue with parameter parsing switch (config.TestType) { case RunType.Matrix: Logger.Info("Running in report mode, generating matrix"); if (IsValidDirectory(options.EntryFile)) { StartMatrixGenerator(Logger, config, options.EntryFile); } else { Logger.Error("Invalid directory provided for matrix generation!"); } break; case RunType.Server: // Check if the URL was set if (!String.IsNullOrEmpty(options.ReportURL)) { Logger.Info("Setting report URL to provided value!"); config.ReportUrl = options.ReportURL; } if (String.IsNullOrEmpty(config.ReportUrl)) { Logger.Error("Server reporting mode selected, but no URL configured! Exiting."); break; } if (IsValidPotentialSampleFile(options.EntryFile)) { Logger.Info("Running provided file"); StartTester(Logger, config, options.EntryFile, location); } else { Logger.Error("No file (or invalid file) provided!"); } break; case RunType.Report: if (IsValidPotentialSampleFile(options.EntryFile)) { Logger.Info("Running provided file"); StartTester(Logger, config, options.EntryFile, location); } else { Logger.Error("No file (or invalid file) provided!"); } break; default: Logger.Error("Unknown RunType!"); break; } } }