Пример #1
0
        // Called by controller before any HL removal reorder. The raw HE stream.  The MCMR etc databases have been updated
        public void Controller_NewHistoryEntryUnfiltered(HistoryEntry he)
        {
            //he.FillInformation(out string ed, out string edi);System.Diagnostics.Debug.WriteLine($"HE Unfiltered {he.EntryType} {he.EventSummary} {ed}");
            System.Diagnostics.Debug.WriteLine($"HE Unfiltered {he.EntryType}");

            // EDSM needs the raw stream, so send it here..

            if (EDCommander.Current.SyncToEdsm && EDSMJournalSync.OkayToSend(he))
            {
                EDSMJournalSync.SendEDSMEvents(LogLine, new List <HistoryEntry>()
                {
                    he
                });                                                                             // send, if bad credentials, EDSM will moan alerting the user
            }

            // as does Inara. Note the MCMR has been updated.  Needed here due to using materials/cargo
            if (EDCommander.Current.SyncToInara)
            {
                var mcmr = history.MaterialCommoditiesMicroResources.GetDict(he.MaterialCommodity);
                EliteDangerousCore.Inara.InaraSync.NewEvent(LogLine, he, mcmr);
            }

            if (DLLManager.Count > 0)
            {
                DLLManager.NewUnfilteredJournalEntry(EliteDangerousCore.DLL.EDDDLLCallerHE.CreateFromHistoryEntry(history, he));       // give DLL the unfiltered stream
            }
        }
        private void Controller_NewEntrySecond(HistoryEntry he, HistoryList hl)         // called after all UI's have had their chance
        {
            BaseUtils.AppTicks.TickCountLapDelta("DFS", true);

            actioncontroller.ActionRunOnEntry(he, Actions.ActionEventEDList.NewEntry(he));

            var t1 = BaseUtils.AppTicks.TickCountLapDelta("DFS");

            if (t1.Item2 >= 80)
            {
                System.Diagnostics.Trace.WriteLine("NE Second Actions slow " + t1.Item1);
            }

            // all notes committed
            SystemNoteClass.CommitDirtyNotes((snc) => { if (EDCommander.Current.SyncToEdsm && snc.FSDEntry)
                                                        {
                                                            EDSMClass.SendComments(snc.SystemName, snc.Note, 0, he.Commander);
                                                        }
                                             });

            var lastent = history.GetLast;

            if (!object.ReferenceEquals(he, lastent))
            {
                LogLineHighlight(string.Format("Current history entry is not last in history - possible re-entrancy.\nAlert the EDDiscovery developers using either discord or Github (see help) and attach log file {0}", BaseUtils.TraceLog.LogFileName));
                Trace.WriteLine($"Current history entry is not last in history");
                Trace.WriteLine($"Current entry: {he.journalEntry?.GetJsonString()}");
                Trace.WriteLine($"Last entry: {lastent.journalEntry?.GetJsonString()}");
                Trace.WriteLine($"Stack Trace:");
                Trace.WriteLine(new StackTrace(true).ToString());
            }

            if (he.IsFSDCarrierJump)
            {
                int count = history.GetVisitsCount(he.System.Name);
                LogLine(string.Format("Arrived at system {0} Visit No. {1}".T(EDTx.EDDiscoveryForm_Arrived), he.System.Name, count));
                System.Diagnostics.Trace.WriteLine("Arrived at system: " + he.System.Name + " " + count + ":th visit.");
            }

            if (EDCommander.Current.SyncToEdsm && EDSMJournalSync.OkayToSend(he))           // send this one, if allowed.
            {
                EDSMJournalSync.SendEDSMEvents(LogLine, new List <HistoryEntry>()
                {
                    he
                });                                                                             // send, if bad credentials, EDSM will moan alerting the user
            }

            if (EDCommander.Current.SyncToInara)
            {
                EliteDangerousCore.Inara.InaraSync.NewEvent(LogLine, hl, he);
            }

            if (EDCommander.Current.SyncToIGAU)
            {
                EliteDangerousCore.IGAU.IGAUSync.NewEvent(LogLine, he);
            }

            if (EDCommander.Current.SyncToEDAstro)
            {
                EliteDangerousCore.EDAstro.EDAstroSync.SendEDAstroEvents(new List <HistoryEntry>()
                {
                    he
                });
            }

            if (EDDNClass.IsEDDNMessage(he.EntryType) && he.AgeOfEntry() < TimeSpan.FromDays(1.0) && EDCommander.Current.SyncToEddn == true)
            {
                EDDNSync.SendEDDNEvents(LogLine, he);
            }



            DLLManager.NewJournalEntry(EliteDangerousCore.DLL.EDDDLLCallerHE.CreateFromHistoryEntry(history, he), false);

            screenshotconverter.NewJournalEntry(he.journalEntry);       // tell the screenshotter.

            CheckActionProfile(he);
        }
        private void Controller_NewEntrySecond(HistoryEntry he, HistoryList hl)         // called after all UI's have had their chance
        {
            BaseUtils.AppTicks.TickCountLapDelta("DFS", true);

            actioncontroller.ActionRunOnEntry(he, Actions.ActionEventEDList.NewEntry(he));

            var t1 = BaseUtils.AppTicks.TickCountLapDelta("DFS");

            if (t1.Item2 >= 80)
            {
                System.Diagnostics.Trace.WriteLine("NE Second Actions slow " + t1.Item1);
            }

            // all notes committed
            SystemNoteClass.CommitDirtyNotes((snc) => { if (EDCommander.Current.SyncToEdsm && snc.FSDEntry)
                                                        {
                                                            EDSMClass.SendComments(snc.SystemName, snc.Note, 0, he.Commander);
                                                        }
                                             });

            var lastent = history.GetLast;

            if (!object.ReferenceEquals(he, lastent))
            {
                LogLineHighlight(string.Format("Current history entry is not last in history - possible re-entrancy.\nAlert the EDDiscovery developers using either discord or Github (see help) and attach log file {0}", BaseUtils.TraceLog.LogFileName));
                Trace.WriteLine($"Current history entry is not last in history");
                Trace.WriteLine($"Current entry: {he.journalEntry?.GetJsonString()}");
                Trace.WriteLine($"Last entry: {lastent.journalEntry?.GetJsonString()}");
                Trace.WriteLine($"Stack Trace:");
                Trace.WriteLine(new StackTrace(true).ToString());
            }

            if (he.IsFSDCarrierJump)
            {
                int count = history.GetVisitsCount(he.System.Name);
                LogLine(string.Format("Arrived at system {0} Visit No. {1}".T(EDTx.EDDiscoveryForm_Arrived), he.System.Name, count));
                System.Diagnostics.Trace.WriteLine("Arrived at system: " + he.System.Name + " " + count + ":th visit.");
            }

            if (EDCommander.Current.SyncToEdsm && EDSMJournalSync.OkayToSend(he))           // send this one, if allowed.
            {
                EDSMJournalSync.SendEDSMEvents(LogLine, new List <HistoryEntry>()
                {
                    he
                });                                                                             // send, if bad credentials, EDSM will moan alerting the user
            }

            if (EDCommander.Current.SyncToInara)
            {
                EliteDangerousCore.Inara.InaraSync.NewEvent(LogLine, he);
            }

            if (EDCommander.Current.SyncToIGAU)
            {
                EliteDangerousCore.IGAU.IGAUSync.NewEvent(LogLine, he);
            }

            if (EDDNClass.IsEDDNMessage(he.EntryType) && he.AgeOfEntry() < TimeSpan.FromDays(1.0) && EDCommander.Current.SyncToEddn == true)
            {
                EDDNSync.SendEDDNEvents(LogLine, he);
            }

            DLLManager.NewJournalEntry(EliteDangerousCore.DLL.EDDDLLCallerHE.CreateFromHistoryEntry(history, he), false);

            screenshotconverter.NewJournalEntry(he.journalEntry);       // tell the screenshotter.

            CheckActionProfile(he);

            // finally, CAPI, if docked, try and get commodity data, and if so, create a new EDD record
            // placed here because it causes a new set of newentries to be called

            if (he.EntryType == JournalTypeEnum.Docked && FrontierCAPI.Active)
            {
                System.Threading.Tasks.Task.Run(() =>           // don't hold up the main thread, do it in a task, as its a HTTP operation
                {
                    var dockevt = he.journalEntry as EliteDangerousCore.JournalEvents.JournalDocked;

                    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.Debug.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);

                            BeginInvoke((System.Windows.Forms.MethodInvoker) delegate
                            {
                                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.
                            });
                        }
                        else
                        {
                            System.Diagnostics.Trace.WriteLine($"CAPI disagree on market {dockevt.StationName} vs {mk.Name}");
                        }
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine($"CAPI market invalid {marketjson}");
                    }
                });
            }
        }