Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        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;
        }