public bool Import(out string result) { if (!ReadFile()) { result = "The import file could not be read with specified settings."; return(false); } if (DateCol.HasValue) { foreach (ImportSystem sys in SystemsForImport) { if (!ImportJump(sys)) { result = string.Format("Travel History import failed at {0}.", sys.SysName); return(false); } } } if (SysNoteCol.HasValue) { foreach (ImportSystem sys in SystemsForImport) { if (!ImportNote(sys)) { result = string.Format("System Note import failed at {0}.", sys.SysName); return(false); } SystemNoteClass.GetAllSystemNotes(); } } result = "File imported successfully"; return(true); }
private void BackgroundInit() { StarScan.LoadBodyDesignationMap(); MaterialCommodityDB.SetUpInitialTable(); if (!EDDOptions.Instance.NoSystemsLoad) { downloadMapsTask = FGEImage.DownloadMaps(this, () => PendingClose, LogLine, LogLineHighlight); CheckSystems(() => PendingClose, (p, s) => ReportProgress(p, s)); } SystemNoteClass.GetAllSystemNotes(); // fill up memory with notes, bookmarks, galactic mapping BookmarkClass.GetAllBookmarks(); ReportProgress(-1, ""); InvokeAsyncOnUiThread(() => OnInitialSyncComplete?.Invoke()); 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!"); } } if (PendingClose) { return; } LogLine("Reading travel history"); if (!EDDOptions.Instance.NoLoad) { DoRefreshHistory(new RefreshWorkerArgs { CurrentCommander = EDCommander.CurrentCmdrID }); } if (PendingClose) { return; } if (syncstate.performeddbsync || syncstate.performedsmsync) { string databases = (syncstate.performedsmsync && syncstate.performeddbsync) ? "EDSM and EDDB" : ((syncstate.performedsmsync) ? "EDSM" : "EDDB"); LogLine("ED Discovery will now synchronise to the " + databases + " databases to obtain star information." + 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."); } InvokeAsyncOnUiThread(() => OnInitialisationComplete?.Invoke()); }
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; } } }
public override bool ToCSV(string filename) { try { using (StreamWriter writer = new StreamWriter(filename)) { if (IncludeHeader) { writer.Write("StarName" + delimiter); writer.Write("JournalEntry" + delimiter); writer.Write("EDSMID" + delimiter); writer.Write("Time" + delimiter); writer.Write("Note"); writer.WriteLine(); } SystemNoteClass.GetAllSystemNotes(); foreach (SystemNoteClass snc in SystemNoteClass.globalSystemNotes) { writer.Write(MakeValueCsvFriendly(snc.SystemName.Length > 0 ? snc.SystemName : "N/A")); writer.Write(MakeValueCsvFriendly(snc.Journalid > 0 ? snc.Journalid.ToString() : "N/A")); writer.Write(MakeValueCsvFriendly(snc.EdsmId > 0 ? snc.EdsmId.ToString() : "N/A")); writer.Write(MakeValueCsvFriendly(snc.Time)); writer.Write(MakeValueCsvFriendly(snc.Note, false)); writer.WriteLine(); } } return(true); } catch (IOException) { ExtendedControls.MessageBoxTheme.Show(String.Format("Is file {0} open?", filename), TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }
// 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")); } }
private void BackgroundWorkerThread() { // check first and download items StarScan.LoadBodyDesignationMap(); Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems"); ReportSyncProgress(""); 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) { // New Galmap load - it was not doing a refresh if EDSM sync kept on happening. Now has its own timer DateTime galmaptime = SystemsDatabase.Instance.GetEDSMGalMapLast(); // Latest time from RW file. if (DateTime.Now.Subtract(galmaptime).TotalDays > 14 || !galacticMapping.GalMapFilePresent()) // Over 14 days do a sync from EDSM for galmap { LogLine("Get galactic mapping from EDSM.".T(EDTx.EDDiscoveryController_EDSM)); if (galacticMapping.DownloadFromEDSM()) { SystemsDatabase.Instance.SetEDSMGalMapLast(DateTime.UtcNow); } } Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems complete"); } galacticMapping.ParseData(); // at this point, gal map data has been uploaded - get it into memory SystemCache.AddToAutoCompleteList(galacticMapping.GetGMONames()); SystemNoteClass.GetAllSystemNotes(); LogLine("Loaded Notes, Bookmarks and Galactic mapping.".T(EDTx.EDDiscoveryController_LN)); 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!".T(EDTx.EDDiscoveryController_EDMC)); } } if (!EDDOptions.Instance.NoLoad) // here in this thread, we do a refresh of history. { LogLine("Reading travel history".T(EDTx.EDDiscoveryController_RTH)); if (EDDOptions.Instance.Commander != null) { EDCommander switchto = EDCommander.GetCommander(EDDOptions.Instance.Commander); if (switchto != null) { EDCommander.CurrentCmdrID = switchto.Nr; } } DoRefreshHistory(new RefreshWorkerArgs { CurrentCommander = EDCommander.CurrentCmdrID }); // kick the background refresh worker thread into action } CheckForSync(); // see if any EDSM/EDDB sync is needed - this just sets some variables up System.Diagnostics.Debug.WriteLine("Background worker setting up refresh worker"); backgroundRefreshWorker = new Thread(BackgroundHistoryRefreshWorkerThread) { Name = "Background Refresh Worker", IsBackground = true }; backgroundRefreshWorker.Start(); // start the refresh worker, another thread which does subsequenct (not the primary one) refresh work in the background.. try { if (!EDDOptions.Instance.NoSystemsLoad) { SystemsDatabase.Instance.WithReadWrite(() => DoPerformSync()); // this is done after the initial history load.. } SystemsDatabase.Instance.SetReadOnly(); while (!PendingClose) { int wh = WaitHandle.WaitAny(new WaitHandle[] { closeRequested, resyncRequestedEvent }); System.Diagnostics.Debug.WriteLine("Background worker kicked by " + wh); if (PendingClose) { break; } if (wh == 1) { if (!EDDOptions.Instance.NoSystemsLoad && EDDConfig.Instance.EDSMEDDBDownload) // if no system off, and EDSM download on { SystemsDatabase.Instance.WithReadWrite(() => DoPerformSync()); } } } } catch (OperationCanceledException) { } backgroundRefreshWorker.Join(); // this should terminate due to closeRequested.. System.Diagnostics.Debug.WriteLine("BW Refresh joined"); // Now we have been ordered to close down, so go thru the process closeRequested.WaitOne(); InvokeAsyncOnUiThread(() => { System.Diagnostics.Debug.WriteLine("Final close"); OnFinalClose?.Invoke(); }); }
private void BackgroundWorkerThread() { // check first and download items string desigmapfile = Path.Combine(EDDOptions.Instance.AppDataDirectory, "bodydesignations.csv"); if (!File.Exists(desigmapfile)) { desigmapfile = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "bodydesignations.csv"); } BodyDesignations.LoadBodyDesignationMap(desigmapfile); Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems"); ReportSyncProgress(""); bool checkGithub = EDDOptions.Instance.CheckGithubFiles; if (checkGithub) // not normal in debug, due to git hub choking { DateTime lastdownloadtime = UserDatabase.Instance.GetSettingDate("DownloadFilesLastTime", DateTime.MinValue); if (DateTime.UtcNow - lastdownloadtime >= new TimeSpan(24, 0, 0)) // only update once per day { // Expedition data DownloadExpeditions(() => PendingClose); // and Exploration data DownloadExploration(() => PendingClose); // and Help files DownloadHelp(() => PendingClose); UserDatabase.Instance.PutSettingDate("DownloadFilesLastTime", DateTime.UtcNow); } } string gmofile = Path.Combine(EDDOptions.Instance.AppDataDirectory, "galacticmapping.json"); if (!EDDOptions.Instance.NoSystemsLoad) { // New Galmap load - it was not doing a refresh if EDSM sync kept on happening. Now has its own timer DateTime galmaptime = SystemsDatabase.Instance.GetEDSMGalMapLast(); // Latest time from RW file. if (DateTime.Now.Subtract(galmaptime).TotalDays > 14 || !File.Exists(gmofile)) // Over 14 days do a sync from EDSM for galmap { LogLine("Get galactic mapping from EDSM.".T(EDTx.EDDiscoveryController_EDSM)); if (galacticMapping.DownloadFromEDSM(gmofile)) { SystemsDatabase.Instance.SetEDSMGalMapLast(DateTime.UtcNow); } } Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems complete"); } if (File.Exists(gmofile)) { galacticMapping.Parse(gmofile); // at this point, gal map data has been uploaded - get it into memory } SystemCache.AddToAutoCompleteList(galacticMapping.GetGMONames()); SystemNoteClass.GetAllSystemNotes(); LogLine("Loaded Notes, Bookmarks and Galactic mapping.".T(EDTx.EDDiscoveryController_LN)); if (!EDDOptions.Instance.NoLoad) // here in this thread, we do a refresh of history. { LogLine("Reading travel history".T(EDTx.EDDiscoveryController_RTH)); if (EDDOptions.Instance.Commander != null) { EDCommander switchto = EDCommander.GetCommander(EDDOptions.Instance.Commander); if (switchto != null) { EDCommander.CurrentCmdrID = switchto.Id; } } DoRefreshHistory(new RefreshWorkerArgs { CurrentCommander = EDCommander.CurrentCmdrID }); // kick the background refresh worker thread into action } CheckForSync(); // see if any EDSM sync is needed - this just sets some variables up System.Diagnostics.Debug.WriteLine("Background worker setting up refresh worker"); backgroundRefreshWorker = new Thread(BackgroundHistoryRefreshWorkerThread) { Name = "Background Refresh Worker", IsBackground = true }; backgroundRefreshWorker.Start(); // start the refresh worker, another thread which does subsequenct (not the primary one) refresh work in the background.. try { if (!EDDOptions.Instance.NoSystemsLoad) { SystemsDatabase.Instance.WithReadWrite(() => DoPerformSync()); // this is done after the initial history load.. } SystemsDatabase.Instance.SetReadOnly(); while (!PendingClose) { int wh = WaitHandle.WaitAny(new WaitHandle[] { closeRequested, resyncRequestedEvent }); System.Diagnostics.Debug.WriteLine("Background worker kicked by " + wh); if (PendingClose) { break; } if (wh == 1) { if (!EDDOptions.Instance.NoSystemsLoad && EDDConfig.Instance.EDSMDownload) // if no system off, and EDSM download on { SystemsDatabase.Instance.WithReadWrite(() => DoPerformSync()); } } } } catch (OperationCanceledException) { } backgroundRefreshWorker.Join(); // this should terminate due to closeRequested.. System.Diagnostics.Debug.WriteLine("BW Refresh joined"); // Now we have been ordered to close down, so go thru the process closeRequested.WaitOne(); InvokeAsyncOnUiThread(() => { System.Diagnostics.Debug.WriteLine("Final close"); OnFinalClose?.Invoke(); }); }
// I think we rework so we have a SyncBackgroundworker, and a refresh background worker. // loading of history is done on refresh one.. private void BackgroundWorkerThread() { readyForInitialLoad.WaitOne(); // wait for shown in form // check first and download items StarScan.LoadBodyDesignationMap(); Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems"); ReportSyncProgress(""); 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) { // New Galmap load - it was not doing a refresh if EDSM sync kept on happening. Now has its own timer DateTime galmaptime = SQLiteConnectionSystem.GetSettingDate("EDSMGalMapLast", DateTime.MinValue); // Latest time from RW file. if (DateTime.Now.Subtract(galmaptime).TotalDays > 14 || !galacticMapping.GalMapFilePresent()) // Over 14 days do a sync from EDSM for galmap { LogLine("Get galactic mapping from EDSM.".Tx(this, "EDSM")); if (galacticMapping.DownloadFromEDSM()) { SQLiteConnectionSystem.PutSettingDate("EDSMGalMapLast", DateTime.UtcNow); } } Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems complete"); } galacticMapping.ParseData(); // at this point, gal map data has been uploaded - get it into memory SystemCache.AddToAutoCompleteList(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; } CheckForSync(); // see if any EDSM/EDDB sync is needed if (PendingClose) { return; } // Now stay in loop services stuff backgroundRefreshWorker = new Thread(BackgroundHistoryRefreshWorkerThread) { Name = "Background Refresh Worker", IsBackground = true }; backgroundRefreshWorker.Start(); // start the refresh worker, another thread which does subsequenct (not the primary one) refresh work in the background.. try { if (!EDDOptions.Instance.NoSystemsLoad && EDDConfig.Instance.EDSMEDDBDownload) // if no system off, and EDSM download on { DoPerformSync(); // this is done after the initial history load.. } while (!PendingClose) { int wh = WaitHandle.WaitAny(new WaitHandle[] { closeRequested, resyncRequestedEvent }); if (PendingClose) { break; } switch (wh) { case 0: // Close Requested break; case 1: // Resync Requested if (!EDDOptions.Instance.NoSystemsLoad && EDDConfig.Instance.EDSMEDDBDownload) // if no system off, and EDSM download on { DoPerformSync(); } break; } } } catch (OperationCanceledException) { } backgroundRefreshWorker.Join(); // Now we have been ordered to close down, so go thru the process closeRequested.WaitOne(); OnBgSafeClose?.Invoke(); ReadyForFinalClose = true; InvokeAsyncOnUiThread(() => { OnFinalClose?.Invoke(); }); }