private void RefreshHistoryWorkerCompleted(HistoryList hist) { if (!PendingClose) { if (hist != null) { history.Copy(hist); OnRefreshCommanders?.Invoke(); if (history.CommanderId >= 0 && history.CommanderId != EdsmLogFetcher.CommanderId) // not hidden, and not last cmdr { EdsmLogFetcher.StopCheck(); // ENSURE stopped. it was asked to be stop on the refresh, so should be EdsmLogFetcher = new EDSMLogFetcher(history.CommanderId, LogLine); EdsmLogFetcher.OnDownloadedSystems += () => RefreshHistoryAsync(); } ReportProgress(-1, ""); LogLine("Refresh Complete."); RefreshDisplays(); } HistoryRefreshed?.Invoke(this, EventArgs.Empty); // Internal hook call journalmonitor.StartMonitor(); EdsmLogFetcher.Start(); // EDSM log fetcher was stopped, restart it.. ignored if not a valid commander or disabled. OnRefreshComplete?.Invoke(); // History is completed refreshRequestedFlag = 0; readyForNewRefresh.Set(); } }
public void Shutdown() { if (!PendingClose) { PendingClose = true; EDDNSync.StopSync(); EdsmSync.StopSync(); EdsmLogFetcher.AsyncStop(); journalmonitor.StopMonitor(); LogLineHighlight("Closing down, please wait.."); Console.WriteLine("Close.. safe close launched"); closeRequested.Set(); } }
// this thread waits around until told to do a refresh then performs it. // ONLY used for subsequent refreshes, first one done on background worker private void BackgroundHistoryRefreshWorkerThread() { System.Diagnostics.Debug.WriteLine("Background history refresh worker thread going.. waiting for read for refresh"); WaitHandle.WaitAny(new WaitHandle[] { closeRequested, readyForNewRefresh }); // Wait to be ready for new refresh after initial load caused by DoRefreshHistory, called by the controller. It sets the flag System.Diagnostics.Debug.WriteLine("Background history refresh worker thread refresh given permission, close " + PendingClose); while (!PendingClose) { int wh = WaitHandle.WaitAny(new WaitHandle[] { closeRequested, refreshRequested }); // wait for a second and subsequent refresh request. System.Diagnostics.Debug.WriteLine("Background history refresh worker - kicked due to " + wh); if (PendingClose) { break; } switch (wh) { case 0: // Close Requested break; case 1: // Refresh Requested journalmonitor.StopMonitor(); // this is called by the foreground. Ensure background is stopped. Foreground must restart it. EdsmLogFetcher.AsyncStop(); InvokeAsyncOnUiThread(() => { OnRefreshStarting?.Invoke(); }); RefreshWorkerArgs argstemp = null; RefreshWorkerArgs args = null; while (refreshWorkerQueue.TryDequeue(out argstemp)) // Get the most recent refresh { args = argstemp; } if (args != null) { readyForNewRefresh.Reset(); DoRefreshHistory(args); WaitHandle.WaitAny(new WaitHandle[] { closeRequested, readyForNewRefresh }); // Wait to be ready for new refresh } break; } } }
public void Shutdown() { if (!PendingClose) { PendingClose = true; EDDNSync.StopSync(); EDSMJournalSync.StopSync(); EdsmLogFetcher.AsyncStop(); journalmonitor.StopMonitor(); LogLineHighlight("Closing down, please wait..".Tx(this, "CD")); closeRequested.Set(); journalqueuedelaytimer.Change(Timeout.Infinite, Timeout.Infinite); journalqueuedelaytimer.Dispose(); } }
public void Shutdown() // called to request a shutdown.. background thread co-ords the shutdown. { if (!PendingClose) { PendingClose = true; EDDNSync.StopSync(); EDSMJournalSync.StopSync(); EdsmLogFetcher.AsyncStop(); journalmonitor.StopMonitor(); LogLineHighlight("Closing down, please wait..".T(EDTx.EDDiscoveryController_CD)); closeRequested.Set(); journalqueuedelaytimer.Change(Timeout.Infinite, Timeout.Infinite); journalqueuedelaytimer.Dispose(); } }
// Called on foreground after history has refreshed private void ForegroundHistoryRefreshCompleteonUI(HistoryList hist) { Debug.Assert(System.Windows.Forms.Application.MessageLoop); if (!PendingClose) { Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Refresh history worker completed"); if (hist != null) { history.Copy(hist); OnRefreshCommanders?.Invoke(); EdsmLogFetcher.StopCheck(); Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Refresh Displays"); OnHistoryChange?.Invoke(history); Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Refresh Displays Completed"); } Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " JM On"); journalmonitor.StartMonitor(); Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Call Refresh Complete"); OnRefreshComplete?.Invoke(); // History is completed if (history.CommanderId >= 0) { EdsmLogFetcher.Start(EDCommander.Current); } refreshHistoryRequestedFlag = 0; readyForNewRefresh.Set(); // say i'm okay for another refresh System.Diagnostics.Debug.WriteLine("Refresh completed, allow another refresh"); LogLine("History refresh complete.".T(EDTx.EDDiscoveryController_HRC)); ReportRefreshProgress(-1, ""); Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Refresh history complete"); } }
// this thread waits around until told to do a refresh then performs it. // ONLY used for subsequent refreshes, first one done on background worker private void BackgroundHistoryRefreshWorkerThread() { // TBD why swalllow one of these.. logic again seems convoluted WaitHandle.WaitAny(new WaitHandle[] { closeRequested, readyForNewRefresh }); // Wait to be ready for new refresh after initial refresh while (!PendingClose) { int wh = WaitHandle.WaitAny(new WaitHandle[] { closeRequested, refreshRequested }); RefreshWorkerArgs argstemp = null; RefreshWorkerArgs args = null; if (PendingClose) { break; } switch (wh) { case 0: // Close Requested break; case 1: // Refresh Requested journalmonitor.StopMonitor(); // this is called by the foreground. Ensure background is stopped. Foreground must restart it. EdsmLogFetcher.AsyncStop(); InvokeAsyncOnUiThread(() => { OnRefreshStarting?.Invoke(); }); while (refreshWorkerQueue.TryDequeue(out argstemp)) // Get the most recent refresh { args = argstemp; } if (args != null) { readyForNewRefresh.Reset(); DoRefreshHistory(args); WaitHandle.WaitAny(new WaitHandle[] { closeRequested, readyForNewRefresh }); // Wait to be ready for new refresh } break; } } }
private void RefreshHistoryWorkerCompleted(HistoryList hist) { if (!PendingClose) { Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " Refresh history worker completed"); if (hist != null) { history.Copy(hist); OnRefreshCommanders?.Invoke(); EdsmLogFetcher.StopCheck(); ReportProgress(-1, ""); LogLine("Refresh Complete."); RefreshDisplays(); Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " Refresh Displays Completed"); } Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " HR Refresh"); HistoryRefreshed?.Invoke(this, EventArgs.Empty); // Internal hook call Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " JMOn"); journalmonitor.StartMonitor(); Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " RFcomplete"); OnRefreshComplete?.Invoke(); // History is completed if (history.CommanderId >= 0) { EdsmLogFetcher.Start(EDCommander.Current); } refreshRequestedFlag = 0; readyForNewRefresh.Set(); Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " refresh history complete"); } }
private void RefreshHistoryWorkerCompleted(HistoryList hist) { if (!PendingClose) { if (hist != null) { OnRefreshCommanders?.Invoke(); history.Clear(); foreach (var ent in hist.EntryOrder) { history.Add(ent); Debug.Assert(ent.MaterialCommodity != null); } history.materialcommodititiesledger = hist.materialcommodititiesledger; history.starscan = hist.starscan; history.shipinformationlist = hist.shipinformationlist; history.CommanderId = hist.CommanderId; if (history.CommanderId != EdsmLogFetcher.CommanderId) { EdsmLogFetcher = new EDSMLogFetcher(history.CommanderId, LogLine); EdsmLogFetcher.OnDownloadedSystems += () => RefreshHistoryAsync(); } ReportProgress(-1, ""); LogLine("Refresh Complete."); RefreshDisplays(); } HistoryRefreshed?.Invoke(this, EventArgs.Empty); // Internal hook call journalmonitor.StartMonitor(); EdsmLogFetcher.Start(); OnRefreshComplete?.Invoke(); // History is completed refreshRequestedFlag = 0; readyForNewRefresh.Set(); } }
// Called on foreground after history has refreshed private void ForegroundHistoryRefreshComplete(HistoryList hist) { Debug.Assert(System.Windows.Forms.Application.MessageLoop); if (!PendingClose) { Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " Refresh history worker completed"); if (hist != null) { history.Copy(hist); OnRefreshCommanders?.Invoke(); EdsmLogFetcher.StopCheck(); ReportProgress(-1, ""); RefreshDisplays(); Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " Refresh Displays Completed"); } Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " JMOn"); journalmonitor.StartMonitor(); Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " RFcomplete"); OnRefreshComplete?.Invoke(); // History is completed if (history.CommanderId >= 0) { EdsmLogFetcher.Start(EDCommander.Current); } refreshHistoryRequestedFlag = 0; readyForNewRefresh.Set(); LogLine("History refresh complete."); Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " refresh history complete"); } }
// this thread waits around until told to do a refresh then performs it. // ONLY used for subsequent refreshes, first one done on background worker private void BackgroundHistoryRefreshWorkerThread() { System.Diagnostics.Debug.WriteLine("Background history refresh worker thread going.. waiting for read for refresh"); WaitHandle.WaitAny(new WaitHandle[] { closeRequested, readyForNewRefresh }); // Wait to be ready for new refresh after initial load caused by DoRefreshHistory, called by the controller. It sets the flag System.Diagnostics.Debug.WriteLine("Background history refresh worker thread refresh given permission, close " + PendingClose); int capirefreshinterval = 10000; // how often we check CAPI system. This is not the poll interval. while (!PendingClose) { int wh = WaitHandle.WaitAny(new WaitHandle[] { closeRequested, refreshRequested }, capirefreshinterval); // wait for a second and subsequent refresh request. if (PendingClose) { break; } switch (wh) { case 0: // Close Requested break; case 1: // Refresh Requested journalmonitor.StopMonitor(); // this is called by the foreground. Ensure background is stopped. Foreground must restart it. EdsmLogFetcher.AsyncStop(); InvokeAsyncOnUiThread(() => { OnRefreshStarting?.Invoke(); }); RefreshWorkerArgs argstemp = null; RefreshWorkerArgs args = null; while (refreshWorkerQueue.TryDequeue(out argstemp)) // Get the most recent refresh { args = argstemp; } if (args != null) { readyForNewRefresh.Reset(); DoRefreshHistory(args); WaitHandle.WaitAny(new WaitHandle[] { closeRequested, readyForNewRefresh }); // Wait to be ready for new refresh } break; case WaitHandle.WaitTimeout: if (EDCommander.Current.ConsoleCommander && FrontierCAPI.Active) { var retstate = FrontierCAPI.ManageJournalDownload(EDCommander.Current.ConsoleUploadHistory, EDDOptions.Instance.CAPIDirectory(), EDCommander.Current.Name, new TimeSpan(0, 30, 0), // journal poll interval 28); // and days back in time to look if (EDCommander.Current.ConsoleUploadHistory == null || !retstate.DeepEquals(EDCommander.Current.ConsoleUploadHistory)) // if changed { EDCommander.Current.ConsoleUploadHistory = retstate; EDCommander.Current.Update(); } } break; } } }
// Called on foreground after history has refreshed private void ForegroundHistoryRefreshCompleteonUI(HistoryList hist) { Debug.Assert(System.Windows.Forms.Application.MessageLoop); if (!PendingClose) { Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Refresh history worker completed"); if (hist != null) { history.Copy(hist); OnRefreshCommanders?.Invoke(); EdsmLogFetcher.StopCheck(); Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Refresh Displays"); OnHistoryChange?.Invoke(history); Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Refresh Displays Completed"); } Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " JM On"); journalmonitor.StartMonitor(true); Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Call Refresh Complete"); OnRefreshComplete?.Invoke(); // History is completed FrontierCAPI.Disconnect(); // Disconnect capi from current user, but don't clear their credential file // available, and not hidden commander, and we have logged in before if (FrontierCAPI.ClientIDAvailable && EDCommander.Current.Id >= 0 && FrontierCAPI.GetUserState(EDCommander.Current.Name) != CAPI.CompanionAPI.UserState.NeverLoggedIn) { System.Threading.Tasks.Task.Run(() => // don't hold up the main thread, do it in a task, as its a HTTP operation { FrontierCAPI.LogIn(EDCommander.Current.Name); // try and get to Active. May cause a new frontier login if (FrontierCAPI.Active) // if active, indicate { LogLine("CAPI User Logged in"); } else { LogLine("CAPI Require Log in"); } }); } if (history.CommanderId >= 0) { EdsmLogFetcher.Start(EDCommander.Current); } refreshHistoryRequestedFlag = 0; readyForNewRefresh.Set(); // say i'm okay for another refresh System.Diagnostics.Debug.WriteLine("Refresh completed, allow another refresh"); LogLine("History refresh complete.".T(EDTx.EDDiscoveryController_HRC)); ReportRefreshProgress(-1, ""); Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Refresh history complete"); } }