/// <summary> /// See interface docs. /// </summary> /// <param name="systemEvent"></param> public void UpdateSystemEvent(BaseStationSystemEvents systemEvent) { if (!WriteSupportEnabled) { throw new InvalidOperationException("You cannot update a system event record when write support is disabled"); } systemEvent.TimeStamp = SQLiteDateHelper.Truncate(systemEvent.TimeStamp); lock (_ConnectionLock) { OpenConnection(); if (_Connection != null) { _SystemEventsTable.Update(_Connection, _TransactionHelper.Transaction, _DatabaseLog, systemEvent); } } }
/// <summary> /// See interface docs. /// </summary> /// <param name="flight"></param> public void UpdateFlight(BaseStationFlight flight) { if (!WriteSupportEnabled) { throw new InvalidOperationException("You cannot update flights when writes are disabled"); } flight.StartTime = SQLiteDateHelper.Truncate(flight.StartTime); flight.EndTime = SQLiteDateHelper.Truncate(flight.EndTime); lock (_ConnectionLock) { OpenConnection(); if (_Connection != null) { _FlightTable.Update(_Connection, _TransactionHelper.Transaction, _DatabaseLog, flight); } } }
/// <summary> /// See interface docs. /// </summary> /// <param name="aircraft"></param> public void UpdateAircraft(BaseStationAircraft aircraft) { if (!WriteSupportEnabled) { throw new InvalidOperationException("You cannot update aircraft when write support is disabled"); } aircraft.FirstCreated = SQLiteDateHelper.Truncate(aircraft.FirstCreated); aircraft.LastModified = SQLiteDateHelper.Truncate(aircraft.LastModified); lock (_ConnectionLock) { OpenConnection(); if (_Connection != null) { _AircraftTable.Update(_Connection, _TransactionHelper.Transaction, _DatabaseLog, aircraft); } } }
/// <summary> /// See interface docs. /// </summary> /// <param name="session"></param> public void UpdateSession(BaseStationSession session) { if (!WriteSupportEnabled) { throw new InvalidOperationException("You must enable writes before you can update a session record"); } session.StartTime = SQLiteDateHelper.Truncate(session.StartTime); session.EndTime = SQLiteDateHelper.Truncate(session.EndTime); lock (_ConnectionLock) { OpenConnection(); if (_Connection != null) { _SessionsTable.Update(_Connection, _TransactionHelper.Transaction, _DatabaseLog, session); } } }
/// <summary> /// See interface docs. /// </summary> /// <param name="fileName"></param> public void CreateDatabaseIfMissing(string fileName) { if (!String.IsNullOrEmpty(fileName)) { bool fileMissing = !File.Exists(fileName); bool fileEmpty = fileMissing || new FileInfo(fileName).Length == 0; if (fileMissing || fileEmpty) { var configuration = Factory.Singleton.Resolve <IConfigurationStorage>().Singleton.Load(); var folder = Path.GetDirectoryName(fileName); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } if (fileMissing) { File.Create(fileName).Close(); } CloseConnection(); OpenConnection(fileName, true); try { if (_Connection != null) { var transaction = _Connection.BeginTransaction(); try { _DbHistoryTable.CreateTable(_Connection, _DatabaseLog); _DbInfoTable.CreateTable(_Connection, _DatabaseLog); _SystemEventsTable.CreateTable(_Connection, _DatabaseLog); _LocationsTable.CreateTable(_Connection, _DatabaseLog); _SessionsTable.CreateTable(_Connection, _DatabaseLog); _AircraftTable.CreateTable(_Connection, _DatabaseLog); _FlightTable.CreateTable(_Connection, _DatabaseLog); _SessionsTable.CreateTriggers(_Connection, _DatabaseLog); _AircraftTable.CreateTriggers(_Connection, _DatabaseLog); _DbHistoryTable.Insert(_Connection, null, _DatabaseLog, new BaseStationDBHistory() { Description = "Database autocreated by Virtual Radar Server", TimeStamp = SQLiteDateHelper.Truncate(Provider.UtcNow) }); _DbInfoTable.Insert(_Connection, null, _DatabaseLog, new BaseStationDBInfo() { OriginalVersion = 2, CurrentVersion = 2 }); _LocationsTable.Insert(_Connection, null, _DatabaseLog, new BaseStationLocation() { LocationName = "Home", Latitude = configuration.GoogleMapSettings.InitialMapLatitude, Longitude = configuration.GoogleMapSettings.InitialMapLongitude }); transaction.Commit(); } catch (Exception ex) { Debug.WriteLine(String.Format("Database.CreateDatabaseIfMissing caught exception {0}", ex.ToString())); transaction.Rollback(); throw; } } } finally { CloseConnection(); } } } }