示例#1
0
        private void CheckSystems(Func <bool> cancelRequested, Action <int, string> reportProgress)  // ASYNC process, done via start up, must not be too slow.
        {
            reportProgress(-1, "");

            string   rwsystime = SQLiteConnectionSystem.GetSettingString("EDSMLastSystems", "2000-01-01 00:00:00"); // Latest time from RW file.
            DateTime edsmdate;

            if (!DateTime.TryParse(rwsystime, CultureInfo.InvariantCulture, DateTimeStyles.None, out edsmdate))
            {
                edsmdate = new DateTime(2000, 1, 1);
            }

            if (DateTime.Now.Subtract(edsmdate).TotalDays > 7)  // Over 7 days do a sync from EDSM
            {
                // Also update galactic mapping from EDSM
                LogLine("Get galactic mapping from EDSM.");
                galacticMapping.DownloadFromEDSM();

                // Skip EDSM full update if update has been performed in last 4 days
                bool     outoforder = SQLiteConnectionSystem.GetSettingBool("EDSMSystemsOutOfOrder", true);
                DateTime lastmod    = outoforder ? SystemClass.GetLastSystemModifiedTime() : SystemClass.GetLastSystemModifiedTimeFast();

                if (DateTime.UtcNow.Subtract(lastmod).TotalDays > 4 ||
                    DateTime.UtcNow.Subtract(edsmdate).TotalDays > 28)
                {
                    syncstate.performedsmsync = true;
                }
                else
                {
                    SQLiteConnectionSystem.PutSettingString("EDSMLastSystems", DateTime.Now.ToString(CultureInfo.InvariantCulture));
                }
            }

            if (!cancelRequested())
            {
                SQLiteConnectionUser.TranferVisitedSystemstoJournalTableIfRequired();
                SQLiteConnectionSystem.CreateSystemsTableIndexes();
                SystemNoteClass.GetAllSystemNotes();                    // fill up memory with notes, bookmarks, galactic mapping
                BookmarkClass.GetAllBookmarks();
                galacticMapping.ParseData();                            // at this point, EDSM data is loaded..
                SystemClass.AddToAutoComplete(galacticMapping.GetGMONames());
                EDDiscovery.EliteDangerous.MaterialCommodityDB.SetUpInitialTable();

                LogLine("Loaded Notes, Bookmarks and Galactic mapping.");

                string   timestr = SQLiteConnectionSystem.GetSettingString("EDDBSystemsTime", "0");
                DateTime time    = new DateTime(Convert.ToInt64(timestr), DateTimeKind.Utc);
                if (DateTime.UtcNow.Subtract(time).TotalDays > 6.5)     // Get EDDB data once every week.
                {
                    syncstate.performeddbsync = true;
                }
            }
        }
示例#2
0
        // Called from DoPerformSync, in back thread

        public static long PerformEDDBFullSync(Func <bool> PendingClose, Action <int, string> ReportProgress, Action <string> LogLine, Action <string> LogLineHighlight)
        {
            LogLine("Get systems from EDDB.");

            string eddbdir = Path.Combine(EliteConfigInstance.InstanceOptions.AppDataDirectory, "eddb");

            if (Directory.Exists(eddbdir))          // clean up old eddb folder
            {
                Directory.Delete(eddbdir, true);
            }

            string systemFileName = Path.Combine(eddbdir, Path.Combine(EliteConfigInstance.InstanceOptions.AppDataDirectory, "eddbsystems.json"));

            bool success = BaseUtils.DownloadFile.HTTPDownloadFile(EliteConfigInstance.InstanceConfig.EDDBSystemsURL, systemFileName, false, out bool newfile);

            if (success)
            {
                if (PendingClose())
                {
                    return(0);
                }

                LogLine("Resyncing all downloaded EDDB data with local database." + Environment.NewLine + "This will take a while.");

                long updates = ParseEDDBUpdateSystems(systemFileName, LogLineHighlight);

                LogLine("Local database updated with EDDB data, " + updates + " systems updated");
                SQLiteConnectionSystem.PutSettingString("EDDBSystemsTime", DateTime.UtcNow.Ticks.ToString());

                BaseUtils.FileHelpers.DeleteFileNoError(systemFileName);       // remove file - don't hold in storage

                GC.Collect();
                return(updates);
            }
            else
            {
                LogLineHighlight("Failed to download EDDB Systems. Will try again next run.");
            }

            return(0);
        }
