public DataItemVehicle GetActiveProfile() { DataItemVehicle result; if (IsMetaEmpty()) { if (!IsVehicleEmpty()) { // upgrade from old database result = GetFirstVehicle(); } else { // empty database -> create and store default item int id = SaveVehicle(DataItem.CreateDefaultVehicle()); result = GetVehicle(id); } // create meta table SaveActiveProfile(result); } else { // the meta table has only one entry at any time -> get first DataItemMeta meta = GetMeta(); result = GetVehicle(meta.ActiveProfile); } return(result); }
public static DataItemMeta CreateDefaultMeta() { DataItemMeta d = new DataItemMeta { Version = 0, ActiveProfile = 0 }; return(d); }
public int UpdateMeta(DataItemMeta item) { int result = 0; lock (locker) { Debug.LogToFileMethod("item: " + item.Id); result = database.Update(item); } return(result); }
public int SaveMeta(DataItemMeta item) { int result = 0; if (IsMetaEmpty()) // the meta table shall have only one entry at all time { lock (locker) { Debug.LogToFileMethod("item: " + item.Id); result = database.Insert(item); } } return(result); }
public void SaveActiveProfile(DataItemVehicle item) { lock (locker) { Debug.LogToFileMethod("item: " + item.Model); if (IsMetaEmpty()) { // empty database -> create and store default meta item SaveMeta(DataItem.CreateDefaultMeta()); } // the meta table always has one entry only -> get first DataItemMeta meta = GetMeta(); // update active profile meta.ActiveProfile = item.Id; UpdateMeta(meta); } }