Exemple #1
0
        private void OnSimulationCompleted(object sender, EventArgs e)
        {
            DataStore dataStore = new DataStore(this);

            dataStore.WriteTable(this.messagesTable);
            dataStore.Disconnect();
        }
Exemple #2
0
        /// <summary>
        /// Create an initial conditions table in the DataStore.
        /// </summary>
        /// <param name="simulation">The simulation to create an table for</param>
        private static void CreateInitialConditionsTable(Simulation simulation)
        {
            // Create our initial conditions table.
            DataTable initialConditionsTable = new DataTable("InitialConditions");

            initialConditionsTable.Columns.Add("ModelPath", typeof(string));
            initialConditionsTable.Columns.Add("Name", typeof(string));
            initialConditionsTable.Columns.Add("Description", typeof(string));
            initialConditionsTable.Columns.Add("DataType", typeof(string));
            initialConditionsTable.Columns.Add("Units", typeof(string));
            initialConditionsTable.Columns.Add("DisplayFormat", typeof(string));
            initialConditionsTable.Columns.Add("Total", typeof(int));
            initialConditionsTable.Columns.Add("Value", typeof(string));

            initialConditionsTable.Rows.Add(
                new object[] { Apsim.FullPath(simulation), "Simulation name", "Simulation name", "String", string.Empty, string.Empty, false, simulation.Name });

            // Get all model properties and store in 'initialConditionsTable'
            foreach (Model model in Apsim.FindAll(simulation))
            {
                string relativeModelPath           = Apsim.FullPath(model).Replace(Apsim.FullPath(simulation) + ".", string.Empty);
                List <VariableProperty> properties = new List <VariableProperty>();

                FindAllProperties(model, properties);

                foreach (VariableProperty property in properties)
                {
                    string value = property.ValueWithArrayHandling.ToString();
                    if (value != string.Empty)
                    {
                        if (value != null && property.DataType == typeof(DateTime))
                        {
                            value = ((DateTime)property.Value).ToString("yyyy-MM-dd hh:mm:ss");
                        }

                        bool showTotal = !double.IsNaN(property.Total);

                        initialConditionsTable.Rows.Add(new object[]
                        {
                            relativeModelPath,
                            property.Name,
                            property.Description,
                            property.DataType.Name,
                            property.Units,
                            property.Format,
                            showTotal,
                            value
                        });
                    }
                }
            }

            // Write to data store.
            DataStore dataStore = new DataStore(simulation);

            dataStore.DeleteOldContentInTable(simulation.Name, "InitialConditions");
            dataStore.WriteTable(simulation.Name, "InitialConditions", initialConditionsTable);
            dataStore.Disconnect();
        }
Exemple #3
0
        private void OnSimulationCompleted(object sender, EventArgs e)
        {
            DataStore dataStore = new DataStore(this);

            dataStore.DeleteOldContentInTable(this.Simulation.Name, "Messages");
            dataStore.WriteTable(this.Simulation.Name, "Messages", this.messagesTable);
            dataStore.Disconnect();
        }
Exemple #4
0
 private void OnSimulationCompleted(object sender, EventArgs e)
 {
     DataStore dataStore = new DataStore(this);
     dataStore.DeleteOldContentInTable(this.Simulation.Name, "Messages");
     dataStore.WriteTable(this.Simulation.Name, "Messages", this.messagesTable);
     dataStore.Disconnect();
 }
