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();
            }
        }
Beispiel #2
0
        void ActionEntry(JournalEntry je) // issue the JE to the system
        {
            if (je.IsUIEvent)             // give windows time to set up for OnNewEvent, and tell them if its coming via showuievents
            {
                if (je is EliteDangerousCore.JournalEvents.JournalMusic)
                {
                    //System.Diagnostics.Debug.WriteLine("Dispatch from controller Journal UI event ");
                    OnNewUIEvent?.Invoke(new EliteDangerousCore.UIEvents.UIJournalMusic((je as EliteDangerousCore.JournalEvents.JournalMusic).MusicTrack, EDDConfig.Instance.ShowUIEvents, DateTime.UtcNow, false));
                }
            }

            OnNewJournalEntry?.Invoke(je);          // Always call this on all entries...

            // filter out commanders, and filter out any UI events
            if (je.CommanderId == history.CommanderId && (!je.IsUIEvent || EDDConfig.Instance.ShowUIEvents))
            {
                HistoryEntry he = history.AddJournalEntry(je, h => LogLineHighlight(h)); // add a new one on top
                //System.Diagnostics.Debug.WriteLine("Add HE " + he.EventSummary);
                OnNewEntry?.Invoke(he, history);                                         // major hook
                OnNewEntrySecond?.Invoke(he, history);                                   // secondary hook..
            }

            if (je.EventTypeID == JournalTypeEnum.LoadGame) // and issue this on Load game
            {
                OnRefreshCommanders?.Invoke();
            }
        }
        public void NewEntry(JournalEntry je)          // hooked into journal monitor and receives new entries.. Also call if you programatically add an entry
        {
            if (je.CommanderId == history.CommanderId) // we are only interested at this point accepting ones for the display commander
            {
                bool uievent = je.IsUIEvent;

                if (!je.IsUIEvent || EDDConfig.Instance.ShowUIEvents)              // filter out any UI events
                {
                    foreach (HistoryEntry he in history.AddJournalEntry(je, h => LogLineHighlight(h)))
                    {
                        OnNewEntry?.Invoke(he, history);            // major hook
                        OnNewEntrySecond?.Invoke(he, history);      // secondary hook..
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("**** Filter out " + je.EventTypeStr);
                }

                if (uievent)
                {
                    if (je is EliteDangerousCore.JournalEvents.JournalMusic)
                    {
                        OnNewUIEvent?.Invoke((je as EliteDangerousCore.JournalEvents.JournalMusic).MusicTrack);
                    }
                }
            }

            OnNewJournalEntry?.Invoke(je);

            if (je.EventTypeID == JournalTypeEnum.LoadGame)
            {
                OnRefreshCommanders?.Invoke();
            }
        }
        private void ActionEntry(JournalEntry je)               // UI thread issue the JE to the system
        {
            System.Diagnostics.Trace.WriteLine(string.Format(Environment.NewLine + "New JEntry {0} {1}", je.EventTimeUTC, je.EventTypeStr));

            OnNewJournalEntry?.Invoke(je);          // Always call this on all entries...

            // filter out commanders, and filter out any UI events
            if (je.CommanderId == history.CommanderId)
            {
                BaseUtils.AppTicks.TickCountLapDelta("CTNE", true);

                var historyentries = history.AddJournalEntryToHistory(je, h => LogLineHighlight(h));        // add a new one on top, return a list of ones to process

                var t1 = BaseUtils.AppTicks.TickCountLapDelta("CTNE");
                if (t1.Item2 >= 20)
                {
                    System.Diagnostics.Trace.WriteLine(" NE Add Journal slow " + t1.Item1);
                }

                foreach (var he in historyentries.EmptyIfNull())
                {
                    if (OnNewEntry != null)
                    {
                        foreach (var e in OnNewEntry.GetInvocationList())       // do the invokation manually, so we can time each method
                        {
                            Stopwatch sw = new Stopwatch(); sw.Start();
                            e.DynamicInvoke(he, history);
                            if (sw.ElapsedMilliseconds >= 20)
                            {
                                System.Diagnostics.Trace.WriteLine(" NE Add Method " + e.Method.DeclaringType + " took " + sw.ElapsedMilliseconds);
                            }
                        }
                    }

                    var t2 = BaseUtils.AppTicks.TickCountLapDelta("CTNE");
                    if (t2.Item2 >= 40)
                    {
                        System.Diagnostics.Trace.WriteLine(" NE First Slow " + t2.Item1);
                    }

                    OnNewEntrySecond?.Invoke(he, history);      // secondary hook..

                    // finally, CAPI, if docked, and CAPI is go for pc commander, do capi procedure

                    if (he.EntryType == JournalTypeEnum.Docked && FrontierCAPI.Active && !EDCommander.Current.ConsoleCommander)
                    {
                        var dockevt = he.journalEntry as EliteDangerousCore.JournalEvents.JournalDocked;
                        DoCAPI(dockevt.StationName, he.System.Name, he.journalEntry.IsBeta, history.Shipyards.AllowCobraMkIV);
                    }

                    var t3 = BaseUtils.AppTicks.TickCountLapDelta("CTNE");
                    System.Diagnostics.Trace.WriteLine("NE END " + t3.Item1 + " " + (t3.Item3 > 99 ? "!!!!!!!!!!!!!" : ""));
                }
            }

            if (je.EventTypeID == JournalTypeEnum.LoadGame) // and issue this on Load game
            {
                OnRefreshCommanders?.Invoke();
            }
        }
Beispiel #5
0
        private void ActionEntry(JournalEntry je)               // UI thread issue the JE to the system
        {
            System.Diagnostics.Trace.WriteLine(string.Format(Environment.NewLine + "New JEntry {0} {1}", je.EventTimeUTC, je.EventTypeStr));

            OnNewJournalEntry?.Invoke(je);          // Always call this on all entries...

            // filter out commanders, and filter out any UI events
            if (je.CommanderId == history.CommanderId)
            {
                BaseUtils.AppTicks.TickCountLapDelta("CTNE", true);

                HistoryEntry he = history.AddJournalEntryToHistory(je, h => LogLineHighlight(h));        // add a new one on top

                var t1 = BaseUtils.AppTicks.TickCountLapDelta("CTNE");
                if (t1.Item2 >= 20)
                {
                    System.Diagnostics.Trace.WriteLine(" NE Add Journal slow " + t1.Item1);
                }

                if (he != null)     // may reject it
                {
                    if (OnNewEntry != null)
                    {
                        foreach (var e in OnNewEntry.GetInvocationList())       // do the invokation manually, so we can time each method
                        {
                            Stopwatch sw = new Stopwatch(); sw.Start();
                            e.DynamicInvoke(he, history);
                            if (sw.ElapsedMilliseconds >= 20)
                            {
                                System.Diagnostics.Trace.WriteLine(" NE Add Method " + e.Method.DeclaringType + " took " + sw.ElapsedMilliseconds);
                            }
                        }
                    }

                    var t2 = BaseUtils.AppTicks.TickCountLapDelta("CTNE");
                    if (t2.Item2 >= 40)
                    {
                        System.Diagnostics.Trace.WriteLine(" NE First Slow " + t2.Item1);
                    }

                    OnNewEntrySecond?.Invoke(he, history);      // secondary hook..

                    var t3 = BaseUtils.AppTicks.TickCountLapDelta("CTNE");
                    System.Diagnostics.Trace.WriteLine("NE END " + t3.Item1 + " " + (t3.Item3 > 99 ? "!!!!!!!!!!!!!" : ""));
                }
            }

            if (je.EventTypeID == JournalTypeEnum.LoadGame) // and issue this on Load game
            {
                OnRefreshCommanders?.Invoke();
            }
        }
Beispiel #6
0
        // 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");
            }
        }
