/// <summary> /// Load the configuration file. /// /// If the InputFile was specified on the command line, adjust the configuration to use it, /// otherwise change InputFile to reflect what was read in from the config file. /// /// Do the same for the OutputFile. /// </summary> /// <returns>The configuration.</returns> SlashConfig LoadConfig() { //TODO: Valid configuration, checking for existence of input file, config file. var definitionText = File.ReadAllText(ConfigFile); var configuration = SlashConfig.Deserialize(definitionText); if ((InputFile ?? "").Length != 0) { configuration.Data.InputDataFile = InputFile; } else { InputFile = configuration.Data.InputDataFile; } if ((OutputFile ?? "").Length != 0) { configuration.Output.OutputDataFile = OutputFile; } else { OutputFile = configuration.Output.OutputDataFile; } InitLogger(configuration); return(configuration); }
void InitLogger(SlashConfig configuration) { Logger.Instance.LogFile = configuration.Output.LogFile; Logger.Instance.Level = configuration.Output.LogLevel; Logger.Instance.WriteToFile = configuration.Output.LogFile.Length > 1; Logger.Instance.WriteToStandardOut = configuration.Output.LogFile.Equals("-"); Logger.Instance.WriteToStandardError = configuration.Output.LogFile.Equals("-"); }
/// <summary> /// Create a SlashCommand that is told which command to execute and is handed its configuration, /// so does not need to load it from a file. /// </summary> /// <param name="command">Command to execute.</param> /// <param name="configuration">Configuration tht specifies how the clustering is to be performed.</param> public SlashCommand(CommandType command, SlashConfig configuration) { Command = command; Configuration = configuration; InputFile = Configuration.Data.InputDataFile; OutputFile = Configuration.Output.OutputDataFile; InitLogger(Configuration); }
/// <summary> /// Execute the command, potentially reading the configuration file and data file and writing the output file. /// </summary> public void Execute() { var alreadyHaveConfig = Configuration != null; switch (Command) { case CommandType.Help: Console.WriteLine(HelpMessage); break; case CommandType.Version: Console.WriteLine($@"Slash Version {Version}"); break; case CommandType.Define: var definition = new SlashConfig(InputFile, OutputFile); File.WriteAllText(ConfigFile, definition.ToString()); break; case CommandType.Assess: if (!alreadyHaveConfig) { Configuration = LoadConfig(); } Assess(); Timer.Log(); break; case CommandType.Cluster: if (!alreadyHaveConfig) { Configuration = LoadConfig(); } Cluster(); Timer.Log(); break; case CommandType.Recluster: if (!alreadyHaveConfig) { Configuration = LoadConfig(); } Recluster(); Timer.Log(); break; } }