Exemple #5
0
        /// <summary>
        /// Create an initial conditions table in the DataStore.
        /// </summary>
        /// <param name="simulation">The simulation to create an table for</param>
        private static void CreateInitialConditionsTable(Simulation simulation)
        {
            // Create our initial conditions table.
            DataTable initialConditionsTable = new DataTable("InitialConditions");
            initialConditionsTable.Columns.Add("ModelPath", typeof(string));
            initialConditionsTable.Columns.Add("Name", typeof(string));
            initialConditionsTable.Columns.Add("Description", typeof(string));
            initialConditionsTable.Columns.Add("DataType", typeof(string));
            initialConditionsTable.Columns.Add("Units", typeof(string));
            initialConditionsTable.Columns.Add("DisplayFormat", typeof(string));
            initialConditionsTable.Columns.Add("Total", typeof(int));
            initialConditionsTable.Columns.Add("Value", typeof(string));

            initialConditionsTable.Rows.Add(
                new object[] { Apsim.FullPath(simulation), "Simulation name", "Simulation name", "String", string.Empty, string.Empty, false, simulation.Name });
            initialConditionsTable.Rows.Add(
                new object[] { Apsim.FullPath(simulation), "APSIM version", "APSIM version", "String", string.Empty, string.Empty, false, simulation.ApsimVersion });
            initialConditionsTable.Rows.Add(
                new object[] { Apsim.FullPath(simulation), "Run on", "Run on", "String", string.Empty, string.Empty, false, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") });

            // Get all model properties and store in 'initialConditionsTable'
            foreach (Model model in Apsim.FindAll(simulation))
            {
                string relativeModelPath = Apsim.FullPath(model).Replace(Apsim.FullPath(simulation) + ".", string.Empty);
                List<VariableProperty> properties = new List<VariableProperty>();

                FindAllProperties(model, properties);

                foreach (VariableProperty property in properties)
                {
                    string value = property.ValueWithArrayHandling.ToString();
                    if (value != string.Empty)
                    {
                        if (value != null && property.DataType == typeof(DateTime))
                        {
                            value = ((DateTime)property.Value).ToString("yyyy-MM-dd HH:mm:ss");
                        }

                        bool showTotal = !double.IsNaN(property.Total);

                        initialConditionsTable.Rows.Add(new object[]
                          {
                              relativeModelPath,
                              property.Name,
                              property.Description,
                              property.DataType.Name,
                              property.Units,
                              property.Format,
                              showTotal,
                              value
                          });
                    }
                }
            }

            // Write to data store.
            DataStore dataStore = new DataStore(simulation);
            dataStore.DeleteOldContentInTable(simulation.Name, "InitialConditions");
            dataStore.WriteTable(simulation.Name, "InitialConditions", initialConditionsTable);
            dataStore.Disconnect();
        }
Exemple #6
0
        /// <summary>
        /// Create an initial conditions table in the DataStore.
        /// </summary>
        private void CreateInitialConditionsTable()
        {
            ReportColumnWithValues modelPath     = new ReportColumnWithValues("ModelPath");
            ReportColumnWithValues name          = new ReportColumnWithValues("Name");
            ReportColumnWithValues description   = new ReportColumnWithValues("Description");
            ReportColumnWithValues dataType      = new ReportColumnWithValues("DataType");
            ReportColumnWithValues units         = new ReportColumnWithValues("Units");
            ReportColumnWithValues displayFormat = new ReportColumnWithValues("DisplayFormat");
            ReportColumnWithValues showTotal     = new ReportColumnWithValues("Total");
            ReportColumnWithValues value         = new ReportColumnWithValues("Value");
            ReportTable            table         = new Report.ReportTable();

            table.FileName       = Path.ChangeExtension(Simulation.FileName, ".db");
            table.SimulationName = Simulation.Name;
            table.TableName      = "InitialConditions";
            table.Columns.Add(modelPath);
            table.Columns.Add(name);
            table.Columns.Add(description);
            table.Columns.Add(dataType);
            table.Columns.Add(units);
            table.Columns.Add(displayFormat);
            table.Columns.Add(showTotal);
            table.Columns.Add(value);

            modelPath.Add(Apsim.FullPath(Simulation));
            name.Add("Simulation name");
            description.Add("Simulation name");
            dataType.Add("String");
            units.Add(string.Empty);
            displayFormat.Add(string.Empty);
            showTotal.Add(0);
            value.Add(Simulation.Name);

            modelPath.Add(Apsim.FullPath(Simulation));
            name.Add("APSIM version");
            description.Add("APSIM version");
            dataType.Add("String");
            units.Add(string.Empty);
            displayFormat.Add(string.Empty);
            showTotal.Add(0);
            value.Add(Simulation.ApsimVersion);

            modelPath.Add(Apsim.FullPath(Simulation));
            name.Add("Run on");
            description.Add("Run on");
            dataType.Add("String");
            units.Add(string.Empty);
            displayFormat.Add(string.Empty);
            showTotal.Add(0);
            value.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

            // Get all model properties and store in 'initialConditionsTable'
            foreach (Model model in Apsim.FindAll(Simulation))
            {
                string relativeModelPath           = Apsim.FullPath(model).Replace(Apsim.FullPath(Simulation) + ".", string.Empty);
                List <VariableProperty> properties = new List <VariableProperty>();

                FindAllProperties(model, properties);

                foreach (VariableProperty property in properties)
                {
                    string propertyValue = property.ValueWithArrayHandling.ToString();
                    if (propertyValue != string.Empty)
                    {
                        if (propertyValue != null && property.DataType == typeof(DateTime))
                        {
                            propertyValue = ((DateTime)property.Value).ToString("yyyy-MM-dd HH:mm:ss");
                        }

                        modelPath.Add(relativeModelPath);
                        name.Add(property.Name);
                        description.Add(property.Description);
                        dataType.Add(property.DataType.Name);
                        units.Add(property.Units);
                        displayFormat.Add(property.Format);
                        if (double.IsNaN(property.Total))
                        {
                            showTotal.Add(0);
                        }
                        else
                        {
                            showTotal.Add(1);
                        }
                        value.Add(propertyValue);
                    }
                }
            }

            // Write to data store.
            DataStore dataStore = new DataStore(Simulation);

            dataStore.WriteTable(table);
            dataStore.Disconnect();
        }