/// <summary> /// The runtime of this method is configured in the <see cref="Program"/> class. /// </summary> public void Update(object sender, EventArgs e) { ELM327Manager.Run(); // Needs a valid configuration from the database. if (OBDConfig == null) { return; } if (OBDConfig.IsLoggingToDb) { UpdateDatabase(); } else { // Used when not storing to db. if (ELM327Manager.Storage == null) { ELM327Manager.SetStorage(1); } } UpdateBrowser(); }
/// <summary> /// Updates the database. /// </summary> private void UpdateDatabase() { // Exit. Application doesn't have a valid OBD device. if (ELM327Manager.RequestType != RequestType.DataStream) { return; } // Create storage. if (ELM327Manager.Storage == null) { int sessionId = OBDSql.GetSession(OBDConfig.CarId); // Do not use try/catch. Let the program crash if it fails to retrieve session id. ELM327Manager.SetStorage(sessionId); } // Insert to database when the threshold is reached. if (ELM327Manager.Storage.Rows.Count >= OBDSql.StorageThreshold) { OBDSql.Insert(ELM327Manager.Storage); } }