Пример #1
0
        public long UpgradeSystemTableFromFile(string filename, bool[] gridids, Func <bool> cancelRequested, Action <string> reportProgress)
        {
            ExecuteWithDatabase(action: conn =>
            {
                conn.Connection.DropStarTables(TempTablePostfix);     // just in case, kill the old tables
                conn.Connection.CreateStarTables(TempTablePostfix);   // and make new temp tables
            });

            DateTime maxdate = DateTime.MinValue;
            long     updates = SystemsDB.ParseEDSMJSONFile(filename, gridids, ref maxdate, cancelRequested, reportProgress, TempTablePostfix, presumeempty: true, debugoutputfile: DebugOutfile);

            if (updates > 0)
            {
                ExecuteWithDatabase(action: conn =>
                {
                    RebuildRunning = true;

                    reportProgress?.Invoke("Remove old data");
                    conn.Connection.DropStarTables();                       // drop the main ones - this also kills the indexes

                    conn.Connection.RenameStarTables(TempTablePostfix, ""); // rename the temp to main ones

                    reportProgress?.Invoke("Shrinking database");
                    conn.Connection.Vacuum();

                    reportProgress?.Invoke("Creating indexes");
                    conn.Connection.CreateSystemDBTableIndexes();

                    RebuildRunning = false;
                });

                SetLastEDSMRecordTimeUTC(maxdate);          // record last data stored in database

                return(updates);
            }
            else
            {
                ExecuteWithDatabase(action: conn =>
                {
                    conn.Connection.DropStarTables(TempTablePostfix);     // clean out half prepared tables
                });

                return(-1);
            }
        }
        // full table replace

        public static long UpgradeSystemTableFromFile(string filename, bool[] gridids, Func <bool> cancelRequested, Action <string> reportProgress)
        {
            using (SQLiteConnectionSystem conn = new SQLiteConnectionSystem(AccessMode.ReaderWriter))
            {
                DropStarTables(conn, tablepostfix);     // just in case, kill the old tables
                CreateStarTables(conn, tablepostfix);   // and make new temp tables
            }

            DateTime maxdate = DateTime.MinValue;
            long     updates = SystemsDB.ParseEDSMJSONFile(filename, gridids, ref maxdate, cancelRequested, reportProgress, tablepostfix, presumeempty: true, debugoutputfile: debugoutfile);

            using (SQLiteConnectionSystem conn = new SQLiteConnectionSystem(AccessMode.ReaderWriter))
            {
                if (updates > 0)
                {
                    reportProgress?.Invoke("Remove old data");
                    DropStarTables(conn);                     // drop the main ones - this also kills the indexes

                    RenameStarTables(conn, tablepostfix, ""); // rename the temp to main ones

                    reportProgress?.Invoke("Shrinking database");
                    conn.Vacuum();

                    reportProgress?.Invoke("Creating indexes");
                    CreateSystemDBTableIndexes(conn);

                    SetLastEDSMRecordTimeUTC(maxdate);          // record last data stored in database

                    return(updates);
                }
                else
                {
                    DropStarTables(conn, tablepostfix);     // clean out half prepared tables
                    return(-1);
                }
            }
        }