Beispiel #1
0
        void Disconnect()
        {
            Resources?.Dispose();
            Experience?.Dispose();
            Expedition?.Dispose();
            Construction?.Dispose();
            Development?.Dispose();
            Sortie?.Dispose();
            Battle?.Dispose();
            Fate?.Dispose();
            r_RankingPoints?.Dispose();
            r_SortieConsumption?.Dispose();
            QuestProgress?.Dispose();
            BattleDetail?.Dispose();

            if (r_Connection != null)
            {
                r_Connection.Update -= OnDatabaseUpdate;

                r_Connection.Dispose();
            }

            foreach (var rCustomGroup in r_CustomRecordsGroups.Values)
            {
                rCustomGroup.Dispose();
            }

            IsConnected = false;
        }
        void Connect(int rpUserID)
        {
            if (r_UserID == rpUserID)
            {
                return;
            }

            Resources?.Dispose();
            Ships?.Dispose();
            Experience?.Dispose();
            Expedition?.Dispose();
            Construction?.Dispose();
            Development?.Dispose();
            Sortie?.Dispose();
            Battle?.Dispose();
            RankingPoints?.Dispose();
            Fate?.Dispose();
            QuestProgress?.Dispose();
            BattleDetail?.Dispose();

            if (r_Connection != null)
            {
                r_Connection.Update -= OnDatabaseUpdate;

                r_Connection.Dispose();
            }

            foreach (var rCustomGroup in r_CustomRecordsGroups.Values)
            {
                rCustomGroup.Dispose();
            }

            IsConnected = false;

            r_UserID = rpUserID;

            r_Connection = new SQLiteConnection($@"Data Source=Records\{r_UserID}.db;Page Size=8192").OpenAndReturn();

            if (IsReadOnlyMode)
            {
                using (var rSourceConnection = r_Connection)
                {
                    r_Connection = new SQLiteConnection("Data Source=:memory:;Page Size=8192").OpenAndReturn();
                    rSourceConnection.BackupDatabase(r_Connection, "main", "main", -1, null, 0);
                }
            }

            using (var rTransaction = r_Connection.BeginTransaction())
            {
                CheckVersion();

                Resources     = new ResourcesRecords(r_Connection).ConnectAndReturn();
                Ships         = new ShipsRecords(r_Connection).ConnectAndReturn();
                Experience    = new ExperienceRecords(r_Connection).ConnectAndReturn();
                Expedition    = new ExpeditionRecords(r_Connection).ConnectAndReturn();
                Construction  = new ConstructionRecords(r_Connection).ConnectAndReturn();
                Development   = new DevelopmentRecords(r_Connection).ConnectAndReturn();
                Sortie        = new SortieRecords(r_Connection).ConnectAndReturn();
                Battle        = new BattleRecords(r_Connection).ConnectAndReturn();
                RankingPoints = new RankingPointsRecords(r_Connection).ConnectAndReturn();
                Fate          = new FateRecords(r_Connection).ConnectAndReturn();

                QuestProgress = new QuestProgressRecords(r_Connection).ConnectAndReturn();

                foreach (var rProvider in r_CustomRecordsGroupProviders)
                {
                    var rGroup = rProvider.Create(r_Connection).ConnectAndReturn();
                    r_CustomRecordsGroups[rGroup.GroupName] = rGroup;
                }

                rTransaction.Commit();
            }

            BattleDetail = new BattleDetailRecords(r_Connection, r_UserID).ConnectAndReturn();

            r_Connection.Update += OnDatabaseUpdate;

            IsConnected = true;
        }