示例#3
0
        // Called from DoPerformSync, in back thread

        public static long PerformEDDBFullSync(Func <bool> PendingClose, Action <int, string> ReportProgress, Action <string> LogLine, Action <string> LogLineHighlight)
        {
            LogLine("Get systems from EDDB.");

            string eddbdir = Path.Combine(EliteConfigInstance.InstanceOptions.AppDataDirectory, "eddb");

            if (!Directory.Exists(eddbdir))
            {
                Directory.CreateDirectory(eddbdir);
            }

            string systemFileName = Path.Combine(eddbdir, "systems_populated.jsonl");

            //"http://robert.astronet.se/Elite/eddb/v5/systems_populated.jsonl"
            bool success = BaseUtils.DownloadFileHandler.DownloadFile(EliteConfigInstance.InstanceConfig.EDDBSystemsURL, systemFileName);

            if (success)
            {
                if (PendingClose())
                {
                    return(0);
                }

                LogLine("Resyncing all downloaded EDDB data with local database." + Environment.NewLine + "This will take a while.");

                long updates = ParseEDDBUpdateSystems(systemFileName, LogLineHighlight);

                LogLine("Local database updated with EDDB data, " + updates + " systems updated");
                SQLiteConnectionSystem.PutSettingString("EDDBSystemsTime", DateTime.UtcNow.Ticks.ToString());

                GC.Collect();
                return(updates);
            }
            else
            {
                LogLineHighlight("Failed to download EDDB Systems. Will try again next run.");
            }

            return(0);
        }
示例#4
0
        public static void PerformEDDBFullSync(Func <bool> cancelRequested, Action <int, string> reportProgress, Action <string> logLine, Action <string> logError)
        {
            logLine("Get systems from EDDB.");

            string eddbdir = Path.Combine(EliteConfigInstance.InstanceOptions.AppDataDirectory, "eddb");

            if (!Directory.Exists(eddbdir))
            {
                Directory.CreateDirectory(eddbdir);
            }

            string systemFileName = Path.Combine(eddbdir, "systems_populated.jsonl");

            bool success = BaseUtils.DownloadFileHandler.DownloadFile("http://robert.astronet.se/Elite/eddb/v5/systems_populated.jsonl", systemFileName);

            if (success)
            {
                if (cancelRequested())
                {
                    return;
                }

                logLine("Resyncing all downloaded EDDB data with local database." + Environment.NewLine + "This will take a while.");

                long number = ParseEDDBUpdateSystems(systemFileName, logError);

                logLine("Local database updated with EDDB data, " + number + " systems updated");
                SQLiteConnectionSystem.PutSettingString("EDDBSystemsTime", DateTime.UtcNow.Ticks.ToString());
            }
            else
            {
                logError("Failed to download EDDB Systems. Will try again next run.");
            }

            GC.Collect();
        }