Beispiel #7
0
        private void ActionEntry(JournalEntry je)   // UI thread issue the JE to the system
        {
            OnNewJournalEntry?.Invoke(je);          // Always call this on all entries...

            // filter out commanders, and filter out any UI events
            if (je.CommanderId == history.CommanderId)
            {
                HistoryEntry he = history.AddJournalEntry(je, h => LogLineHighlight(h)); // add a new one on top
                //System.Diagnostics.Debug.WriteLine("Add HE " + he.EventSummary);
                OnNewEntry?.Invoke(he, history);                                         // major hook
                OnNewEntrySecond?.Invoke(he, history);                                   // secondary hook..
            }

            if (je.EventTypeID == JournalTypeEnum.LoadGame) // and issue this on Load game
            {
                OnRefreshCommanders?.Invoke();
            }
        }
        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");
            }
        }
Beispiel #9
0
        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();
            }
        }
Beispiel #10
0
        // 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");
            }
        }
        public void NewEntry(JournalEntry je)          // hooked into journal monitor and receives new entries.. Also call if you programatically add an entry
        {
            if (je.CommanderId == history.CommanderId) // we are only interested at this point accepting ones for the display commander
            {
                foreach (HistoryEntry he in history.AddJournalEntry(je, h => LogLineHighlight(h)))
                {
                    {
                        OnNewEntry?.Invoke(he, history);        // major hook
                        OnNewEntrySecond?.Invoke(he, history);  // secondary hook..
                    }
                }
            }

            OnNewJournalEntry?.Invoke(je);

            if (je.EventTypeID == JournalTypeEnum.LoadGame)
            {
                OnRefreshCommanders?.Invoke();
            }
        }
