static void ReportEntry(ActionProgramRun ap, List<HistoryEntry> hl, int pos, string prefix) { if (hl != null && pos >= 0 && pos < hl.Count) // if within range.. (1 based) { try { Variables values = new Variables(); ActionVars.HistoryEventVars(values, hl[pos], prefix); ActionVars.ShipBasicInformation(values, hl[pos].ShipInformation, prefix); ActionVars.SystemVars(values, hl[pos].System, prefix); ap.Add(values); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception reporting entry variables in event " + ex.Message); } ap[prefix + "JID"] = hl[pos].Journalid.ToStringInvariant(); ap[prefix + "Count"] = hl.Count.ToString(System.Globalization.CultureInfo.InvariantCulture); // give a count of matches } else { ap[prefix + "JID"] = "0"; ap[prefix + "Count"] = "0"; } }
static void ReportHistoryEntry(ActionProgramRun ap, HistoryEntry he, string prefix) { try { ConditionVariables values = new ConditionVariables(); ActionVars.HistoryEventVars(values, he, prefix); ActionVars.ShipInformation(values, he.ShipInformation, prefix, true); ActionVars.SystemVars(values, he.System, prefix); ap.Add(values); } catch { } }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.functions.ExpandString(UserData, out res) != Conditions.ConditionFunctions.ExpandResult.Failed) { StringParser sp = new StringParser(res); string prefix = "ST_"; string cmdname = sp.NextQuotedWord(); if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase)) { prefix = sp.NextWord(); if (prefix == null) { ap.ReportError("Missing name after Prefix in Star"); return(true); } cmdname = sp.NextQuotedWord(); } if (cmdname != null) { ISystem sc = SystemClassDB.GetSystem(cmdname); ap[prefix + "Found"] = sc != null ? "1" : "0"; if (sc != null) { Conditions.ConditionVariables vars = new Conditions.ConditionVariables(); ActionVars.SystemVars(vars, sc, prefix); ap.Add(vars); ActionVars.SystemVarsFurtherInfo(ap, (ap.actioncontroller as ActionController).HistoryList, sc, prefix); } } else { ap.ReportError("Missing starname in Star"); } } else { ap.ReportError(res); } return(true); }
private void NewStarListComputed(ISystem sys, BaseUtils.SortedListDoubleDuplicate <ISystem> list) // In UI thread { System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop); int i = 1; foreach (var s in list) { string p = ret_prefix + (i++).ToStringInvariant() + "_"; ActionVars.SystemVars(apr.variables, s.Value, p); ActionVars.SystemVarsFurtherInfo(apr, (apr.ActionController as ActionController).HistoryList, s.Value, p); apr[p + "Dist"] = Math.Sqrt(s.Key).ToStringInvariant("0.##"); } apr[ret_prefix + "Count"] = list.Count.ToStringInvariant(); apr.ResumeAfterPause(); }
static void ReportEntry(ActionProgramRun ap, List <HistoryEntry> hl, int pos, string prefix) { if (hl != null && pos >= 0 && pos < hl.Count) // if within range.. (1 based) { try { ConditionVariables values = new ConditionVariables(); ActionVars.HistoryEventVars(values, hl[pos], prefix); ActionVars.ShipBasicInformation(values, hl[pos].ShipInformation, prefix); ActionVars.SystemVars(values, hl[pos].System, prefix); ap.Add(values); } catch { } ap[prefix + "Count"] = hl.Count.ToString(System.Globalization.CultureInfo.InvariantCulture); // give a count of matches } else { ap[prefix + "JID"] = "0"; ap[prefix + "Count"] = "0"; } }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.functions.ExpandString(UserData, out res) != ConditionFunctions.ExpandResult.Failed) { HistoryList hl = (ap.actioncontroller as ActionController).HistoryList; StringParser sp = new StringParser(res); string prefix = "EC_"; string cmdname = sp.NextWord(" ", true); if (cmdname != null && cmdname.Equals("prefix")) { prefix = sp.NextWord(); if (prefix == null) { ap.ReportError("Missing name after Prefix in Event"); return(true); } cmdname = sp.NextWord(" ", true); } int jidindex = -1; if (cmdname != null && (cmdname.Equals("from") || cmdname.Equals("thpos"))) { long?jid; if (cmdname.Equals("thpos")) { HistoryEntry he = (ap.actioncontroller as ActionController).DiscoveryForm.TravelControl.GetTravelHistoryCurrent; if (he == null) { ReportEntry(ap, null, 0, prefix); return(true); } jid = he.Journalid; } else { jid = sp.NextWord().InvariantParseLongNull(); if (!jid.HasValue) { ap.ReportError("Non integer JID after FROM in Event"); return(true); } } jidindex = hl.GetIndex(jid.Value); if (jidindex == -1) { ReportEntry(ap, null, 0, prefix); return(true); } cmdname = sp.NextWord(" ", true); } if (cmdname == null) { if (jidindex != -1) { ReportEntry(ap, hl.EntryOrder, jidindex, prefix); } else { ap.ReportError("No commands in Event"); } return(true); } bool fwd = cmdname.Equals("forward") || cmdname.Equals("first"); bool back = cmdname.Equals("backward") || cmdname.Equals("last"); if (fwd || back) { List <string> eventnames = sp.NextOptionallyBracketedList(); bool whereasfirst = eventnames.Count == 1 && eventnames[0].Equals("WHERE", StringComparison.InvariantCultureIgnoreCase); ConditionLists cond = new ConditionLists(); string nextword; if (whereasfirst || ((nextword = sp.NextWord()) != null && nextword.Equals("WHERE", StringComparison.InvariantCultureIgnoreCase))) { if (whereasfirst) // clear out event names if it was WHERE cond.. { eventnames.Clear(); } string resc = cond.Read(sp.LineLeft); // rest of it is the condition.. if (resc != null) { ap.ReportError(resc + " in Where of Event"); return(true); } } List <HistoryEntry> hltest; if (jidindex == -1) // if no JID given.. { hltest = hl.EntryOrder; // the whole list } else if (fwd) { hltest = hl.EntryOrder.GetRange(jidindex + 1, hl.Count - (jidindex + 1)); // cut down list, excluding this entry } else { hltest = hl.EntryOrder.GetRange(0, jidindex); } if (eventnames.Count > 0) { hltest = (from h in hltest where eventnames.Contains(h.journalEntry.EventTypeStr, StringComparer.OrdinalIgnoreCase) select h).ToList(); } if (cond.Count > 0) // if we have filters, apply, filter out, true only stays { hltest = UserControls.FilterHelpers.CheckFilterTrue(hltest, cond, new ConditionVariables()); // apply filter.. } if (fwd) { ReportEntry(ap, hltest, 0, prefix); } else { ReportEntry(ap, hltest, hltest.Count - 1, prefix); } return(true); } else { if (jidindex == -1) { ap.ReportError("Valid JID must be given for command " + cmdname + " in Event"); } else if (cmdname.Equals("action")) { int count = (ap.actioncontroller as ActionController).ActionRunOnEntry(hl.EntryOrder[jidindex], "ActionProgram", now: true); ap[prefix + "Count"] = count.ToString(System.Globalization.CultureInfo.InvariantCulture); } else if (cmdname.Equals("edsm")) { HistoryEntry he = hl.EntryOrder[jidindex]; (ap.actioncontroller as ActionController).HistoryList.FillEDSM(he, reload: true); long?id_edsm = he.System.id_edsm; if (id_edsm <= 0) { id_edsm = null; } EliteDangerousCore.EDSM.EDSMClass edsm = new EliteDangerousCore.EDSM.EDSMClass(); string url = edsm.GetUrlToEDSMSystem(he.System.name, id_edsm); ap[prefix + "URL"] = url; if (url.Length > 0) // may pass back empty string if not known, this solves another exception { System.Diagnostics.Process.Start(url); } } else if (cmdname.Equals("ross")) { HistoryEntry he = hl.EntryOrder[jidindex]; (ap.actioncontroller as ActionController).HistoryList.FillEDSM(he, reload: true); string url = ""; if (he.System.id_eddb > 0) { url = "http://ross.eddb.io/system/update/" + he.System.id_eddb.ToString(); System.Diagnostics.Process.Start(url); } ap[prefix + "URL"] = url; } else if (cmdname.Equals("info")) { HistoryEntry he = hl.EntryOrder[jidindex]; ActionVars.HistoryEventFurtherInfo(ap, hl, he, prefix); ActionVars.SystemVarsFurtherInfo(ap, hl, he.System, prefix); ActionVars.ShipModuleInformation(ap, he.ShipInformation, prefix); } else if (cmdname.Equals("missions")) { HistoryEntry he = hl.EntryOrder[jidindex]; ActionVars.MissionInformation(ap, he.MissionList, prefix); } else { ap.ReportError("Unknown command " + cmdname + " in Event"); } } } else { ap.ReportError(res); } return(true); }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.functions.ExpandString(UserData, out res) != Functions.ExpandResult.Failed) { HistoryList hl = (ap.actioncontroller as ActionController).HistoryList; StringParser sp = new StringParser(res); string prefix = "EC_"; string cmdname = sp.NextWordLCInvariant(" "); if (cmdname != null && cmdname.Equals("prefix") ) { prefix = sp.NextWord(); if ( prefix == null ) { ap.ReportError("Missing name after Prefix in Event"); return true; } cmdname = sp.NextWordLCInvariant(" "); } int jidindex = -1; if (cmdname!=null && (cmdname.Equals("from") || cmdname.Equals("thpos"))) { long? jid; if (cmdname.Equals("thpos")) { HistoryEntry he = (ap.actioncontroller as ActionController).DiscoveryForm.PrimaryCursor.GetCurrentHistoryEntry; if ( he == null ) { ReportEntry(ap, null, 0, prefix); return true; } jid = he.Journalid; } else { jid = sp.NextWord().InvariantParseLongNull(); if (!jid.HasValue) { ap.ReportError("Non integer JID after FROM in Event"); return true; } } jidindex = hl.GetIndex(jid.Value); if ( jidindex == -1 ) { ReportEntry(ap, null, 0, prefix); return true; } cmdname = sp.NextWordLCInvariant(" "); } if (cmdname == null) { if (jidindex != -1) { ReportEntry(ap, hl.EntryOrder, jidindex, prefix); } else ap.ReportError("No commands in Event"); return true; } bool fwd = cmdname.Equals("forward") || cmdname.Equals("first"); bool back = cmdname.Equals("backward") || cmdname.Equals("last"); if (fwd || back) { List<string> eventnames = sp.NextOptionallyBracketedList(); // single entry, list of events bool not = eventnames.Count == 1 && eventnames[0].Equals("NOT", StringComparison.InvariantCultureIgnoreCase); // if it goes NOT if ( not ) eventnames = sp.NextOptionallyBracketedList(); // then get another list // is it "WHERE" bool whereasfirst = eventnames.Count == 1 && eventnames[0].Equals("WHERE", StringComparison.InvariantCultureIgnoreCase); ConditionLists cond = new ConditionLists(); string nextword; // if WHERE cond, or eventname WHERE cond if ( whereasfirst || ((nextword = sp.NextWord()) != null && nextword.Equals("WHERE", StringComparison.InvariantCultureIgnoreCase) )) { if ( whereasfirst ) // clear out event names if it was WHERE cond.. eventnames.Clear(); string resc = cond.Read(sp.LineLeft); // rest of it is the condition.. if (resc != null) { ap.ReportError(resc + " in Where of Event"); return true; } } List<HistoryEntry> hltest; if (jidindex == -1) // if no JID given.. hltest = hl.EntryOrder; // the whole list else if (fwd) hltest = hl.EntryOrder.GetRange(jidindex + 1, hl.Count - (jidindex + 1)); // cut down list, excluding this entry else hltest = hl.EntryOrder.GetRange(0, jidindex ); if (eventnames.Count > 0) // screen out event names hltest = (from h in hltest where eventnames.Contains(h.journalEntry.EventTypeStr, StringComparer.OrdinalIgnoreCase) == !not select h).ToList(); if (cond.Count > 0) // if we have filters, apply, filter out, true only stays hltest = UserControls.FilterHelpers.CheckFilterTrue(hltest, cond, new Variables()); // apply filter.. if (fwd) ReportEntry(ap, hltest, 0, prefix); else ReportEntry(ap, hltest, hltest.Count - 1, prefix); return true; } else { if (jidindex == -1) ap.ReportError("Valid JID must be given for command " + cmdname + " in Event"); else { HistoryEntry he = hl.EntryOrder[jidindex]; ap[prefix + "JID"] = jidindex.ToStringInvariant(); if (cmdname.Equals("action")) { int count = (ap.actioncontroller as ActionController).ActionRunOnEntry(he, Actions.ActionEventEDList.EventCmd(he), now: true); ap[prefix + "Count"] = count.ToString(System.Globalization.CultureInfo.InvariantCulture); } else if (cmdname.Equals("edsm")) { (ap.actioncontroller as ActionController).HistoryList.FillEDSM(he); long? id_edsm = he.System.EDSMID; if (id_edsm <= 0) { id_edsm = null; } EliteDangerousCore.EDSM.EDSMClass edsm = new EliteDangerousCore.EDSM.EDSMClass(); string url = edsm.GetUrlToEDSMSystem(he.System.Name, id_edsm); ap[prefix + "URL"] = url; if (url.Length > 0) // may pass back empty string if not known, this solves another exception System.Diagnostics.Process.Start(url); } else if (cmdname.Equals("ross")) { (ap.actioncontroller as ActionController).HistoryList.FillEDSM(he); string url = ""; if (he.System.EDDBID > 0) { url = Properties.Resources.URLRossSystem + he.System.EDDBID.ToString(); System.Diagnostics.Process.Start(url); } ap[prefix + "URL"] = url; } else if (cmdname.Equals("eddb")) { (ap.actioncontroller as ActionController).HistoryList.FillEDSM(he); string url = ""; if (he.System.EDDBID > 0) { url = Properties.Resources.URLEDDBSystem + he.System.EDDBID.ToString(); System.Diagnostics.Process.Start(url); } ap[prefix + "URL"] = url; } else if (cmdname.Equals("info")) { ActionVars.HistoryEventFurtherInfo(ap, hl, he, prefix); ActionVars.SystemVarsFurtherInfo(ap, hl, he.System, prefix); ActionVars.ShipModuleInformation(ap, he.ShipInformation, prefix); } else if (cmdname.Equals("missions")) { ActionVars.MissionInformation(ap, he.MissionList, prefix); } else if (cmdname.Equals("setstartmarker")) { he.journalEntry.SetStartFlag(); } else if (cmdname.Equals("setstopmarker")) { he.journalEntry.SetEndFlag(); } else if (cmdname.Equals("clearstartstopmarker")) { he.journalEntry.ClearStartEndFlag(); } else if (cmdname.Equals("note")) { string note = sp.NextQuotedWord(); if (note != null && sp.IsEOL) { he.SetJournalSystemNoteText(note, true, EDCommander.Current.SyncToEdsm); (ap.actioncontroller as ActionController).DiscoveryForm.NoteChanged(this, he, true); } else ap.ReportError("Missing note text or unquoted text in Event NOTE"); } else ap.ReportError("Unknown command " + cmdname + " in Event"); } } } else ap.ReportError(res); return true; }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.Functions.ExpandString(UserData, out res) != BaseUtils.Functions.ExpandResult.Failed) { StringParser sp = new StringParser(res); string prefix = "ST_"; string cmdname = sp.NextQuotedWord(); if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase)) { prefix = sp.NextWord(); if (prefix == null) { ap.ReportError("Missing name after Prefix in Star"); return(true); } cmdname = sp.NextQuotedWord(); } if (cmdname != null) { ISystem sc = SystemCache.FindSystem(cmdname); ap[prefix + "Found"] = sc != null ? "1" : "0"; if (sc != null) { BaseUtils.Variables vars = new BaseUtils.Variables(); ActionVars.SystemVars(vars, sc, prefix); ap.Add(vars); ActionVars.SystemVarsFurtherInfo(ap, (ap.ActionController as ActionController).HistoryList, sc, prefix); string options = sp.NextWord(); if (options != null) { if (options.Equals("NEAREST", StringComparison.InvariantCultureIgnoreCase)) { double mindist = sp.NextDouble(0.01); double maxdist = sp.NextDouble(20.0); int number = sp.NextInt(50); bool cube = (sp.NextWord() ?? "Spherical").Equals("Cube", StringComparison.InvariantCultureIgnoreCase); // spherical default for all but cube StarDistanceComputer computer = new StarDistanceComputer(); apr = ap; ret_prefix = prefix; computer.CalculateClosestSystems(sc, (sys, list) => (apr.ActionController as ActionController).DiscoveryForm.BeginInvoke(new Action(() => NewStarListComputed(sys, list))), (mindist > 0) ? (number - 1) : number, // adds an implicit 1 on for centre star mindist, maxdist, !cube); return(false); // go to sleep until value computed } } } } else { ap.ReportError("Missing starname in Star"); } } else { ap.ReportError(res); } return(true); }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.functions.ExpandString(UserData, out res) != BaseUtils.Functions.ExpandResult.Failed) { StringParser sp = new StringParser(res); string prefix = "SH_"; string cmdname = sp.NextQuotedWord(); if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase)) { prefix = sp.NextWord(); if (prefix == null) { ap.ReportError("Missing name after Prefix in Ship"); return(true); } cmdname = sp.NextQuotedWord(); } if (cmdname != null) { EliteDangerousCore.ShipInformationList lst = (ap.actioncontroller as ActionController).HistoryList.ShipInformationList; Variables values = new Variables(); if (cmdname.Length > 0) { EliteDangerousCore.ShipInformation si = lst.GetShipByFullInfoMatch(cmdname); if (si != null) { ActionVars.ShipBasicInformation(values, si, prefix); ActionVars.ShipModuleInformation(ap, si, prefix); } values[prefix + "Found"] = (si != null) ? "1" : "0"; } values[prefix + "Ships"] = lst.Ships.Count.ToString(System.Globalization.CultureInfo.InvariantCulture); int ind = 0; foreach (EliteDangerousCore.ShipInformation si in lst.Ships.Values) { string p = prefix + "Ships[" + ind.ToString() + "]_"; ActionVars.ShipBasicInformation(values, si, p); ind++; } ap.Add(values); } else { ap.ReportError("Missing ship name in Ship"); } } else { ap.ReportError(res); } return(true); }