Beispiel #1
0
        // this function does the history refresh, executes on Background worker or background history refresh thread
        private void DoRefreshHistory(RefreshWorkerArgs args)
        {
            HistoryList hist = null;

            try
            {
                refreshWorkerArgs = args;

                Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Load history for Cmdr " + args.CurrentCommander + " " + EDCommander.Current.Name);

                if (args.RemoveDuplicateFSDEntries)
                {
                    int n = JournalEntry.RemoveDuplicateFSDEntries(EDCommander.CurrentCmdrID);
                    LogLine(string.Format("Removed {0} FSD entries".T(EDTx.EDDiscoveryForm_FSDRem), n));
                }

                hist = HistoryList.LoadHistory(journalmonitor,
                                               () => PendingClose,
                                               (p, s) => ReportRefreshProgress(p, string.Format("Processing log file {0}".T(EDTx.EDDiscoveryController_PLF), s)), args.NetLogPath,
                                               args.ForceNetLogReload, args.ForceJournalReload, args.CurrentCommander,
                                               EDDConfig.Instance.FullHistoryLoadDayLimit, EDDConfig.Instance.EssentialEventTypes);

                Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Load history complete with " + hist.Count + " records");
            }
            catch (Exception ex)
            {
                LogLineHighlight("History Refresh Error: " + ex);
            }

            ReportRefreshProgress(-1, "Refresh Displays".T(EDTx.EDDiscoveryController_RD));

            InvokeAsyncOnUiThread(() => ForegroundHistoryRefreshCompleteonUI(hist));
        }
Beispiel #2
0
        // this function does the history refresh, executes on Background worker or background history refresh thread
        private void DoRefreshHistory(RefreshWorkerArgs args)
        {
            HistoryList hist = null;

            try
            {
                refreshWorkerArgs = args;

                Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Load history for Cmdr " + args.CurrentCommander + " " + EDCommander.Current.Name);

                hist = HistoryList.LoadHistory(journalmonitor,
                                               () => PendingClose,
                                               (p, s) => ReportRefreshProgress(p, string.Format("Processing log file {0}".Tx(this, "PLF"), s)), args.NetLogPath,
                                               args.ForceJournalReload, args.ForceJournalReload, args.CurrentCommander,
                                               EDDConfig.Instance.ShowUIEvents,
                                               EDDConfig.Instance.FullHistoryLoadDayLimit, EDDConfig.Instance.EssentialEventTypes);

                Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Load history complete with " + hist.Count + " records");
            }
            catch (Exception ex)
            {
                LogLineHighlight("History Refresh Error: " + ex);
            }

            initComplete.WaitOne();

            ReportRefreshProgress(-1, "Refresh Displays".Tx(this, "RD"));

            InvokeAsyncOnUiThread(() => ForegroundHistoryRefreshComplete(hist));
        }
        // this function does the history refresh, executes on Background worker or background history refresh thread
        private void DoRefreshHistory(RefreshWorkerArgs args)
        {
            HistoryList hist = null;

            try
            {
                refreshWorkerArgs = args;

                Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Load history for Cmdr " + args.CurrentCommander + " " + EDCommander.Current.Name);

                if (args.RemoveDuplicateFSDEntries)
                {
                    int n = JournalEntry.RemoveDuplicateFSDEntries(EDCommander.CurrentCmdrID);
                    LogLine(string.Format("Removed {0} FSD entries".T(EDTx.EDDiscoveryForm_FSDRem), n));
                }

                if (args.CurrentCommander >= 0)                                              // if we have a real commander
                {
                    journalmonitor.SetupWatchers();                                          // monitors are stopped, set up watchers

                    int forcereloadoflastn = args.ForceJournalReload ? int.MaxValue / 2 : 0; // if forcing a reload, we indicate that by setting the reload count to a very high value, but not enough to cause int wrap

                    journalmonitor.ParseJournalFilesOnWatchers((p, s) => ReportRefreshProgress(p, string.Format("Processing log file {0}".T(EDTx.EDDiscoveryController_PLF), s)),
                                                               forcereloadoflastn);

                    if (args.NetLogPath != null)            // see if net logs need reading for old times sake.
                    {
                        NetLogClass.ParseFiles(args.NetLogPath, out string errstr, EDCommander.Current.MapColour, () => PendingClose, (p, s) => ReportRefreshProgress(p, s),
                                               args.ForceNetLogReload, currentcmdrid: args.CurrentCommander);
                    }
                }

                hist = HistoryList.LoadHistory((s) => ReportRefreshProgress(-1, s),
                                               args.CurrentCommander,
                                               EDDConfig.Instance.FullHistoryLoadDayLimit,
                                               EDDConfig.Instance.EssentialEventTypes
                                               );

                if (args.NetLogPath != null)
                {
                    ReportRefreshProgress(-1, "Netlog Updating System Positions");
                    hist.FillInPositionsFSDJumps(LogLine);                         // if netlog reading, try and resolve systems..
                }

                EDCommander.Current.FID = hist.GetCommanderFID();                   // ensure FID is set.. the other place it gets changed is a read of LoadGame.

                ReportRefreshProgress(-1, "Done");

                Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Load history complete with " + hist.Count + " records");
            }
            catch (Exception ex)
            {
                LogLineHighlight("History Refresh Error: " + ex);
            }

            ReportRefreshProgress(-1, "Refresh Displays".T(EDTx.EDDiscoveryController_RD));

            InvokeAsyncOnUiThread(() => ForegroundHistoryRefreshCompleteonUI(hist));
        }
