Exemple #1
0
        public int Run(Options opts)
        {
            try
            {
                _logger_helper.LogHeader("STARTING HARVESTER");
                _logger_helper.LogCommandLineParameters(opts);
                foreach (int source_id in opts.source_ids)
                {
                    HarvestData(source_id, opts);
                }
                _logger_helper.LogHeader("Closing Log");
                return(0);
            }

            catch (Exception e)
            {
                _logger.Error(e.Message);
                _logger.Error(e.StackTrace);
                _logger_helper.LogHeader("Closing Log");
                return(-1);
            }
        }
        // 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);
            }
        }