/// <summary> /// Create an initial conditions table in the DataStore. /// </summary> private void CreateInitialConditionsTable() { var initConditions = new DataTable("_InitialConditions"); initConditions.Columns.Add("SimulationName", typeof(string)); initConditions.Columns.Add("ModelPath", typeof(string)); initConditions.Columns.Add("Name", typeof(string)); initConditions.Columns.Add("Description", typeof(string)); initConditions.Columns.Add("DataType", typeof(string)); initConditions.Columns.Add("Units", typeof(string)); initConditions.Columns.Add("DisplayFormat", typeof(string)); initConditions.Columns.Add("Total", typeof(int)); initConditions.Columns.Add("Value", typeof(string)); string simulationPath = simulation.FullPath; var row = initConditions.NewRow(); row.ItemArray = new object[] { simulation.Name, simulationPath, "Simulation name", "Simulation name", "String", string.Empty, string.Empty, 0, simulation.Name }; initConditions.Rows.Add(row); row = initConditions.NewRow(); row.ItemArray = new object[] { simulation.Name, simulationPath, "APSIM version", "APSIM version", "String", string.Empty, string.Empty, 0, Simulations.GetApsimVersion() }; initConditions.Rows.Add(row); row = initConditions.NewRow(); row.ItemArray = new object[] { simulation.Name, simulationPath, "Run on", "Run on", "String", string.Empty, string.Empty, 0, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; initConditions.Rows.Add(row); // Get all model properties and store in 'initialConditionsTable' foreach (Model model in simulation.FindAllInScope()) { string thisRelativeModelPath = model.FullPath.Replace(simulationPath + ".", string.Empty); var properties = new List <Tuple <string, VariableProperty> >(); FindAllProperties(model, properties); foreach (var tuple in properties) { string propertyValue = tuple.Item2.ValueAsString(); if (propertyValue != string.Empty) { if (propertyValue != null && tuple.Item2.DataType == typeof(DateTime)) { propertyValue = ((DateTime)tuple.Item2.Value).ToString("yyyy-MM-dd HH:mm:ss"); } int total; if (double.IsNaN(tuple.Item2.Total)) { total = 0; } else { total = 1; } if (tuple.Item2.Units == null) { tuple.Item2.Units = string.Empty; } row = initConditions.NewRow(); row.ItemArray = new object[] { simulation.Name, thisRelativeModelPath, tuple.Item1, tuple.Item2.Description, tuple.Item2.DataType.Name, tuple.Item2.Units, tuple.Item2.Format, total, propertyValue }; initConditions.Rows.Add(row); } } } storage.Writer.WriteTable(initConditions); }
/// <summary> /// Write the APSIM version to the console. /// </summary> private static void WriteVersion() { Console.WriteLine(Simulations.GetApsimVersion()); }