public Sensor(string name, int index, SensorType sensorType, Hardware hardware, ParameterDescription[] parameterDescriptions, ISettings settings) : this(name, index, false, sensorType, hardware, parameterDescriptions, settings) { }
public Sensor(string name, int index, bool defaultHidden, SensorType sensorType, Hardware hardware, ParameterDescription[] parameterDescriptions, ISettings settings) { this.index = index; this.defaultHidden = defaultHidden; this.sensorType = sensorType; this.hardware = hardware; Parameter[] parameters = new Parameter[parameterDescriptions == null ? 0 : parameterDescriptions.Length]; for (int i = 0; i < parameters.Length; i++ ) parameters[i] = new Parameter(parameterDescriptions[i], this, settings); this.parameters = parameters; this.settings = settings; this.defaultName = name; this.name = settings.GetValue( new Identifier(Identifier, "name").ToString(), name); GetSensorValuesFromSettings(); hardware.Closing += delegate(IHardware h) { SetSensorValuesToSettings(); }; }
public Sensor(string name, int index, SensorType sensorType, Hardware hardware, ISettings settings) : this(name, index, sensorType, hardware, null, settings) { }
private static Int64 GetComponentId(Hardware.IHardware hardware) { SQLiteDataReader reader; //has this hardware component been added before? Int64 componentId = -1; using (SQLiteCommand command = new SQLiteCommand(s_dataManager._sqliteConnection)) { command.CommandText = "SELECT ComponentID FROM Component WHERE Name = '@componentName' AND Type = '@componentType'"; command.Parameters.Add(new SQLiteParameter("@componentName", hardware.Name)); command.Parameters.Add(new SQLiteParameter("@componentType", hardware.HardwareType.ToString())); reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { componentId = Convert.ToInt64(reader["ComponentID"]); } } } if (componentId == -1) { using (SQLiteCommand command = new SQLiteCommand(s_dataManager._sqliteConnection)) { command.CommandText = "INSERT INTO Component (Name, Type) values (@componentName, @componentType)"; command.Parameters.Add(new SQLiteParameter("@componentName", hardware.Name)); command.Parameters.Add(new SQLiteParameter("@componentType", hardware.HardwareType.ToString())); command.ExecuteNonQuery(); command.CommandText = "SELECT ComponentID FROM Component WHERE Name = @componentName AND Type = @componentType"; command.Parameters.Add(new SQLiteParameter("@componentName", hardware.Name)); command.Parameters.Add(new SQLiteParameter("@componentType", hardware.HardwareType.ToString())); reader = command.ExecuteReader(); while (reader.Read()) { componentId = Convert.ToInt64(reader["ComponentID"]); } } } return componentId; }
public static void AddHardware(Hardware.IHardware hardware) { lock (s_lockObject) { //lets check if this computer-component combo has already been added SQLiteDataReader reader; using (SQLiteCommand command = new SQLiteCommand(s_dataManager._sqliteConnection)) { command.CommandText = "SELECT * FROM ComputerComponent WHERE ComputerComponentID = @computerComponentId AND ComputerID = @computerID"; command.Parameters.Add(new SQLiteParameter("@computerComponentId", hardware.Identifier.ToString())); command.Parameters.Add(new SQLiteParameter("@computerID", GetComputerId(GetMacAddress))); reader = command.ExecuteReader(); if (reader.HasRows) return; } Int64 componentId = GetComponentId(hardware); using (SQLiteCommand command = new SQLiteCommand(s_dataManager._sqliteConnection)) { command.CommandText = "INSERT INTO ComputerComponent (ComputerComponentID, ComputerID, ComponentID, ParentComputerComponentID) values (@computerComponentId, @computerId, @componentId, @parentComputerComponentId)"; command.Parameters.Add(new SQLiteParameter("@computerComponentId", hardware.Identifier.ToString())); command.Parameters.Add(new SQLiteParameter("@computerId", GetComputerId(GetMacAddress))); command.Parameters.Add(new SQLiteParameter("@componentId", componentId)); command.Parameters.Add(new SQLiteParameter("@parentComputerComponentId", (hardware.Parent == null?"":hardware.Parent.Identifier.ToString()))); command.ExecuteNonQuery(); } } }