// Parse command line arguments and return true if values are valid. // Otherwise log errors and return false. public bool ValidArgumentValues(Options opts) { try { if (opts.using_test_data) { // Set up array of source ids to reflect // those in the test data set. opts.source_ids = _test_repo.ObtainTestSourceIDs(); return(true); // Should always be able to run } else { if (opts.source_ids.Count() == 0) { throw new ArgumentException("No source id provided"); } foreach (int source_id in opts.source_ids) { if (!_mon_repo.SourceIdPresent(source_id)) { throw new ArgumentException("Source argument " + source_id.ToString() + " does not correspond to a known source"); } } return(true); // Got this far - the program can run! } } catch (Exception e) { _logger.Error(e.Message); _logger.Error(e.StackTrace); _logger.Information("Harvester application aborted"); _logger_helper.Logheader("Closing Log"); return(false); } }
// Parse command line arguments and return true if values are valid. // Otherwise log errors and return false. public bool ValidArgumentValues(Options opts) { try { if (opts.setup_expected_data_only) { // Set the 'manual input of test data' source id. List <int> ids = new List <int>(); ids.Add(999999); opts.source_ids = ids; opts.harvest_type_id = 3; opts.org_update_only = false; return(true); // can always run if -E parameter present } else if (opts.harvest_all_test_data) { // Set up array of source ids to reflect // those in the test data set. opts.source_ids = _test_repo.ObtainTestSourceIDs(); opts.harvest_type_id = 3; opts.org_update_only = false; return(true); // should always run if -F parameter present } else { // check valid harvest type id int harvest_type_id = opts.harvest_type_id; if (!opts.org_update_only) { if (harvest_type_id != 1 && harvest_type_id != 2 && harvest_type_id != 3) { throw new Exception("The t (harvest type) parameter is not one of the allowed values - 1,2 or 3"); } } // check the source(s) validity foreach (int source_id in opts.source_ids) { if (!_mon_repo.SourceIdPresent(source_id)) { throw new ArgumentException("Source argument " + source_id.ToString() + " does not correspond to a known source"); } } return(true); // Got this far - the program can run! } } catch (Exception e) { _logger.Error(e.Message); _logger.Error(e.StackTrace); _logger.Information("Harvester application aborted"); _logger_helper.LogHeader("Closing Log"); return(false); } }