Esempio n. 1
0
        // Input Validation Methods

        // Method to create a phidget class based on the configuration combo box and assign it to the correct hub port
        public PhidgetSensor CreateSensor(string sensorName, int hubPort, string hubName, bool wireless)
        {
            PhidgetSensor ret = null;

            // Using -1 as a parameter for debug purposes, come back and change it to the minThreshold and maxThreshold variable
            switch (sensorName)
            {
            case "Moisture":
                ret = new MyMoistureSensor(hubPort, sensorName, hubName, MinMoisture, MaxMoisture, wireless);
                break;

            case "Light":
                ret = new MyLightSensor(hubPort, sensorName, hubName, -1, -1, wireless);
                break;

            case "Humidity/Air Temperature":
                ret = new MyHumidityAirTemperatureSensor(hubPort, sensorName, hubName, MinHumidity, MaxHumidity, MinAirTemperature, MaxAirTemperature, wireless);
                break;

            case "Oxygen":
                ret = new MyOxygenSensor(hubPort, sensorName, hubName, MinOxygen, MaxOxygen, wireless);
                break;

            case "Soil Temperature":
                ret = new MySoilTemperatureSensor(hubPort, sensorName, hubName, MinSoilTemperature, MaxSoilTemperature, wireless);
                break;

            case "None":
                ret = new PhidgetSensor(hubPort, "None", hubName, 0, 0, true);
                break;
            }
            return(ret);
        }
Esempio n. 2
0
        public VintHub(PhidgetSensor[] sensors, bool wireless, string hubName)
        {
            try
            {
                AllSensors = new ItemsChangeObservableCollection <PhidgetSensor>();
                if (sensors.Length == 6)
                {
                    for (int i = 0; i < 6; i++)
                    {
                        Type         hubType = typeof(VintHub);
                        PropertyInfo hubInfo = hubType.GetProperty($"Sensor{i}");
                        hubInfo.SetValue(this, sensors[i]);
                        PhidgetSensor sensor = (PhidgetSensor)hubInfo.GetValue(this, null);
                        AllSensors.Add(sensor);
                    }

                    Wireless = wireless;

                    this.HubName = hubName;
                }
                else
                {
                    throw new ArgumentException("Exactly 6 sensors are required to initiate a VINT Hub.");
                }
            }
            catch
            {
                return;
            }
        }
Esempio n. 3
0
        // loads configuration from database
        public string LoadConfiguration()
        {
            string result = "";
            string getGeneralConfigQuery = $@"select * from GeneralConfig";
            string getVintConfig         = "select * from VintHubConfig";
            string getExtensionConfig    = "select * from ExtensionHubConfig";

            if (CheckForConfig())
            {
                try
                {
                    _tradDBConn.Open();

                    // Loads General Configuration Values
                    using (SQLiteCommand cmd = new SQLiteCommand(getGeneralConfigQuery, _tradDBConn))
                    {
                        using (SQLiteDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                if (reader[0].GetType().ToString() != "System.DBNull")
                                {
                                    RecipientEmailAddress = reader.GetString(0);
                                }

                                if (reader[1].GetType().ToString() != "System.DBNull")
                                {
                                    SenderEmailAddress = reader.GetString(1);
                                }

                                if (reader[2].GetType().ToString() != "System.DBNull")
                                {
                                    SenderEmailPassword = reader.GetString(2);
                                }

                                if (reader[3].GetType().ToString() != "System.DBNull")
                                {
                                    SenderEmailSmtpAddress = reader.GetString(3);
                                }

                                if (reader[4].GetType().ToString() != "System.DBNull")
                                {
                                    SenderEmailSmtpPort = reader.GetInt32(4);
                                }

                                if (reader[5].GetType().ToString() != "System.DBNull")
                                {
                                    DataCollectionIntervalTime = reader.GetInt32(5);
                                }

                                if (reader[6].GetType().ToString() != "System.DBNull")
                                {
                                    MinSoilTemperature = reader.GetDouble(6);
                                }

                                if (reader[7].GetType().ToString() != "System.DBNull")
                                {
                                    MinAirTemperature = reader.GetDouble(7);
                                }

                                if (reader[8].GetType().ToString() != "System.DBNull")
                                {
                                    MinHumidity = reader.GetDouble(8);
                                }

                                if (reader[9].GetType().ToString() != "System.DBNull")
                                {
                                    MinMoisture = reader.GetDouble(9);
                                }

                                if (reader[10].GetType().ToString() != "System.DBNull")
                                {
                                    MinOxygen = reader.GetDouble(10);
                                }

                                if (reader[11].GetType().ToString() != "System.DBNull")
                                {
                                    MinCO2 = reader.GetDouble(11);
                                }

                                if (reader[12].GetType().ToString() != "System.DBNull")
                                {
                                    MinVOC = reader.GetDouble(12);
                                }

                                if (reader[13].GetType().ToString() != "System.DBNull")
                                {
                                    MaxSoilTemperature = reader.GetDouble(13);
                                }

                                if (reader[14].GetType().ToString() != "System.DBNull")
                                {
                                    MaxAirTemperature = reader.GetDouble(14);
                                }

                                if (reader[15].GetType().ToString() != "System.DBNull")
                                {
                                    MaxHumidity = reader.GetDouble(15);
                                }

                                if (reader[16].GetType().ToString() != "System.DBNull")
                                {
                                    MaxMoisture = reader.GetDouble(16);
                                }

                                if (reader[17].GetType().ToString() != "System.DBNull")
                                {
                                    MaxOxygen = reader.GetDouble(17);
                                }

                                if (reader[18].GetType().ToString() != "System.DBNull")
                                {
                                    MaxVOC = reader.GetDouble(18);
                                }

                                if (reader[19].GetType().ToString() != "System.DBNull")
                                {
                                    MaxCO2 = reader.GetDouble(19);
                                }

                                if (reader[20].GetType().ToString() != "System.DBNull")
                                {
                                    GpsEnabled = reader.GetBoolean(20);
                                }
                            }
                        }
                    }
                    VintHubs = new ItemsChangeObservableCollection <VintHub>();

                    // loads all sets of saved VINT hub configs,
                    using (SQLiteCommand cmd = new SQLiteCommand(getVintConfig, _tradDBConn))
                    {
                        using (SQLiteDataReader reader = cmd.ExecuteReader())
                        {
                            if (!reader.HasRows)
                            {
                                VintHubs.Add(CreateNewHub());
                            }
                            else
                            {
                                while (reader.Read())
                                {
                                    string hubName = reader.GetString(0);

                                    PhidgetSensor[] sensors = new PhidgetSensor[6];
                                    for (int i = 0; i < 6; i++)
                                    {
                                        PhidgetSensor sensor = CreateSensor(reader.GetString(i + 1), i, hubName, reader.GetBoolean(7));
                                        sensors[i] = sensor;
                                    }

                                    VintHub newVint = new VintHub(sensors, reader.GetBoolean(7), hubName);
                                    VintHubs.Add(newVint);
                                }
                            }
                        }
                    }
                    _tradDBConn.Close();

                    result = "good";
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                    _tradDBConn.Close();
                    throw;
                }
            }
            return(result);
        }