public Add ( ScienceScope.SensorDefinition sensor ) : void | ||
sensor | ScienceScope.SensorDefinition | |
Résultat | void |
private static ServerData ResultToServerData(SQLiteDataReader result) { ServerData serverToReturn = null; Guid id = result.GetGuid(0); string name = result.GetString(1); string description = result.GetString(2); string location = result.GetString(3); byte[] imageBytes = (byte[])result.GetValue(4); SensorDescriptionsData sensorData = new SensorDescriptionsData(); SensorDefinition[] sensor = new SensorDefinition[4] { new SensorDefinition(), new SensorDefinition(), new SensorDefinition(), new SensorDefinition()}; for (int s = 0; s < 4; s++) { // Do 4 sensor descriptions and 4 fields for each sensor[s].Name = (string)SQLHelper.ValueIfNull(result, s + 5, ""); sensor[s].Unit = (string)SQLHelper.ValueIfNull(result, s + 9, ""); sensor[s].ID = Convert.ToInt16(SQLHelper.ValueIfNull(result, s + 13, 255)); sensor[s].Range = Convert.ToInt16(SQLHelper.ValueIfNull(result, s + 17, 255)); sensorData.Add(sensor[s]); } serverToReturn = new ServerData(id, name, location, description, sensorData, imageBytes); return serverToReturn; }
public void SetUpWorkings() { descriptionUpdater = new VoidDelegate(UpdateServerDescription); connectionHandler = new DeviceNotification(DeviceManagement_NetworkConnected); InitialiseWiFi(); log.Name = "log"; log.LogMessage += new LogMessageEventHandler(log_LogMessage); log.Start(); #region Regestry data setup RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(SensorShareConfig.ConfigKeyName); bool createNewConfig = true; object regKey = registryKey.GetValue("ServerID"); if (regKey != null) { Guid serverID = new Guid((string)regKey); CurrentServerData = DatabaseHelper.GetServerByID(database, serverID); if (CurrentServerData != null) { createNewConfig = false; } else { log.Append("Server ID saved in Registry not found"); } } #endregion #region Server Configuration Setup if (createNewConfig) { log.Append("Need to create a new server configuration"); // Show server config before starting server (which is automatically done when config box is closed) Bitmap serverPic = new Bitmap(Application2.StartupPath + "/defaultImage.jpg"); CurrentServerData = new ServerData(Guid.Empty, "New Server", "Location", "Description", new SensorDescriptionsData(), JpegImage.GetBytes(serverPic)); configMenuItem_Click(this, new EventArgs()); } else { //If config isn't needed, start now registryKey.Close(); log.Append("Starting with server: " + CurrentServerData.id.ToString() + " " + CurrentServerData.name); // Save sensor data laoded from database (past session) SensorDescriptionsData loadedSensors = new SensorDescriptionsData(); foreach (SensorDefinition sensor in CurrentServerData.sensors) { loadedSensors.Add(sensor); } //Clear current data as logbook isn't connected yet so sensors are unknown CurrentServerData.sensors.Clear(); InitialiseLogbook(); // Set up logbook data // Connect Logbook and send identify commands (reply comes on other threads ConnectLogbookAndIdentifySensors(); // Should have done Thread.Sleep in above method to allow reply to have come by now // Check sensors match the database version ConfirmSensors(); bool sensorSelectionNotCompleted = true; while (sensorSelectionNotCompleted) { // check that the sensors connected are the same bool sameSensorsConnected = true; lock (CurrentServerData.sensors) { if (loadedSensors.Count != CurrentServerData.sensors.Count) { sameSensorsConnected = false; } else { for (int s = 0; s < loadedSensors.Count; s++) { if ((loadedSensors[s].ID != CurrentServerData.sensors[s].ID) || (loadedSensors[s].Range != CurrentServerData.sensors[s].Range)) { sameSensorsConnected = false; } } } } if (!sameSensorsConnected) { DialogResult result = MessageBox.Show("The sensors currently attached to the Logbook do not match the previously saved sensors. Click Retry to change the sensors, or Cancel to create a new server configuration.", "Different Sensors Connected", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == DialogResult.Retry) { disconnectLogbook(); StringBuilder sb = new StringBuilder(); sb.Append("You need to connect the following sensors:\r\n"); foreach (SensorDefinition sensor in loadedSensors) { sb.AppendFormat("{0}\r\n", sensor.Description); } MessageBox.Show(sb.ToString(), "Sensors Required", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); CurrentServerData.sensors.Clear(); ConnectLogbookAndIdentifySensors(); ConfirmSensors(); } else { if (result == DialogResult.Cancel) { CurrentServerData.id = Guid.NewGuid(); DatabaseHelper.SaveServerConfigData(database, CurrentServerData); sensorSelectionNotCompleted = false; } } } else { sensorSelectionNotCompleted = false; } } StartServer(); } #endregion DeviceManagement.NetworkConnected += connectionHandler; }