示例#1
0
        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);
        }
示例#2
0
        public static DataItemMeta CreateDefaultMeta()
        {
            DataItemMeta d = new DataItemMeta
            {
                Version       = 0,
                ActiveProfile = 0
            };

            return(d);
        }
示例#3
0
        public int UpdateMeta(DataItemMeta item)
        {
            int result = 0;

            lock (locker)
            {
                Debug.LogToFileMethod("item: " + item.Id);
                result = database.Update(item);
            }

            return(result);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
            }
        }