Beispiel #4
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;
                }
            }
        }
        private void DoRefreshHistory(RefreshWorkerArgs args)
        {
            HistoryList hist = null;

            try
            {
                refreshWorkerArgs = args;
                hist = HistoryList.LoadHistory(journalmonitor, () => PendingClose, (p, s) => ReportProgress(p, $"Processing log file {s}"), args.NetLogPath, args.ForceJournalReload, args.ForceJournalReload, args.CheckEdsm, args.CurrentCommander);
            }
            catch (Exception ex)
            {
                LogLineHighlight("History Refresh Error: " + ex);
            }

            InvokeAsyncOnUiThread(() => RefreshHistoryWorkerCompleted(hist));
        }
        // 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;
                }
            }
        }
Beispiel #7
0
        // indicate change commander, indicate netlogpath load (with forced refresh), indicate forced journal load

        public bool RefreshHistoryAsync(string netlogpath = null, bool forcenetlogreload = false, bool forcejournalreload = false, int?currentcmdr = null, bool removedupfsdentries = false)
        {
            if (PendingClose)
            {
                return(false);
            }

            bool newrefresh = false;

            RefreshWorkerArgs curargs = refreshWorkerArgs;

            if (refreshHistoryRequestedFlag == 0)                                                           // if we are not operating
            {
                if (curargs == null ||                                                                      // and we have mateirlally changed comething important
                    curargs.ForceNetLogReload != forcenetlogreload ||
                    curargs.ForceJournalReload != forcejournalreload ||
                    curargs.CurrentCommander != (currentcmdr ?? history.CommanderId) ||
                    curargs.NetLogPath != netlogpath ||
                    curargs.RemoveDuplicateFSDEntries != removedupfsdentries)
                {
                    newrefresh = true;                                                                      // we queue the refresh, even if we have a async refresh pending..
                }
            }

            if (Interlocked.CompareExchange(ref refreshHistoryRequestedFlag, 1, 0) == 0 || newrefresh)      // set the refresh requested to 1 in all circumstances, to stop a
            {
                refreshWorkerQueue.Enqueue(new RefreshWorkerArgs
                {
                    NetLogPath                = netlogpath,
                    ForceNetLogReload         = forcenetlogreload,
                    ForceJournalReload        = forcejournalreload,
                    CurrentCommander          = currentcmdr ?? history.CommanderId,
                    RemoveDuplicateFSDEntries = removedupfsdentries
                });

                refreshRequested.Set();
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool RefreshHistoryAsync(string netlogpath = null, bool forcenetlogreload = false, bool forcejournalreload = false, bool checkedsm = false, int?currentcmdr = null)
        {
            if (PendingClose)
            {
                return(false);
            }

            bool newrefresh = false;

            RefreshWorkerArgs curargs = refreshWorkerArgs;

            if (refreshRequestedFlag == 0)
            {
                if (curargs == null ||
                    curargs.CheckEdsm != checkedsm ||
                    curargs.ForceNetLogReload != forcenetlogreload ||
                    curargs.ForceJournalReload != forcejournalreload ||
                    curargs.CurrentCommander != (currentcmdr ?? history.CommanderId) ||
                    curargs.NetLogPath != netlogpath)
                {
                    newrefresh = true;
                }
            }

            if (Interlocked.CompareExchange(ref refreshRequestedFlag, 1, 0) == 0 || newrefresh)
            {
                refreshWorkerQueue.Enqueue(new RefreshWorkerArgs
                {
                    NetLogPath         = netlogpath,
                    ForceNetLogReload  = forcenetlogreload,
                    ForceJournalReload = forcejournalreload,
                    CheckEdsm          = checkedsm,
                    CurrentCommander   = currentcmdr ?? history.CommanderId
                });

                refreshRequested.Set();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #9
0
        private void DoRefreshHistory(RefreshWorkerArgs args)
        {
            HistoryList hist = null;

            try
            {
                refreshWorkerArgs = args;
                Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " Load history");
                hist = HistoryList.LoadHistory(journalmonitor, () => PendingClose, (p, s) => ReportProgress(p, $"Processing log file {s}"), args.NetLogPath,
                                               args.ForceJournalReload, args.ForceJournalReload, args.CheckEdsm, args.CurrentCommander, EDDConfig.Instance.ShowUIEvents);
                Debug.WriteLine(BaseUtils.AppTicks.TickCount100 + " Load history complete");
            }
            catch (Exception ex)
            {
                LogLineHighlight("History Refresh Error: " + ex);
            }

            InvokeAsyncOnUiThread(() => RefreshHistoryWorkerCompleted(hist));
        }
Beispiel #10
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;
                }
            }
        }