示例#5
0
        // Called from Background Thread Worker at Init()

        private void BackgroundInit()
        {
            StarScan.LoadBodyDesignationMap();

            SQLiteConnectionSystem.CreateSystemsTableIndexes();     // just make sure they are there..

            Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems");
            ReportSyncProgress(-1, "");

            bool checkGithub = EDDOptions.Instance.CheckGithubFiles;

            if (checkGithub)      // not normall in debug, due to git hub chokeing
            {
                // Async load of maps in another thread
                DownloadMaps(() => PendingClose);

                // and Expedition data
                DownloadExpeditions(() => PendingClose);

                // and Exploration data
                DownloadExploration(() => PendingClose);
            }

            if (!EDDOptions.Instance.NoSystemsLoad)
            {
                // Former CheckSystems, reworked to accomodate new switches..
                // Check to see what sync refreshes we need

                // New Galmap load - it was not doing a refresh if EDSM sync kept on happening. Now has its own timer

                string   rwgalmaptime = SQLiteConnectionSystem.GetSettingString("EDSMGalMapLast", "2000-01-01 00:00:00"); // Latest time from RW file.
                DateTime galmaptime;
                if (!DateTime.TryParse(rwgalmaptime, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out galmaptime))
                {
                    galmaptime = new DateTime(2000, 1, 1);
                }

                if (DateTime.Now.Subtract(galmaptime).TotalDays > 14)  // Over 14 days do a sync from EDSM for galmap
                {
                    LogLine("Get galactic mapping from EDSM.".Tx(this, "EDSM"));
                    galacticMapping.DownloadFromEDSM();
                    SQLiteConnectionSystem.PutSettingString("EDSMGalMapLast", DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"));
                }

                Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems complete");
            }

            galacticMapping.ParseData();                            // at this point, gal map data has been uploaded - get it into memory
            SystemClassDB.AddToAutoComplete(galacticMapping.GetGMONames());
            SystemNoteClass.GetAllSystemNotes();

            LogLine("Loaded Notes, Bookmarks and Galactic mapping.".Tx(this, "LN"));

            if (PendingClose)
            {
                return;
            }

            if (EliteDangerousCore.EDDN.EDDNClass.CheckforEDMC()) // EDMC is running
            {
                if (EDCommander.Current.SyncToEddn)               // Both EDD and EDMC should not sync to EDDN.
                {
                    LogLineHighlight("EDDiscovery and EDMarketConnector should not both sync to EDDN. Stop EDMC or uncheck 'send to EDDN' in settings tab!".Tx(this, "EDMC"));
                }
            }

            if (!EDDOptions.Instance.NoLoad)        // here in this thread, we do a refresh of history.
            {
                LogLine("Reading travel history".Tx(this, "RTH"));
                DoRefreshHistory(new RefreshWorkerArgs {
                    CurrentCommander = EDCommander.CurrentCmdrID
                });                                                                                             // kick the background refresh worker thread into action
            }

            if (PendingClose)
            {
                return;
            }

            if (!EDDOptions.Instance.NoSystemsLoad && EDDConfig.Instance.EDSMEDDBDownload)        // if enabled
            {
                SystemClassEDSM.DetermineIfFullEDSMSyncRequired(syncstate);                       // ask EDSM and EDDB if they want to do a Full sync..
                EliteDangerousCore.EDDB.SystemClassEDDB.DetermineIfEDDBSyncRequired(syncstate);

                if (syncstate.perform_eddb_sync || syncstate.perform_edsm_fullsync)
                {
                    string databases = (syncstate.perform_edsm_fullsync && syncstate.perform_eddb_sync) ? "EDSM and EDDB" : ((syncstate.perform_edsm_fullsync) ? "EDSM" : "EDDB");

                    LogLine(string.Format("Full synchronisation to the {0} databases required." + Environment.NewLine +
                                          "This will take a while, up to 15 minutes, please be patient." + Environment.NewLine +
                                          "Please continue running ED Discovery until refresh is complete.".Tx(this, "SyncEDSM"), databases));
                }
            }
            else
            {
                LogLine("Synchronisation to EDSM and EDDB disabled. Use Settings panel to reenable".Tx(this, "SyncOff"));
            }
        }
示例#6
0
 static public void ForceEDDBFullUpdate()
 {
     SQLiteConnectionSystem.PutSettingString("EDDBSystemsTime", "0");
 }
示例#7
0
 static public void SetLastEDSMRecordTimeUTC(DateTime time)
 {
     SQLiteConnectionSystem.PutSettingString("EDSMLastSystems", time.ToString(CultureInfo.InvariantCulture));
     System.Diagnostics.Debug.WriteLine("Last EDSM record " + time.ToString());
 }
示例#8
0
        // Time storers

        static public void ForceEDSMFullUpdate()
        {
            SQLiteConnectionSystem.PutSettingString("EDSMLastSystems", "2010-01-01 00:00:00");
        }
示例#9
0
        public static bool PerformEDSMFullSync(Func <bool> cancelRequested, Action <int, string> reportProgress, Action <string> logLine, Action <string> logError)
        {
            string   rwsystime = SQLiteConnectionSystem.GetSettingString("EDSMLastSystems", "2000-01-01 00:00:00"); // Latest time from RW file.
            DateTime edsmdate;

            if (!DateTime.TryParse(rwsystime, CultureInfo.InvariantCulture, DateTimeStyles.None, out edsmdate))
            {
                edsmdate = new DateTime(2000, 1, 1);
            }

            long updates = 0;

            // Delete all old systems
            SQLiteConnectionSystem.PutSettingString("EDSMLastSystems", "2010-01-01 00:00:00");
            SQLiteConnectionSystem.PutSettingString("EDDBSystemsTime", "0");

            EDSMClass edsm = new EDSMClass();

            logLine("Get hidden systems from EDSM and remove from database");

            RemoveHiddenSystems();

            if (cancelRequested())
            {
                return(false);
            }

            logLine("Download systems file from EDSM.");

            string edsmsystems = Path.Combine(EliteConfigInstance.InstanceOptions.AppDataDirectory, "edsmsystems.json");

            logLine("Resyncing all downloaded EDSM systems with local database." + Environment.NewLine + "This will take a while.");

            bool newfile;
            bool success = BaseUtils.DownloadFileHandler.DownloadFile(EDSMClass.ServerAddress + "dump/systemsWithCoordinates.json", edsmsystems, out newfile, (n, s) =>
            {
                SQLiteConnectionSystem.CreateTempSystemsTable();

                string rwsysfiletime = "2014-01-01 00:00:00";
                bool outoforder      = false;
                using (var reader = new StreamReader(s))
                    updates = ParseEDSMUpdateSystemsStream(reader, ref rwsysfiletime, ref outoforder, true, cancelRequested, reportProgress, useCache: false, useTempSystems: true);
                if (!cancelRequested())       // abort, without saving time, to make it do it again
                {
                    SQLiteConnectionSystem.PutSettingString("EDSMLastSystems", rwsysfiletime);
                    logLine("Replacing old systems table with new systems table and re-indexing - please wait");
                    reportProgress(-1, "Replacing old systems table with new systems table and re-indexing - please wait");
                    SQLiteConnectionSystem.ReplaceSystemsTable();
                    SQLiteConnectionSystem.PutSettingBool("EDSMSystemsOutOfOrder", outoforder);
                    reportProgress(-1, "");
                }
                else
                {
                    throw new OperationCanceledException();
                }
            });

            if (!success)
            {
                logLine("Failed to download EDSM system file from server, will check next time");
                return(false);
            }

            // Stop if requested
            if (cancelRequested())
            {
                return(false);
            }

            logLine("Local database updated with EDSM data, " + updates + " systems updated.");

            GC.Collect();

            return(updates > 0);
        }