Beispiel #12
0
        // 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");
            }
        }
Beispiel #13
0
        public void PlayJournalList()                 // UI Threead play delay list out..
        {
            Debug.Assert(System.Windows.Forms.Application.MessageLoop);
            //System.Diagnostics.Debug.WriteLine(Environment.TickCount + " Play out list");

            while (journalqueue.Count > 0)
            {
                var current = journalqueue.Dequeue();

                System.Diagnostics.Trace.WriteLine($"New JEntry {current.EventTimeUTC} {current.EventTypeStr}");

                BaseUtils.AppTicks.TickCountLapDelta("CTNE", true);

                if (current.CommanderId != history.CommanderId)         // remove non relevant jes
                {
                    continue;
                }

                OnNewJournalEntryUnfiltered?.Invoke(current);         // Called before any removal or merging, so this is the raw journal list
                HistoryEntry historyentry = history.MakeHistoryEntry(current);
                OnNewHistoryEntryUnfiltered?.Invoke(historyentry);

                while (journalqueue.Count > 0)                      // go thru the list and find merge candidates
                {
                    var peek = journalqueue.Peek();

                    if (peek.CommanderId != history.CommanderId)             // remove non relevant jes
                    {
                        journalqueue.Dequeue();                              // remove it
                    }
                    else if (HistoryList.MergeJournalEntries(current, peek)) // if the peeked is merged into current
                    {
                        OnNewJournalEntryUnfiltered?.Invoke(peek);           // send the peeked, unmodified
                        OnNewHistoryEntryUnfiltered?.Invoke(history.MakeHistoryEntry(peek));
                        journalqueue.Dequeue();                              // remove it
                    }
                    else
                    {
                        break;                                      // not mergable and since we peeked not removed
                    }
                }

                var historyentries = history.AddHistoryEntryToListWithReorder(historyentry, h => LogLineHighlight(h));   // add a new one on top of the HL, reorder, remove, return a list of ones to process

                foreach (var he in historyentries.EmptyIfNull())
                {
                    if (he.EntryType == JournalTypeEnum.CodexEntry)     // need to do some work on codex entry.. set bodyid as long as recorded body name matches tracking name, and update DB
                    {
                        var jce = he.journalEntry as EliteDangerousCore.JournalEvents.JournalCodexEntry;
                        if (jce.EDDBodyName == he.Status.BodyName)        // following EDDN advice, use status body name as master key
                        {
                            jce.EDDBodyId = he.Status.BodyID ?? -1;
                            System.Diagnostics.Debug.WriteLine($"Journal Codex set body ID to {jce.EDDBodyId} as ID");
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine($"Journal Codex WARNING name does not match {he.Status.BodyName} vs {jce.EDDBodyName} {jce.EDDBodyId}");
                        }
                        jce.UpdateDB();                     // write back
                    }

                    if (OnNewEntry != null)                               // issue to OnNewEntry handlers
                    {
                        foreach (var e in OnNewEntry.GetInvocationList()) // do the invokation manually, so we can time each method
                        {
                            Stopwatch sw = new Stopwatch(); sw.Start();
                            e.DynamicInvoke(he, history);
                            if (sw.ElapsedMilliseconds >= 20)
                            {
                                System.Diagnostics.Trace.WriteLine(" NE Add Method " + e.Method.DeclaringType + " took " + sw.ElapsedMilliseconds);
                            }
                        }
                    }

                    var t2 = BaseUtils.AppTicks.TickCountLapDelta("CTNE");
                    if (t2.Item2 >= 40)
                    {
                        System.Diagnostics.Trace.WriteLine(" NE First Slow " + t2.Item1);
                    }

                    OnNewEntrySecond?.Invoke(he, history);      // secondary hook..

                    // finally, CAPI, if docked, and CAPI is go for pc commander, do capi procedure

                    if (he.EntryType == JournalTypeEnum.Docked && FrontierCAPI.Active && !EDCommander.Current.ConsoleCommander)
                    {
                        var dockevt = he.journalEntry as EliteDangerousCore.JournalEvents.JournalDocked;
                        DoCAPI(dockevt.StationName, he.System.Name, he.journalEntry.IsBeta, history.Shipyards.AllowCobraMkIV);
                    }

                    var t3 = BaseUtils.AppTicks.TickCountLapDelta("CTNE");
                    System.Diagnostics.Trace.WriteLine("NE END " + t3.Item1 + " " + (t3.Item3 > 99 ? "!!!!!!!!!!!!!" : ""));
                }

                if (historyentry.EntryType == JournalTypeEnum.LoadGame) // and issue this on Load game
                {
                    OnRefreshCommanders?.Invoke();
                }
            }
        }
        private void ActionEntry(JournalEntry je)               // UI thread issue the JE to the system
        {
            System.Diagnostics.Trace.WriteLine(string.Format(Environment.NewLine + "New JEntry {0} {1}", je.EventTimeUTC, je.EventTypeStr));

            OnNewJournalEntry?.Invoke(je);          // Always call this on all entries...

            // filter out commanders, and filter out any UI events
            if (je.CommanderId == history.CommanderId)
            {
                BaseUtils.AppTicks.TickCountLapDelta("CTNE", true);

                HistoryEntry he = history.AddJournalEntryToHistory(je, h => LogLineHighlight(h));        // add a new one on top

                var t1 = BaseUtils.AppTicks.TickCountLapDelta("CTNE");
                if (t1.Item2 >= 20)
                {
                    System.Diagnostics.Trace.WriteLine(" NE Add Journal slow " + t1.Item1);
                }

                if (he != null)     // may reject it
                {
                    if (OnNewEntry != null)
                    {
                        foreach (var e in OnNewEntry.GetInvocationList())       // do the invokation manually, so we can time each method
                        {
                            Stopwatch sw = new Stopwatch(); sw.Start();
                            e.DynamicInvoke(he, history);
                            if (sw.ElapsedMilliseconds >= 20)
                            {
                                System.Diagnostics.Trace.WriteLine(" NE Add Method " + e.Method.DeclaringType + " took " + sw.ElapsedMilliseconds);
                            }
                        }
                    }

                    var t2 = BaseUtils.AppTicks.TickCountLapDelta("CTNE");
                    if (t2.Item2 >= 40)
                    {
                        System.Diagnostics.Trace.WriteLine(" NE First Slow " + t2.Item1);
                    }

                    OnNewEntrySecond?.Invoke(he, history);      // secondary hook..


                    // finally, CAPI, if docked, try and get commodity data, and if so, create a new EDD record.  Do not do this for console commanders

                    if (he.EntryType == JournalTypeEnum.Docked)
                    {
                        if (FrontierCAPI.Active && !EDCommander.Current.ConsoleCommander)
                        {
                            // don't hold up the main thread, do it in a task, as its a HTTP operation
                            // and wait for the CAPI to recover by delaying for 15 s

                            System.Threading.Tasks.Task.Delay(15000).ContinueWith((task) =>
                            {
                                var dockevt = he.journalEntry as EliteDangerousCore.JournalEvents.JournalDocked;

                                for (int tries = 0; tries < 3; tries++)
                                {
                                    FrontierCAPI.GameIsBeta = he.journalEntry.IsBeta;
                                    string marketjson       = FrontierCAPI.Market();

                                    CAPI.Market mk = new CAPI.Market(marketjson);
                                    if (mk.IsValid)
                                    {
                                        //System.IO.File.WriteAllText(@"c:\code\market.json", marketjson);

                                        if (dockevt.StationName.Equals(mk.Name, StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            System.Diagnostics.Trace.WriteLine($"CAPI got market {mk.Name}");

                                            var entry = new EliteDangerousCore.JournalEvents.JournalEDDCommodityPrices(he.EventTimeUTC.AddSeconds(1),
                                                                                                                       mk.ID, mk.Name, he.System.Name, EDCommander.CurrentCmdrID, mk.Commodities);

                                            var jo = entry.ToJSON();        // get json of it, and add it to the db
                                            entry.Add(jo);

                                            InvokeAsyncOnUiThread(() =>
                                            {
                                                Debug.Assert(System.Windows.Forms.Application.MessageLoop);
                                                System.Diagnostics.Debug.WriteLine("CAPI fire new entry");
                                                NewEntry(entry);                // then push it thru. this will cause another set of calls to NewEntry First/Second
                                                                                // EDDN handler will pick up EDDCommodityPrices and send it.
                                            });

                                            break;
                                        }
                                        else
                                        {
                                            LogLine("CAPI received incorrect information, retrying");
                                            System.Diagnostics.Trace.WriteLine($"CAPI disagree on market {dockevt.StationName} vs {mk.Name}");
                                        }
                                    }
                                    else
                                    {
                                        LogLine("CAPI market data invalid, retrying");
                                        System.Diagnostics.Trace.WriteLine($"CAPI market invalid {marketjson}");
                                    }

                                    Thread.Sleep(10000);
                                }
                            });
                        }
                    }


                    var t3 = BaseUtils.AppTicks.TickCountLapDelta("CTNE");
                    System.Diagnostics.Trace.WriteLine("NE END " + t3.Item1 + " " + (t3.Item3 > 99 ? "!!!!!!!!!!!!!" : ""));
                }
            }

            if (je.EventTypeID == JournalTypeEnum.LoadGame) // and issue this on Load game
            {
                OnRefreshCommanders?.Invoke();
            }
        }