public int ActionRunOnEntry(HistoryEntry he, string triggertype) { return(actioncontroller.ActionRunOnEntry(he, triggertype)); }
public int ActionRun(string name, string triggertype, HistoryEntry he = null, ConditionVariables additionalvars = null, string flagstart = null, bool now = false) { return(actioncontroller.ActionRun(name, triggertype, he, additionalvars, flagstart, now)); }
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++) { 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(); } }