static void Main(string[] args)
        {
            var options = new CommandLineOptions();
            var result  = Parser.Default.ParseArguments <CommandLineOptions>(args);

            result.WithParsed(a => {
                if (a.CultureInfoName != null)
                {
                    Global.StringUtilities.ci = new CultureInfo(a.CultureInfoName, true);
                }
                string json = ReadFile(a.ConfigPath);
                JsonConfigLoader jsonConfigLoader = new JsonConfigLoader();
                Sitplugin sitplugin = jsonConfigLoader.Load(json);
                try
                {
                    sitplugin.Import(a.AppendMode);
                }
                catch (CBMSIT.ProjectCreation.ProjectCreationException ex)
                {
                    System.Console.WriteLine(ex.Message);
                    throw ex;
                }
            });
        }
Example #2
0
        public void Import(string jsonConfigTemplatePath, string outputPath,
                           string inputPath)
        {
            string json = "";

            using (var s = File.OpenRead(jsonConfigTemplatePath))
                using (StreamReader reader = new StreamReader(s))
                {
                    json = reader.ReadToEnd();
                }
            JObject jsonObj = JObject.Parse(json);

            jsonObj["output_path"]           = outputPath;
            jsonObj["import_config"]["path"] = inputPath;
            var loader = new StandardImportToolPlugin.JsonConfigLoader();

            log.Info(string.Format("running Operational-Scale CBM-CFS3" +
                                   " Standard import tool. input database {0}", inputPath));
            Sitplugin sitplugin = loader.Load(jsonObj.ToString());

            sitplugin.Import();
            log.Info(string.Format("finished standard import tool. CBM" +
                                   " project db: {0}", outputPath));
        }
        /// <summary>
        /// use a json configuration
        /// </summary>
        private static void Method3()
        {
            //creates a config object equivalent to Method1
            var config = new
            {
                output_path   = @"C:\Program Files (x86)\Operational-Scale CBM-CFS3\Projects\tutorial6_json\tutorial6_json.mdb",
                import_config = new
                {
                    path = @"C:\Program Files (x86)\Operational-Scale CBM-CFS3\Tutorials\Tutorial 6\Tutorial6.xls",
                    ageclass_table_name           = "AgeClasses$",
                    classifiers_table_name        = "Classifiers$",
                    disturbance_events_table_name = "DistEvents$",
                    disturbance_types_table_name  = "DistType$",
                    inventory_table_name          = "Inventory$",
                    transition_rules_table_name   = "Transitions$",
                    yield_table_name = "Growth$"
                },
                mapping_config = new
                {
                    spatial_units = new
                    {
                        mapping_mode  = "SingleDefaultSpatialUnit",
                        default_spuid = 42
                    },
                    disturbance_types = new
                    {
                        disturbance_type_mapping = new[]
                        {
                            new { user_dist_type = "Fire", default_dist_type = "Wildfire" },
                            new { user_dist_type = "Firewood collection", default_dist_type = "Firewood Collection - post logging" },
                            new { user_dist_type = "Clearcut", default_dist_type = "Clear-cut with slash-burn" },
                            new { user_dist_type = "Afforestation", default_dist_type = "Afforestation" },
                            new { user_dist_type = "Hurricane", default_dist_type = "Generic 50% mortality" },
                        }
                    },
                    species = new
                    {
                        species_classifier = "Species",
                        species_mapping    = new[]
                        {
                            new { user_species = "Hispaniolan pine", default_species = "Pine" },
                            new { user_species = "Nonforest", default_species = "Not stocked" },
                            new { user_species = "Improved pine stock", default_species = "Pine" }
                        }
                    },
                    nonforest = new
                    {
                        nonforest_classifier = "Forest type",
                        nonforest_mapping    = new[]
                        {
                            new { user_nonforest_type = "Afforestation", default_nonforest_type = "Gleysolic" },
                            new { user_nonforest_type = "Natural forest", default_nonforest_type = Sitplugin.ForestOnly },
                            new { user_nonforest_type = "Control", default_nonforest_type = Sitplugin.ForestOnly }
                        }
                    }
                }
            };
            var              jsonObject       = JObject.FromObject(config);
            string           json             = jsonObject.ToString(Newtonsoft.Json.Formatting.Indented);
            JsonConfigLoader jsonConfigLoader = new JsonConfigLoader();
            Sitplugin        sitplugin        = jsonConfigLoader.Load(json);

            sitplugin.Import();
        }