Esempio n. 1
0
        protected override int OnInsert(SQLiteConnection db, int?key, DesignInfo value)
        {
            if (key.HasValue)
            {
                throw new ArgumentOutOfRangeException(nameof(key), "Design insertion does not permit explicit specification of an ID.");
            }
            if (ScriptHost.AllowConsole)
            {
                if (value.DesignSections == null || value.DesignSections.Length == 0)
                {
                    throw new InvalidDataException("DesignInfo does not supply any DesignSections.");
                }
            }
            else
            {
                RowCache <int, DesignInfo> .Warn(string.Format("DesignsCache.OnInsert: DesignInfo does not supply any DesignSections (player={0}, stationType={1}, stationLevel={2})", (object)value.PlayerID, (object)value.StationType.ToString(), (object)value.StationLevel.ToString()));
            }
            value.HackValidateRole();
            int num = db.ExecuteIntegerQuery(string.Format(Queries.InsertDesign, (object)value.PlayerID.ToOneBasedSQLiteValue(), (object)value.Name.ToSQLiteValue(), (object)value.Armour.ToSQLiteValue(), (object)value.Structure.ToSQLiteValue(), (object)value.NumTurrets.ToSQLiteValue(), (object)value.Mass.ToSQLiteValue(), (object)0.ToSQLiteValue(), (object)value.Acceleration.ToSQLiteValue(), (object)value.TopSpeed.ToSQLiteValue(), (object)value.SavingsCost.ToSQLiteValue(), (object)value.ProductionCost.ToSQLiteValue(), (object)((int)value.Class).ToSQLiteValue(), (object)value.CrewAvailable.ToSQLiteValue(), (object)value.PowerAvailable.ToSQLiteValue(), (object)value.SupplyAvailable.ToSQLiteValue(), (object)value.CrewRequired.ToSQLiteValue(), (object)value.PowerRequired.ToSQLiteValue(), (object)value.SupplyRequired.ToSQLiteValue(), (object)GameDatabase.GetTurnCount(db).ToSQLiteValue(), (object)((int)value.Role).ToSQLiteValue(), (object)((int)value.WeaponRole).ToSQLiteValue(), (object)value.isPrototyped.ToSQLiteValue(), (object)value.isAttributesDiscovered.ToSQLiteValue(), (object)((int)value.StationType).ToSQLiteValue(), (object)value.StationLevel.ToSQLiteValue(), (object)value.PriorityWeaponName.ToSQLiteValue(), (object)value.RetrofitBaseID.ToOneBasedSQLiteValue()));

            value.ID = num;
            foreach (DesignSectionInfo designSection in value.DesignSections)
            {
                designSection.DesignInfo = value;
                int designSectionId = db.ExecuteIntegerQuery(string.Format(Queries.InsertDesignSection.ToSQLiteValue(), (object)num.ToSQLiteValue(), (object)designSection.FilePath.ToSQLiteValue()));
                designSection.ID = designSectionId;
                if (designSection.WeaponBanks == null)
                {
                    designSection.WeaponBanks = new List <WeaponBankInfo>();
                }
                foreach (WeaponBankInfo weaponBank in designSection.WeaponBanks)
                {
                    weaponBank.ID = DesignsCache.InsertWeaponBank(db, designSectionId, weaponBank);
                }
                if (designSection.Modules == null)
                {
                    designSection.Modules = new List <DesignModuleInfo>();
                }
                foreach (DesignModuleInfo module in designSection.Modules)
                {
                    module.DesignSectionInfo = designSection;
                    module.ID = DesignsCache.InsertDesignModuleInfo(db, module);
                }
                if (designSection.Techs == null)
                {
                    designSection.Techs = new List <int>();
                }
                foreach (int tech in designSection.Techs)
                {
                    db.ExecuteIntegerQuery(string.Format(Queries.InsertDesignSectionTech, (object)designSectionId.ToSQLiteValue(), (object)tech.ToSQLiteValue()));
                }
            }
            return(num);
        }
Esempio n. 2
0
 protected void SynchronizeWithDatabase()
 {
     if (!this.syncfromdb)
     {
         return;
     }
     if (this.syncall)
     {
         if (ScriptHost.AllowConsole)
         {
             RowCache <TRowKey, TRowObject> .Trace(string.Format("{0}: Synchronizing all objects", (object)this.GetType().Name));
         }
         foreach (KeyValuePair <TRowKey, TRowObject> keyValuePair in this.OnSynchronizeWithDatabase(this.db, (IEnumerable <TRowKey>)null))
         {
             this.items.Add(keyValuePair.Key, keyValuePair.Value);
         }
     }
     else
     {
         List <TRowKey> rowKeyList = (List <TRowKey>)null;
         if (ScriptHost.AllowConsole)
         {
             rowKeyList = new List <TRowKey>();
         }
         foreach (KeyValuePair <TRowKey, TRowObject> keyValuePair in this.OnSynchronizeWithDatabase(this.db, (IEnumerable <TRowKey>) this.staleItems))
         {
             this.items[keyValuePair.Key] = keyValuePair.Value;
             rowKeyList?.Add(keyValuePair.Key);
         }
         if (ScriptHost.AllowConsole)
         {
             foreach (TRowKey rowKey in rowKeyList)
             {
                 RowCache <TRowKey, TRowObject> .Trace(string.Format("{0}: Synchronized object for key {1}", (object)this.GetType().Name, (object)rowKey));
             }
         }
     }
     this.staleItems.Clear();
     this.syncall    = false;
     this.syncfromdb = false;
 }