Ejemplo n.º 1
0
 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();
     }
 }
Ejemplo n.º 2
0
        // 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;
                }
            }
        }
Ejemplo n.º 3
0
 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();
     }
 }
Ejemplo n.º 4
0
 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();
     }
 }
        // 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;
                }
            }
        }
Ejemplo n.º 6
0
        // 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;
                }
            }
        }