Example #1
0
        private void DoPerformSync()                                      // in Background worker
        {
            InvokeAsyncOnUiThread.Invoke(() => OnSyncStarting?.Invoke()); // tell listeners sync is starting

            resyncEDSMEDDBRequestedFlag = 1;                              // sync is happening, stop any async requests..

            Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Perform EDSM/EDDB sync");
            try
            {
                bool[] grids = new bool[GridId.MaxGridID];
                foreach (int i in GridId.FromString(EDDConfig.Instance.EDSMGridIDs))
                {
                    grids[i] = true;
                }

                syncstate.ClearCounters();

                if (syncstate.perform_edsm_fullsync || syncstate.perform_eddb_sync)
                {
                    if (syncstate.perform_edsm_fullsync && !PendingClose)
                    {
                        // Download new systems
                        try
                        {
                            syncstate.edsm_fullsync_count   = SystemClassEDSM.PerformEDSMFullSync(grids, () => PendingClose, ReportSyncProgress, LogLine, LogLineHighlight);
                            syncstate.perform_edsm_fullsync = false;
                        }
                        catch (Exception ex)
                        {
                            LogLineHighlight("GetAllEDSMSystems exception:" + ex.Message);
                        }
                    }

                    if (!PendingClose)
                    {
                        SQLiteConnectionSystem.CreateSystemsTableIndexes();  // again check indexes.. sometimes SQL does not create them due to schema change

                        try
                        {
                            syncstate.eddb_sync_count   = EliteDangerousCore.EDDB.SystemClassEDDB.PerformEDDBFullSync(() => PendingClose, ReportSyncProgress, LogLine, LogLineHighlight);
                            syncstate.perform_eddb_sync = false;
                        }
                        catch (Exception ex)
                        {
                            LogLineHighlight("GetEDDBUpdate exception: " + ex.Message);
                        }
                    }
                }

                if (!PendingClose)
                {
                    SQLiteConnectionSystem.CreateSystemsTableIndexes();         // again check indexes.. sometimes SQL does not create them due to schema change

                    syncstate.edsm_updatesync_count = EliteDangerousCore.EDSM.SystemClassEDSM.PerformEDSMUpdateSync(grids, () => PendingClose, ReportSyncProgress, LogLine, LogLineHighlight);
                }
            }
            catch (OperationCanceledException)
            {
                // Swallow Operation Cancelled exceptions
            }
            catch (Exception ex)
            {
                LogLineHighlight("Check Systems exception: " + ex.Message + Environment.NewLine + "Trace: " + ex.StackTrace);
            }

            InvokeAsyncOnUiThread(() => PerformSyncCompleted());
        }
Example #2
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"));
            }
        }