Exemple #1
0
        void DumpGMO(ActionProgramRun ap, string nprefix, EliteDangerousCore.EDSM.GalacticMapObject g)
        {
            ap[nprefix + "Name"]        = g.name;
            ap[nprefix + "Type"]        = g.type;
            ap[nprefix + "Search"]      = g.galMapSearch;
            ap[nprefix + "MapURL"]      = g.galMapUrl;
            ap[nprefix + "Description"] = g.description;
            ap[nprefix + "Group"]       = g.galMapType.Group.ToString();

            if (g.points != null)
            {
                for (int i = 0; i < g.points.Count; i++)
                {
                    string p = nprefix + "Vertex_" + (i + 1).ToStringInvariant() + "_";
                    ap[p + "X"] = g.points[i].X.ToStringInvariant("0.##");
                    ap[p + "Y"] = g.points[i].Y.ToStringInvariant("0.##");
                    ap[p + "Z"] = g.points[i].Z.ToStringInvariant("0.##");
                }
            }
        }
Exemple #2
0
        // now = true, run it immediately, else run at end of queue.  Optionally pass in handles and dialogs in case its a sub prog

        public void Run(bool now, ActionFile fileset, ActionProgram r, ConditionVariables inputparas,
                        ConditionFileHandles fh = null, Dictionary <string, Forms.ConfigurableForm> d = null, bool closeatend = true)
        {
            if (now)
            {
                if (progcurrent != null)                    // if running, push the current one back onto the queue to be picked up
                {
                    progqueue.Insert(0, progcurrent);
                }

                progcurrent = new ActionProgramRun(fileset, r, inputparas, this, actioncontroller);   // now we run this.. no need to push to stack

                progcurrent.PrepareToRun(new ConditionVariables(progcurrent.inputvariables, actioncontroller.Globals),
                                         fh == null ? new ConditionFileHandles() : fh, d == null ? new Dictionary <string, Forms.ConfigurableForm>() : d, closeatend);              // if no filehandles, make them and close at end
            }
            else
            {
                progqueue.Add(new ActionProgramRun(fileset, r, inputparas, this, actioncontroller));
            }
        }
Exemple #3
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            if (ap.IsExecutingType(Action.ActionType.If))
            {
                if (ap.IsExecuteOff)       // if not executing, check condition
                {
                    if (condition == null)
                    {
                        condition = new ConditionLists();
                        if (condition.FromString(UserData) != null)
                        {
                            ap.ReportError("IF condition is not correctly formed");
                            return(true);
                        }
                    }

                    string errlist;
                    bool?  condres = condition.CheckAll(ap.functions.vars, out errlist, null, ap.functions);    // may return null.. and will return errlist

                    if (errlist == null)
                    {
                        bool res = condres.HasValue && condres.Value;
                        ap.ChangeState(res);            // either to ON.. or to OFF, continuing the off
                    }
                    else
                    {
                        ap.ReportError(errlist);
                    }
                }
                else
                {
                    ap.ChangeState(ActionProgramRun.ExecState.OffForGood);      // make sure off for good
                }
            }
            else
            {
                ap.ReportError("ElseIf without IF");
            }

            return(true);
        }
Exemple #4
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            if (av == null)
            {
                FromString(userdata, out av, out operations);
            }

            foreach (string key in av.NameEnumuerable)
            {
                string res;

                if (operations[key].Contains("$"))
                {
                    res = av[key];
                }
                else if (ap.functions.ExpandString(av[key], out res) == ConditionFunctions.ExpandResult.Failed)        //Expand out.. and if no errors
                {
                    ap.ReportError(res);
                    break;
                }

                if (operations[key].Contains("+") && ap.VarExist(key))
                {
                    ap[key] += res;
                    ap.actioncontroller.SetPeristentGlobal(key, ap[key]);
                }
                else
                {
                    ap[key] = res;
                    ap.actioncontroller.SetPeristentGlobal(key, res);
                }
            }

            if (av.Count == 0)
            {
                ap.ReportError("PersistentGlobal no variable name given");
            }

            return(true);
        }
Exemple #5
0
        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";
            }
        }
Exemple #6
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            List <string> ctrl = FromString(UserData);

            if (ctrl != null)
            {
                List <string> exp;

                if (ap.functions.ExpandStrings(ctrl, out exp) != ConditionFunctions.ExpandResult.Failed)
                {
                    string[] prompts   = exp[1].Split(';');
                    string[] def       = (exp.Count >= 3) ? exp[2].Split(';') : null;
                    bool     multiline = (exp.Count >= 4) ? (exp[3].IndexOf("Multiline", StringComparison.InvariantCultureIgnoreCase) >= 0) : false;
                    string[] tooltips  = (exp.Count >= 5) ? exp[4].Split(';') : null;

                    List <string> r = Forms.PromptMultiLine.ShowDialog(ap.actioncontroller.DiscoveryForm, exp[0],
                                                                       prompts, def, multiline, tooltips);

                    ap["InputBoxOK"] = (r != null) ? "1" : "0";
                    if (r != null)
                    {
                        for (int i = 0; i < r.Count; i++)
                        {
                            ap["InputBox" + (i + 1).ToString()] = r[i];
                        }
                    }
                }
                else
                {
                    ap.ReportError(exp[0]);
                }
            }
            else
            {
                ap.ReportError("MenuInput command line not in correct format");
            }

            return(true);
        }
Exemple #7
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            if (av == null)
            {
                FromString(userdata, out av, out operations);
            }

            foreach (string key in av.NameEnumuerable)
            {
                string res;

                if (operations[key].Contains("$"))
                {
                    res = av[key];
                }
                else if (ap.functions.ExpandString(av[key], out res) == ConditionFunctions.ExpandResult.Failed)
                {
                    ap.ReportError(res);
                    break;
                }

                string value;
                if (!res.Eval(out value))
                {
                    ap.ReportError("Let " + value);
                    break;
                }

                ap[key] = value;
            }

            if (av.Count == 0)
            {
                ap.ReportError("Let no variable name given");
            }

            return(true);
        }
Exemple #8
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string res;

            if (ap.functions.ExpandString(UserData, out res) != ConditionFunctions.ExpandResult.Failed)
            {
                StringParser p = new StringParser(res);

                string v;
                while ((v = p.NextWord(", ")) != null)
                {
                    ap.actioncontroller.DeleteVariable(v);
                    ap.DeleteVar(v);
                    p.IsCharMoveOn(',');
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Exemple #9
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string             keys;
            ConditionVariables statementvars;

            if (FromString(userdata, out keys, out statementvars))
            {
                string             errlist = null;
                ConditionVariables vars    = statementvars.ExpandAll(ap.functions, statementvars, out errlist);

                if (errlist == null)
                {
                    int    defdelay = vars.Exists(DelayID) ? vars[DelayID].InvariantParseInt(DefaultDelay) : DefaultDelay;
                    string process  = vars.Exists(ProcessID) ? vars[ProcessID] : "";

                    ActionController ac = ap.actioncontroller as ActionController;
                    EliteDangerousCore.BindingsFile bf = ac.DiscoveryForm.FrontierBindings;

                    string res = BaseUtils.EnhancedSendKeys.Send(keys, defdelay, DefaultShiftDelay, DefaultUpDelay, process);

                    if (res.HasChars())
                    {
                        ap.ReportError("Key Syntax error : " + res);
                    }
                }
                else
                {
                    ap.ReportError(errlist);
                }
            }
            else
            {
                ap.ReportError("Key command line not in correct format");
            }

            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  = (commodities) ? "C_" : "M_";
                string cmdname = sp.NextWord();

                if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase))
                {
                    prefix = sp.NextWord();

                    if (prefix == null)
                    {
                        ap.ReportError("Missing name after Prefix in Materials/Commodity");
                        return(true);
                    }

                    cmdname = sp.NextWord();
                }

                if (cmdname != null)
                {
                    long jid;
                    if (!cmdname.InvariantParse(out jid))
                    {
                        ap.ReportError("Non integer JID in Materials/Commodity");
                        return(true);
                    }

                    int index = (ap.ActionController as ActionController).HistoryList.EntryOrder().FindIndex(x => x.Journalid == jid);

                    if (index == -1)
                    {
                        ap.ReportError("JID does not exist in Materials/Commodity");
                        return(true);
                    }

                    var hl = (ap.ActionController as ActionController).HistoryList;
                    var he = hl[index];

                    List <MaterialCommodityMicroResource> list = hl.MaterialCommoditiesMicroResources.GetSorted(he.MaterialCommodity, commodities);

                    ap[prefix + "Count"]   = list.Count.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    ap[prefix + "IndexOf"] = (ap.ActionController as ActionController).HistoryList.EntryOrder()[index].EntryNumber.ToString(System.Globalization.CultureInfo.InvariantCulture);

                    for (int i = 0; i < list.Count; i++)
                    {
                        string postfix = (i + 1).ToString(System.Globalization.CultureInfo.InvariantCulture);
                        ap[prefix + "Name" + postfix]      = list[i].Details.Name;
                        ap[prefix + "Category" + postfix]  = list[i].Details.Category.ToString();
                        ap[prefix + "fdname" + postfix]    = list[i].Details.FDName;
                        ap[prefix + "type" + postfix]      = list[i].Details.Type.ToString().SplitCapsWord();
                        ap[prefix + "shortname" + postfix] = list[i].Details.Shortname;
                    }
                }
                else
                {
                    ap.ReportError("Missing JID in Materials");
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Exemple #11
0
 public override bool ExecuteAction(ActionProgramRun ap)
 {
     return(ExecuteAction(ap, null)); //base, TBD pass in tx funct
 }
Exemple #12
0
        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  = "G_";
                string cmdname = sp.NextWord();

                if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase))
                {
                    prefix = sp.NextWord();

                    if (prefix == null)
                    {
                        ap.ReportError("Missing name after Prefix in GMO");
                        return(true);
                    }

                    cmdname = sp.NextWord();
                }

                if (cmdname != null)
                {
                    EDDiscoveryForm discoveryform = (ap.ActionController as ActionController).DiscoveryForm;

                    if (cmdname.Equals("LIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string wildcard = sp.NextQuotedWord() ?? "*";

                        int count = 1;
                        foreach (var g in discoveryform.galacticMapping.galacticMapObjects)
                        {
                            if (g.name.WildCardMatch(wildcard))
                            {
                                string nprefix = prefix + (count++).ToStringInvariant() + "_";
                                DumpGMO(ap, nprefix, g);
                            }
                        }

                        ap[prefix + "MatchCount"] = (count - 1).ToStringInvariant();
                        ap[prefix + "TotalCount"] = discoveryform.galacticMapping.galacticMapObjects.Count.ToStringInvariant();
                    }
                    else
                    {
                        string name = sp.NextQuotedWord();

                        if (name != null)
                        {
                            if (cmdname.Equals("EXISTS", StringComparison.InvariantCultureIgnoreCase))
                            {
                                EliteDangerousCore.EDSM.GalacticMapObject gmo = discoveryform.galacticMapping.Find(name, false);
                                ap[prefix + "Exists"] = (gmo != null).ToStringIntValue();
                                if (gmo != null)
                                {
                                    DumpGMO(ap, prefix, gmo);
                                }
                            }
                            else
                            {
                                ap.ReportError("Unknown GMO command");
                            }
                        }
                        else
                        {
                            ap.ReportError("Missing name in command");
                        }
                    }
                }
                else
                {
                    ap.ReportError("Missing GMO command");
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Exemple #13
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string             say;
            ConditionVariables statementvars;

            if (FromString(userdata, out say, out statementvars))
            {
                string             errlist = null;
                ConditionVariables vars    = statementvars.ExpandAll(ap.functions, statementvars, out errlist);

                if (errlist == null)
                {
                    bool wait = vars.GetInt(waitname, 0) != 0;
                    Audio.AudioQueue.Priority priority = Audio.AudioQueue.GetPriority(vars.GetString(priorityname, "Normal"));
                    string start  = vars.GetString(startname);
                    string finish = vars.GetString(finishname);
                    string voice  = vars.Exists(voicename) ? vars[voicename] : (ap.VarExist(globalvarspeechvoice) ? ap[globalvarspeechvoice] : "Default");

                    int vol = vars.GetInt(volumename, -999);
                    if (vol == -999)
                    {
                        vol = ap.variables.GetInt(globalvarspeechvolume, 60);
                    }

                    int rate = vars.GetInt(ratename, -999);
                    if (rate == -999)
                    {
                        rate = ap.variables.GetInt(globalvarspeechrate, 0);
                    }

                    string culture = vars.Exists(culturename) ? vars[culturename] : (ap.VarExist(globalvarspeechculture) ? ap[globalvarspeechculture] : "Default");

                    bool literal   = vars.GetInt(literalname, 0) != 0;
                    bool dontspeak = vars.GetInt(dontspeakname, 0) != 0;

                    Audio.SoundEffectSettings ses = new Audio.SoundEffectSettings(vars);       // use the rest of the vars to place effects

                    if (!ses.Any && !ses.OverrideNone && ap.VarExist(globalvarspeecheffects))  // if can't see any, and override none if off, and we have a global, use that
                    {
                        vars = new ConditionVariables(ap[globalvarspeecheffects], ConditionVariables.FromMode.MultiEntryComma);
                    }

                    string expsay;
                    if (ap.functions.ExpandString(say, out expsay) != EDDiscovery.ConditionFunctions.ExpandResult.Failed)
                    {
                        if (!literal)
                        {
                            expsay = expsay.PickOneOfGroups(rnd);       // expand grouping if not literal
                        }
                        ap["SaySaid"] = expsay;

                        if ((ap.VarExist("SpeechDebug") && ap["SpeechDebug"].Contains("Print")))
                        {
                            ap.actioncontroller.LogLine("Say: " + expsay);
                            expsay = "";
                        }

                        if (dontspeak)
                        {
                            expsay = "";
                        }

                        System.IO.MemoryStream ms = ap.actioncontroller.DiscoveryForm.SpeechSynthesizer.Speak(expsay, culture, voice, rate);

                        if (ms != null)
                        {
                            Audio.AudioQueue.AudioSample audio = ap.actioncontroller.DiscoveryForm.AudioQueueSpeech.Generate(ms, vars, true);

                            if (audio != null)
                            {
                                if (start != null && start.Length > 0)
                                {
                                    audio.sampleStartTag = new AudioEvent {
                                        apr = ap, eventname = start, triggername = "onSayStarted"
                                    };
                                    audio.sampleStartEvent += Audio_sampleEvent;
                                }
                                if (wait || (finish != null && finish.Length > 0))       // if waiting, or finish call
                                {
                                    audio.sampleOverTag = new AudioEvent()
                                    {
                                        apr = ap, wait = wait, eventname = finish, triggername = "onSayFinished"
                                    };
                                    audio.sampleOverEvent += Audio_sampleEvent;
                                }

                                ap.actioncontroller.DiscoveryForm.AudioQueueSpeech.Submit(audio, vol, priority);

                                return(!wait);       //False if wait, meaning terminate and wait for it to complete, true otherwise, continue
                            }
                            else
                            {
                                ap.ReportError("Say could not create audio, check Effects settings");
                            }
                        }
                    }
                    else
                    {
                        ap.ReportError(expsay);
                    }
                }
                else
                {
                    ap.ReportError(errlist);
                }
            }
            else
            {
                ap.ReportError("Say command line not in correct format");
            }


            return(true);
        }
Exemple #14
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string res;

            if (ap.Functions.ExpandString(UserData, out res) != BaseUtils.Functions.ExpandResult.Failed)
            {
                BaseUtils.StringParser sp = new BaseUtils.StringParser(res);

                string nextcmd = sp.NextWordLCInvariant(" ");

                if (nextcmd == null)
                {
                    ap.ReportError("Missing command in ProgramWindow");
                }
                else if (nextcmd.Equals("tab") || nextcmd.Equals("opentab") || nextcmd.Equals("closetab"))
                {
                    string tabname = sp.NextQuotedWord(lowercase: System.Globalization.CultureInfo.InvariantCulture, replaceescape: true);

                    if (!(ap.ActionController as ActionController).DiscoveryForm.SelectTabPage(tabname, nextcmd.Equals("opentab"), nextcmd.Equals("closetab")))
                    {
                        ap.ReportError("Tab page name " + tabname + " not found");
                    }
                }
                else if (nextcmd.Equals("topmost"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.TopMost = true;
                }
                else if (nextcmd.Equals("normalz"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.TopMost = false;
                }
                else if (nextcmd.Equals("showintaskbar"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.ShowInTaskbar = true;
                }
                else if (nextcmd.Equals("notshowintaskbar"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.ShowInTaskbar = false;
                }
                else if (nextcmd.Equals("minimize"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.WindowState = FormWindowState.Minimized;
                }
                else if (nextcmd.Equals("normal"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.WindowState = FormWindowState.Normal;
                }
                else if (nextcmd.Equals("maximize"))
                {
                    (ap.ActionController as ActionController).DiscoveryForm.WindowState = FormWindowState.Maximized;
                }
                else if (nextcmd.Equals("location"))
                {
                    int?x = sp.NextWordComma().InvariantParseIntNull();
                    int?y = sp.NextWordComma().InvariantParseIntNull();
                    int?w = sp.NextWordComma().InvariantParseIntNull();
                    int?h = sp.NextWord().InvariantParseIntNull();

                    if (x.HasValue && y.HasValue && w.HasValue && h.HasValue)
                    {
                        (ap.ActionController as ActionController).DiscoveryForm.Location = new Point(x.Value, y.Value);
                        (ap.ActionController as ActionController).DiscoveryForm.Size     = new Size(w.Value, h.Value);
                    }
                    else
                    {
                        ap.ReportError("Location needs x,y,w,h in Popout");
                    }
                }
                else if (nextcmd.Equals("position"))
                {
                    int?x = sp.NextWordComma().InvariantParseIntNull();
                    int?y = sp.NextWord().InvariantParseIntNull();

                    if (x.HasValue && y.HasValue)
                    {
                        (ap.ActionController as ActionController).DiscoveryForm.Location = new Point(x.Value, y.Value);
                    }
                    else
                    {
                        ap.ReportError("Position needs x,y in Popout");
                    }
                }
                else if (nextcmd.Equals("size"))
                {
                    int?w = sp.NextWordComma().InvariantParseIntNull();
                    int?h = sp.NextWord().InvariantParseIntNull();

                    if (w.HasValue && h.HasValue)
                    {
                        (ap.ActionController as ActionController).DiscoveryForm.Size = new Size(w.Value, h.Value);
                    }
                    else
                    {
                        ap.ReportError("Size needs x,y,w,h in Popout");
                    }
                }
                else
                {
                    ap.ReportError("Unknown command " + nextcmd + " in Popout");
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Exemple #15
0
        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) != Conditions.ConditionFunctions.ExpandResult.Failed)
            {
                StringParser sp = new StringParser(res);

                string cmdname = sp.NextWord();

                if (cmdname == null)
                {
                    ap.ReportError("Missing panel name in Historytab");
                }
                else
                {
                    ExtendedControls.TabStrip ts = (ap.actioncontroller as ActionController).DiscoveryForm.TravelControl.GetTabStrip(cmdname);     // case insensitive

                    if (ts != null)
                    {
                        string nextcmd = sp.NextWord(" ", true);

                        if (nextcmd == null)
                        {
                            ap.ReportError("Missing command after panel name in Historytab");
                        }
                        else if (nextcmd.Equals("toggle"))
                        {
                            ts.Toggle();
                        }
                        else
                        {
                            Forms.PopOutControl         poc = (ap.actioncontroller as ActionController).DiscoveryForm.PopOuts;
                            Forms.PopOutControl.PopOuts?poi = Forms.PopOutControl.GetPopOutTypeByName(nextcmd);

                            if (poi.HasValue)
                            {
                                if (!ts.ChangeTo((int)poi.Value))
                                {
                                    ap.ReportError("Panel " + nextcmd + " cannot be used in Historytab");
                                }
                            }
                            else
                            {
                                ap.ReportError("Cannot find generic panel type name " + nextcmd + " in Historytab");
                            }
                        }
                    }
                    else
                    {
                        ap.ReportError("Unknown panel name " + cmdname + " in Historytab");
                    }
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Exemple #17
0
        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);
        }
Exemple #18
0
        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  = "S_";
                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 Scan");
                        return(true);
                    }

                    cmdname = sp.NextQuotedWord();
                }

                bool edsm = false;
                if (cmdname != null && cmdname.Equals("EDSM", StringComparison.InvariantCultureIgnoreCase))
                {
                    edsm    = true;
                    cmdname = sp.NextQuotedWord();
                }

                if (cmdname != null)
                {
                    StarScan scan = (ap.actioncontroller as ActionController).HistoryList.starscan;
                    ISystem  sc   = SystemClassDB.GetSystem(cmdname);

                    if (sc == null)
                    {
                        sc        = new SystemClass(cmdname);
                        sc.EDSMID = 0;
                    }

                    StarScan.SystemNode sn = scan.FindSystem(sc, edsm);

                    System.Globalization.CultureInfo ct = System.Globalization.CultureInfo.InvariantCulture;

                    if (sn != null)
                    {
                        int starno = 1;
                        ap[prefix + "Stars"] = sn.starnodes.Count.ToString(ct);

                        foreach (KeyValuePair <string, StarScan.ScanNode> scannode in sn.starnodes)
                        {
                            DumpInfo(ap, scannode, prefix + "Star_" + starno.ToString(ct), "_Planets");

                            int pcount = 1;

                            if (scannode.Value.children != null)
                            {
                                foreach (KeyValuePair <string, StarScan.ScanNode> planetnodes in scannode.Value.children)
                                {
                                    DumpInfo(ap, planetnodes, prefix + "Planet_" + starno.ToString(ct) + "_" + pcount.ToString(ct), "_Moons");

                                    if (planetnodes.Value.children != null)
                                    {
                                        int mcount = 1;
                                        foreach (KeyValuePair <string, StarScan.ScanNode> moonnodes in planetnodes.Value.children)
                                        {
                                            DumpInfo(ap, moonnodes, prefix + "Moon_" + starno.ToString(ct) + "_" + pcount.ToString(ct) + "_" + mcount.ToString(ct), "_Submoons");

                                            if (moonnodes.Value.children != null)
                                            {
                                                int smcount = 1;
                                                foreach (KeyValuePair <string, StarScan.ScanNode> submoonnodes in moonnodes.Value.children)
                                                {
                                                    DumpInfo(ap, submoonnodes, prefix + "SubMoon_" + starno.ToString(ct) + "_" + pcount.ToString(ct) + "_" + mcount.ToString(ct) + "_" + smcount.ToString(ct), null);
                                                    smcount++;
                                                }
                                            }

                                            mcount++;
                                        }
                                    }

                                    pcount++;
                                }
                            }

                            starno++;
                        }
                    }
                    else
                    {
                        ap[prefix + "Stars"] = "0";
                    }
                }
                else
                {
                    ap.ReportError("Missing starname in Scan");
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Exemple #19
0
        }                                                          // update user data, if allow direct editing

        public virtual bool ExecuteAction(ActionProgramRun ap)     // execute action in the action program context.. AP has data on current state, variables etc.
        {
            return(false);
        }
        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 cmdname = sp.NextWord();

                if (cmdname == null)
                {
                    ap.ReportError("Missing panel name in Historytab");
                }
                else
                {
                    ExtendedControls.TabStrip ts = (ap.actioncontroller as ActionController).DiscoveryForm.PrimarySplitter.GetTabStrip(cmdname);     // case insensitive

                    if (ts != null)
                    {
                        string nextcmd = sp.NextWordLCInvariant(" ");

                        if (nextcmd == null)
                        {
                            ap.ReportError("Missing command after panel name in Historytab");
                        }
                        else if (nextcmd.Equals("toggle"))
                        {
                            ts.Toggle();
                        }
                        else
                        {
                            PopOutControl             poc = (ap.actioncontroller as ActionController).DiscoveryForm.PopOuts;
                            PanelInformation.PanelIDs?id  = PanelInformation.GetPanelIDByWindowsRefName(nextcmd);

                            if (id != null)
                            {
                                PanelInformation.PanelIDs[] list = ts.TagList.Cast <PanelInformation.PanelIDs>().ToArray();
                                int index = Array.IndexOf(list, id.Value);
                                if (!ts.ChangePanel(index))
                                {
                                    ap.ReportError("Panel " + nextcmd + " cannot be used in Historytab");
                                }
                            }
                            else
                            {
                                ap.ReportError("Cannot find generic panel type name " + nextcmd + " in Historytab");
                            }
                        }
                    }
                    else
                    {
                        ap.ReportError("Unknown panel name or panels re-ordered " + cmdname + " in Historytab");
                    }
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Exemple #21
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            List <string> ctrl = FromString(UserData);

            if (ctrl != null)
            {
                List <string> exp;

                if (ap.functions.ExpandStrings(ctrl, out exp) != BaseUtils.Functions.ExpandResult.Failed)
                {
                    int time;
                    if (exp[1].InvariantParse(out time))
                    {
                        HistoryEntry he = null;
                        long         jid;
                        if (exp.Count >= 3)
                        {
                            if (exp[2].InvariantParse(out jid))
                            {
                                he = (ap.actioncontroller as ActionController).HistoryList.GetByJID(jid);

                                if (he == null)
                                {
                                    ap.ReportError("Timer could not find event " + jid);
                                    return(true);
                                }
                            }
                            else
                            {
                                ap.ReportError("Timer JID is not an integer ");
                                return(true);
                            }
                        }

                        if (exp[0].StartsWith("+"))         // + name means replace if running
                        {
                            exp[0] = exp[0].Substring(1);

                            Timer told = timers.Find(x => ((TimerInfo)x.Tag).name.Equals(exp[0]));
                            //System.Diagnostics.Debug.WriteLine("Timers " + timers.Count);

                            if (told != null)
                            {
                                System.Diagnostics.Debug.WriteLine("Replace timer " + exp[0]);
                                told.Stop();
                                told.Interval = time;
                                told.Start();
                                return(true);
                            }
                        }

                        Timer t = new Timer()
                        {
                            Interval = time
                        };
                        t.Tick += Timer_Tick;
                        t.Tag   = new TimerInfo()
                        {
                            ap = ap, name = exp[0], he = he
                        };
                        timers.Add(t);
                        t.Start();
                        System.Diagnostics.Debug.WriteLine("Timer Go " + exp[0]);
                    }
                    else
                    {
                        ap.ReportError("Timer bad name or time count");
                    }
                }
                else
                {
                    ap.ReportError(exp[0]);
                }
            }
            else
            {
                ap.ReportError("Timer command line not in correct format");
            }

            return(true);
        }
Exemple #22
0
        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  = "EB_";
                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 EliteBindings");
                        return(true);
                    }

                    cmdname = sp.NextQuotedWord();
                }

                BindingsFile bf = (ap.actioncontroller as ActionController).DiscoveryForm.FrontierBindings;

                int    matchno = 1;
                string list    = "";

                while (cmdname != null)
                {
                    bool partial = false;
                    int  i       = cmdname.IndexOf("*");
                    if (i >= 0)
                    {
                        cmdname = cmdname.Substring(0, i);
                        partial = true;
                    }

                    List <BindingsFile.Assignment> matches = bf.Find(cmdname, partial);

                    if (matches.Count > 0)
                    {
                        foreach (BindingsFile.Assignment a in matches)
                        {
                            ap[prefix + "Binding" + matchno.ToStringInvariant()] = a.ToString();
                            list += a.ToString() + Environment.NewLine;
                            matchno++;
                        }
                    }

                    Dictionary <string, string> values = bf.BindingValue(cmdname, partial);
                    foreach (string k in values.Keys)
                    {
                        ap[prefix + k] = values[k];
                        list          += k + "=" + values[k] + Environment.NewLine;
                    }

                    cmdname = sp.NextQuotedWord();
                }

                ap[prefix + "Text"] = list;
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Exemple #23
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;
        }
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            List <string> preexpand = FromString(UserData);

            if (preexpand != null)
            {
                List <string> exp;

                if (ap.Functions.ExpandStrings(preexpand, out exp) != Functions.ExpandResult.Failed && preexpand.Count >= 2)
                {
                    System.Diagnostics.Debug.WriteLine("dll call " + string.Join(",", preexpand));

                    if (exp[1].Equals("JournalEntry", StringComparison.InvariantCultureIgnoreCase))
                    {
                        long?jid = null;
                        if (exp.Count == 3)
                        {
                            jid = exp[2].InvariantParseLongNull();
                        }

                        if (jid.HasValue)
                        {
                            var          ac = (ap.ActionController as ActionController);
                            HistoryList  hl = ac.DiscoveryForm.history;
                            HistoryEntry h  = ac.DiscoveryForm.history.GetByJID(jid.Value);

                            if (h != null)
                            {
                                Tuple <bool, bool> ret = (ap.ActionController as ActionController).DiscoveryForm.DLLManager.
                                                         ActionJournalEntry(exp[0], EliteDangerousCore.DLL.EDDDLLCallerHE.CreateFromHistoryEntry(hl, h));
                                if (ret.Item1 == false)
                                {
                                    ap.ReportError("DLLCall cannot find DLL '" + exp[0] + "'");
                                }
                                else if (ret.Item2 == false)
                                {
                                    ap.ReportError("DLL '" + exp[0] + "' does not implement ActionJournalEntry");
                                }
                            }
                            else
                            {
                                ap.ReportError("DLLCall JournalEntry history does not have that JID");
                            }
                        }
                        else
                        {
                            ap.ReportError("DLLCall JournalEntry missing Journal ID");
                        }
                    }
                    else
                    {
                        string[] paras = exp.GetRange(2, exp.Count - 2).ToArray();

                        List <Tuple <bool, string, string> > res = (ap.ActionController as ActionController).DiscoveryForm.DLLManager.ActionCommand(exp[0], exp[1], paras);

                        ap["DLLCalled"] = res.Count.ToStringInvariant();

                        if (res.Count == 0)         // if no calls
                        {
                            ap.ReportError("No DLLs found");
                        }
                        else
                        {
                            for (int i = 0; i < res.Count; i++)
                            {
                                ap["DLL[" + (i + 1).ToStringInvariant() + "]"] = res[i].Item2;

                                if (res[i].Item1 == false)       // error, create an error
                                {
                                    ap.ReportError("DLL " + res[i].Item2 + ": " + res[i].Item3);
                                }
                                else
                                {
                                    ap["DLLResult[" + (i + 1).ToStringInvariant() + "]"] = res[i].Item3;
                                }
                            }
                        }
                    }
                }
                else
                {
                    ap.ReportError(exp[0]);
                }
            }
            else
            {
                ap.ReportError("DLLCall command line not in correct format");
            }


            return(true);
        }
Exemple #25
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);
        }
Exemple #26
0
        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  = "B_";
                string cmdname = sp.NextWord();

                if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase))
                {
                    prefix = sp.NextWord();

                    if (prefix == null)
                    {
                        ap.ReportError("Missing name after Prefix in Bookmarks");
                        return(true);
                    }

                    cmdname = sp.NextWord();
                }

                if (cmdname != null)
                {
                    if (cmdname.Equals("LIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string wildcard = sp.NextQuotedWord() ?? "*";

                        int bcount = 1;
                        foreach (BookmarkClass b in GlobalBookMarkList.Instance.Bookmarks)
                        {
                            if (b.Name.WildCardMatch(wildcard, true))
                            {
                                string nprefix = prefix + bcount++.ToStringInvariant() + "_";

                                ap[nprefix + "isstar"] = b.isStar.ToStringIntValue();
                                ap[nprefix + "name"]   = b.Name;
                                ap[nprefix + "x"]      = b.x.ToStringInvariant();
                                ap[nprefix + "y"]      = b.y.ToStringInvariant();
                                ap[nprefix + "z"]      = b.z.ToStringInvariant();
                                ap[nprefix + "time"]   = b.TimeUTC.ToStringUS(); // US Date format
                                ap[nprefix + "note"]   = b.Note;

                                if (b.PlanetaryMarks != null)
                                {
                                    string pprefix = nprefix + "Planet_";
                                    ap[pprefix + "Count"] = b.PlanetaryMarks.Planets.Count().ToStringInvariant();

                                    int pcount = 1;
                                    foreach (PlanetMarks.Planet p in b.PlanetaryMarks.Planets)
                                    {
                                        string plname = pprefix + pcount++.ToStringInvariant() + "_";
                                        ap[plname + "name"]  = p.Name;
                                        ap[plname + "Count"] = p.Locations.Count.ToStringInvariant();

                                        int lcount = 1;
                                        foreach (PlanetMarks.Location l in p.Locations)
                                        {
                                            string locname = plname + lcount++.ToStringInvariant() + "_";
                                            ap[locname + "name"]      = l.Name;
                                            ap[locname + "comment"]   = l.Comment;
                                            ap[locname + "latitude"]  = l.Latitude.ToStringInvariant("0.#");
                                            ap[locname + "longitude"] = l.Longitude.ToStringInvariant("0.#");
                                        }
                                    }
                                }
                            }
                        }

                        ap[prefix + "MatchCount"] = (bcount - 1).ToStringInvariant();
                        ap[prefix + "TotalCount"] = GlobalBookMarkList.Instance.Bookmarks.Count.ToStringInvariant();
                    }
                    else
                    {
                        string name   = sp.NextQuotedWord();
                        bool   region = name.Equals("REGION", StringComparison.InvariantCultureIgnoreCase);
                        if (region)
                        {
                            name = sp.NextQuotedWord();
                        }

                        if (name == null)
                        {
                            ap.ReportError("Missing name in command");
                        }
                        else if (cmdname.Equals("EXIST", StringComparison.InvariantCultureIgnoreCase))
                        {
                            BookmarkClass bk = GlobalBookMarkList.Instance.FindBookmark(name, region);
                            ap[prefix + "Exists"] = (bk != null).ToStringIntValue();
                        }
                        else if (cmdname.Equals("ADD", StringComparison.InvariantCultureIgnoreCase))
                        {
                            double?x     = sp.NextDouble();
                            double?y     = sp.NextDouble();
                            double?z     = sp.NextDouble();
                            string notes = sp.NextQuotedWord(); // valid for it to be null.  Means don't update notes

                            if (x != null && y != null && z != null)
                            {
                                BookmarkClass bk = GlobalBookMarkList.Instance.FindBookmark(name, region);
                                GlobalBookMarkList.Instance.AddOrUpdateBookmark(bk, !region, name, x.Value, y.Value, z.Value, DateTime.Now, notes);
                            }
                            else
                            {
                                ap.ReportError("Missing parameters in Add");
                            }
                        }
                        else if (cmdname.Equals("DELETE", StringComparison.InvariantCultureIgnoreCase))
                        {
                            BookmarkClass bk = GlobalBookMarkList.Instance.FindBookmark(name, region);
                            if (bk != null)
                            {
                                GlobalBookMarkList.Instance.Delete(bk);
                            }
                            else
                            {
                                ap.ReportError("Delete cannot find star or region " + name);
                            }
                        }
                        else if (cmdname.Equals("UPDATENOTE", StringComparison.InvariantCultureIgnoreCase))
                        {
                            string notes = sp.NextQuotedWord();

                            if (notes != null)
                            {
                                BookmarkClass bk = GlobalBookMarkList.Instance.FindBookmark(name, region);
                                if (bk != null)
                                {
                                    bk.UpdateNotes(notes);
                                    GlobalBookMarkList.Instance.TriggerChange(bk);
                                }
                                else
                                {
                                    ap.ReportError("UpdateNote cannot find star or region " + name);
                                }
                            }
                            else
                            {
                                ap.ReportError("UpdateNote notes not present");
                            }
                        }
                        else
                        {
                            bool addstar            = cmdname.Equals("ADDSTAR", StringComparison.InvariantCultureIgnoreCase);
                            bool addplanet          = cmdname.Equals("ADDPLANET", StringComparison.InvariantCultureIgnoreCase);
                            bool deleteplanet       = cmdname.Equals("DELETEPLANET", StringComparison.InvariantCultureIgnoreCase);
                            bool updatenoteonplanet = cmdname.Equals("UPDATEPLANETNOTE", StringComparison.InvariantCultureIgnoreCase);
                            bool planetmarkexists   = cmdname.Equals("PLANETMARKEXISTS", StringComparison.InvariantCultureIgnoreCase);

                            if (!addstar && !addplanet && !deleteplanet && !updatenoteonplanet && !planetmarkexists)
                            {
                                ap.ReportError("Unknown command");
                            }
                            else if (region)
                            {
                                ap.ReportError("Command and REGION are incompatible");
                            }
                            else if (addstar)
                            {
                                var     df  = (ap.ActionController as ActionController).DiscoveryForm;
                                ISystem sys = df.history.FindSystem(name, df.galacticMapping, true);

                                if (sys != null)
                                {
                                    string        notes = sp.NextQuotedWord(); // valid for it to be null, means don't override or set to empty
                                    BookmarkClass bk    = GlobalBookMarkList.Instance.FindBookmarkOnSystem(name);
                                    GlobalBookMarkList.Instance.AddOrUpdateBookmark(bk, true, name, sys.X, sys.Y, sys.Z, DateTime.UtcNow, notes);
                                }
                                else
                                {
                                    ap.ReportError("AddStar cannot find star " + name + " in database");
                                }
                            }
                            else
                            {
                                BookmarkClass bk = GlobalBookMarkList.Instance.FindBookmarkOnSystem(name);

                                if (bk != null)
                                {
                                    string planet    = sp.NextQuotedWord();
                                    string placename = sp.NextQuotedWord();

                                    if (planet != null && placename != null)
                                    {
                                        if (addplanet)
                                        {
                                            double?latp    = sp.NextDouble();
                                            double?longp   = sp.NextDouble();
                                            string comment = sp.NextQuotedWord();       // can be null

                                            if (planet != null && latp != null && longp != null)
                                            {
                                                bk.AddOrUpdateLocation(planet, placename, comment ?? "", latp.Value, longp.Value);
                                                GlobalBookMarkList.Instance.TriggerChange(bk);
                                            }
                                            else
                                            {
                                                ap.ReportError("AddPlanet missing parameters");
                                            }
                                        }
                                        else if (updatenoteonplanet)
                                        {
                                            string comment = sp.NextQuotedWord();
                                            if (comment != null)
                                            {
                                                if (bk.UpdateLocationComment(planet, placename, comment))
                                                {
                                                    GlobalBookMarkList.Instance.TriggerChange(bk);
                                                }
                                                else
                                                {
                                                    ap.ReportError("UpdatePlanetNote no such placename");
                                                }
                                            }
                                            else
                                            {
                                                ap.ReportError("UpdatePlanetNote no comment");
                                            }
                                        }
                                        else if (deleteplanet)
                                        {
                                            if (bk.DeleteLocation(planet, placename))
                                            {
                                                GlobalBookMarkList.Instance.TriggerChange(bk);
                                            }
                                            else
                                            {
                                                ap.ReportError("DeletePlanet no such placename");
                                            }
                                        }
                                        else if (planetmarkexists)
                                        {
                                            ap[prefix + "Exists"] = bk.HasLocation(planet, placename).ToStringIntValue();
                                        }
                                    }
                                    else
                                    {
                                        ap.ReportError("Missing planet and/or placename");
                                    }
                                }
                                else
                                {
                                    ap.ReportError("Cannot find bookmark for " + name);
                                }
                            }
                        }
                    }
                }
                else
                {
                    ap.ReportError("Missing Bookmarks command");
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Exemple #27
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            List <string> ctrl = FromString(UserData);

            if (ctrl != null)
            {
                List <string> exp;

                if (ap.Functions.ExpandStrings(ctrl, out exp) != Functions.ExpandResult.Failed)
                {
                    string cmdname    = exp[0].ToLowerInvariant();
                    string nextword   = exp.Count >= 2 ? exp[1] : null;
                    string thirdword  = exp.Count >= 3 ? exp[2] : null;
                    string fourthword = exp.Count >= 4 ? exp[3] : null;
                    string fifthword  = exp.Count >= 5 ? exp[4] : null;

                    if (cmdname == null)
                    {
                        ap.ReportError("Missing command in Perform");
                    }
                    else if (cmdname.Equals("3dmap"))
                    {
                        (ap.ActionController as ActionController).DiscoveryForm.Open3DMap(null);
                    }
                    else if (cmdname.Equals("2dmap"))
                    {
                        (ap.ActionController as ActionController).DiscoveryForm.PopOuts.PopOut(PanelInformation.PanelIDs.Map2D);
                    }
                    else if (cmdname.Equals("edsm"))
                    {
                        ActionController ac = (ap.ActionController as ActionController);

                        EliteDangerousCore.EDSM.EDSMClass edsm = new EliteDangerousCore.EDSM.EDSMClass();

                        if (edsm.ValidCredentials)
                        {
                            ac.DiscoveryForm.EDSMSend();
                        }
                        else
                        {
                            ap.ReportError("No valid EDSM Credentials");
                        }
                    }
                    else if (cmdname.Equals("refresh"))
                    {
                        (ap.ActionController as ActionController).DiscoveryForm.RefreshHistoryAsync();
                    }
                    else if (cmdname.Equals("url"))
                    {
                        if (nextword != null && nextword.StartsWith("http:", StringComparison.InvariantCultureIgnoreCase) || nextword.StartsWith("https:", StringComparison.InvariantCultureIgnoreCase))        // security..
                        {
                            System.Diagnostics.Process.Start(nextword);
                        }
                        else
                        {
                            ap.ReportError("Perform url must start with http");
                        }
                    }
                    else if (cmdname.Equals("configurevoice"))
                    {
                        (ap.ActionController as ActionController).ConfigureVoice(nextword ?? "Configure Voice Synthesis");
                    }
                    else if (cmdname.Equals("manageaddons"))
                    {
                        (ap.ActionController as ActionController).ManageAddOns();
                    }
                    else if (cmdname.Equals("editaddons"))
                    {
                        (ap.ActionController as ActionController).EditAddOns();
                    }
                    else if (cmdname.Equals("editlastpack"))
                    {
                        (ap.ActionController as ActionController).EditLastPack();
                    }
                    else if (cmdname.Equals("editpack"))
                    {
                        if (nextword != null)
                        {
                            if (!(ap.ActionController as ActionController).EditPack(nextword))
                            {
                                ap.ReportError("Pack " + nextword + " not found");
                            }
                        }
                        else
                        {
                            ap.ReportError("EditPack requires a pack name");
                        }
                    }
                    else if (cmdname.Equals("editspeechtext"))
                    {
                        (ap.ActionController as ActionController).EditSpeechText();
                    }
                    else if (cmdname.Equals("configurewave"))
                    {
                        (ap.ActionController as ActionController).ConfigureWave(nextword ?? "Configure Wave Output");
                    }
                    else if (cmdname.Equals("enableeliteinput"))
                    {
                        (ap.ActionController as ActionController).EliteInput(true, true);
                    }
                    else if (cmdname.Equals("enableeliteinputnoaxis"))
                    {
                        (ap.ActionController as ActionController).EliteInput(true, false);
                    }
                    else if (cmdname.Equals("disableeliteinput"))
                    {
                        (ap.ActionController as ActionController).EliteInput(false, false);
                    }
                    else if (cmdname.Equals("enablevoicerecognition"))
                    {
                        if (nextword != null)
                        {
                            ap["VoiceRecognitionEnabled"] = ((ap.ActionController as ActionController).VoiceReconOn(nextword)).ToStringIntValue();
                        }
                        else
                        {
                            ap.ReportError("EnableVoiceRecognition requires a culture");
                        }
                    }
                    else if (cmdname.Equals("disablevoicerecognition"))
                    {
                        (ap.ActionController as ActionController).VoiceReconOff();
                    }
                    else if (cmdname.Equals("beginvoicerecognition"))
                    {
                        (ap.ActionController as ActionController).VoiceLoadEvents();
                    }
                    else if (cmdname.Equals("voicerecognitionconfidencelevel"))
                    {
                        float?conf = nextword.InvariantParseFloatNull();
                        if (conf != null)
                        {
                            (ap.ActionController as ActionController).VoiceReconConfidence(conf.Value);
                        }
                        else
                        {
                            ap.ReportError("VoiceRecognitionConfidencelLevel requires a confidence value");
                        }
                    }
                    else if (cmdname.Equals("voicerecognitionparameters"))
                    {
                        int?babble              = nextword.InvariantParseIntNull();   // babble at end
                        int?initialsilence      = thirdword.InvariantParseIntNull();  // silence at end
                        int?endsilence          = fourthword.InvariantParseIntNull(); // unambigious timeout
                        int?endsilenceambigious = fifthword.InvariantParseIntNull();  // ambiguous timeout

                        if (babble != null && initialsilence != null && endsilence != null && endsilenceambigious != null)
                        {
                            (ap.ActionController as ActionController).VoiceReconParameters(babble.Value, initialsilence.Value, endsilence.Value, endsilenceambigious.Value);
                        }
                        else
                        {
                            ap.ReportError("VoiceRecognitionParameters requires four values");
                        }
                    }
                    else if (cmdname.Equals("voicerecognitionphrases"))
                    {
                        ap["Phrases"] = (ap.ActionController as ActionController).VoicePhrases(Environment.NewLine);
                    }
                    else if (cmdname.Equals("listeliteinput"))
                    {
                        ap["EliteInput"]      = (ap.ActionController as ActionController).EliteInputList();
                        ap["EliteInputCheck"] = (ap.ActionController as ActionController).EliteInputCheck();
                    }
                    else if (cmdname.Equals("voicenames"))
                    {
                        ap["VoiceNames"] = (ap.ActionController as ActionController).SpeechSynthesizer.GetVoiceNames().QuoteStrings();
                    }
                    else if (cmdname.Equals("bindings"))
                    {
                        ap["Bindings"] = (ap.ActionController as ActionController).FrontierBindings.ListBindings();
                    }
                    else if (cmdname.Equals("bindingvalues"))
                    {
                        ap["BindingValues"] = (ap.ActionController as ActionController).FrontierBindings.ListValues();
                    }
                    else if (cmdname.Equals("actionfile"))
                    {
                        ActionFile f = (ap.ActionController as ActionController).Get(nextword);
                        if (f != null)
                        {
                            int i = 0;
                            foreach (var x in f.EventList.Enumerable)
                            {
                                ap["Events[" + i++ + "]"]   = x.ToString(true); // list hooked events
                                ap["Events_" + x.eventname] = x.ToString(true); // list hooked events
                            }

                            i = 0;
                            foreach (string jname in Enum.GetNames(typeof(EliteDangerousCore.JournalTypeEnum)))
                            {
                                List <Condition> cl = f.EventList.GetConditionListByEventName(jname);

                                if (cl != null)
                                {
                                    int v = 0;
                                    foreach (var c in cl)
                                    {
                                        ap["JEvents[" + i++ + "]"] = c.ToString(true);
                                        ap["JEvents_" + c.eventname + "_" + v++] = c.ToString(true);
                                    }
                                }
                                else
                                {
                                    ap["JEvents[" + i++ + "]"] = jname + ", None";
                                    ap["JEvents_" + jname]     = "None";
                                }
                            }

                            i = 0;
                            foreach (string iname in Enum.GetNames(typeof(EliteDangerousCore.UITypeEnum)))
                            {
                                List <Condition> cl = f.EventList.GetConditionListByEventName("UI" + iname);

                                if (cl != null)
                                {
                                    int v = 0;
                                    foreach (var c in cl)
                                    {
                                        ap["UIEvents[" + i++ + "]"] = c.ToString(true);
                                        ap["UIEvents_" + c.eventname + "_" + v++] = c.ToString(true);
                                    }
                                }
                                else
                                {
                                    ap["UIEvents[" + i++ + "]"] = iname + ", None";
                                    ap["UIEvents_" + iname]     = "None";
                                }
                            }

                            i = 0;
                            foreach (var x in f.InstallationVariables.NameEnumuerable)
                            {
                                ap["Install[" + i++ + "]"] = x + "," + f.InstallationVariables[x];   // list hooked events
                            }
                            i = 0;
                            foreach (var x in f.FileVariables.NameEnumuerable)
                            {
                                ap["FileVar[" + i++ + "]"] = x + "," + f.FileVariables[x];   // list hooked events
                            }
                            ap["Enabled"] = f.Enabled.ToStringIntValue();
                        }
                        else
                        {
                            ap.ReportError("Action file " + nextword + " is not loaded");
                        }
                    }
                    else if (cmdname.Equals("datadownload"))
                    {
                        string gitfolder    = nextword;
                        string filewildcard = thirdword;
                        string directory    = fourthword;
                        string optclean     = fifthword;

                        if (gitfolder != null && filewildcard != null && directory != null)
                        {
                            if (System.IO.Directory.Exists(directory))
                            {
                                BaseUtils.GitHubClass ghc = new BaseUtils.GitHubClass(EDDiscovery.Properties.Resources.URLGithubDataDownload);
                                bool worked = ghc.Download(directory, gitfolder, filewildcard, optclean != null && optclean == "1");
                                ap["Downloaded"] = worked.ToStringIntValue();
                            }
                            else
                            {
                                ap.ReportError("Download folder " + directory + " does not exist");
                            }
                        }
                        else
                        {
                            ap.ReportError("Missing parameters in Perform Datadownload");
                        }
                    }
                    else if (cmdname.Equals("generateevent"))
                    {
                        if (nextword != null)
                        {
                            ActionEvent f = ActionEventEDList.EventList(excludejournal: true).Find(x => x.TriggerName.Equals(nextword));

                            if (f != null)
                            {
                                BaseUtils.Variables c = new BaseUtils.Variables();

                                for (int w = 2; w < exp.Count; w++)
                                {
                                    string vname    = exp[w];
                                    int    asterisk = vname.IndexOf('*');

                                    if (asterisk >= 0)      // pass in name* no complaining if not there
                                    {
                                        string prefix = vname.Substring(0, asterisk);

                                        foreach (string jkey in ap.variables.NameEnumuerable)
                                        {
                                            if (jkey.StartsWith(prefix))
                                            {
                                                c[jkey] = ap.variables[jkey];
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (ap.variables.Exists(vname))     // pass in explicit name
                                        {
                                            c[vname] = ap.variables[vname];
                                        }
                                        else
                                        {
                                            ap.ReportError("No such variable '" + vname + "'");
                                            return(true);
                                        }
                                    }
                                }

                                if (f.TriggerName.StartsWith("UI") || f.TriggerName.Equals("onEliteUIEvent"))
                                {
                                    c["EventClass_EventTimeUTC"] = DateTime.UtcNow.ToStringUS();
                                    c["EventClass_EventTypeID"]  = c["EventClass_EventTypeStr"] = f.TriggerName.Substring(2);
                                    c["EventClass_UIDisplayed"]  = "0";
                                    (ap.ActionController as ActionController).ActionRun(Actions.ActionEventEDList.onUIEvent, c);
                                }

                                (ap.ActionController as ActionController).ActionRun(f, c, now: true);
                            }
                            else
                            {
                                try
                                {
                                    EliteDangerousCore.JournalEntry je = EliteDangerousCore.JournalEntry.CreateJournalEntry(nextword);

                                    ap["GenerateEventName"] = je.EventTypeStr;

                                    if (je is EliteDangerousCore.JournalEvents.JournalUnknown)
                                    {
                                        ap.ReportError("Unknown journal event");
                                    }
                                    else
                                    {
                                        EliteDangerousCore.HistoryEntry he = EliteDangerousCore.HistoryEntry.FromJournalEntry(je, null);
                                        (ap.ActionController as ActionController).ActionRunOnEntry(he, Actions.ActionEventEDList.NewEntry(he), now: true);
                                    }
                                }
                                catch
                                {
                                    ap.ReportError("Journal event not in correct JSON form");
                                }
                            }
                        }
                        else
                        {
                            ap.ReportError("No journal event or event name after GenerateEvent");
                        }
                    }
                    else
                    {
                        ap.ReportError("Unknown command " + cmdname + " in Performaction");
                    }
                }
                else
                {
                    ap.ReportError(exp[0]);
                }
            }
            else
            {
                ap.ReportError("Perform command line not in correct format");
            }

            return(true);
        }
        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 = "P_";

                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 in Popout");
                        return(true);
                    }

                    cmdname = sp.NextQuotedWord();
                }

                PopOutControl poc = (ap.actioncontroller as ActionController).DiscoveryForm.PopOuts;

                if (cmdname == null)
                {
                    ap.ReportError("Missing command or popout name in Popout");
                }
                else if (cmdname.Equals("Status", StringComparison.InvariantCultureIgnoreCase))
                {
                    ap[prefix + "Count"] = poc.Count.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    for (int i = 0; i < poc.Count; i++)
                    {
                        ap[prefix + i.ToString(System.Globalization.CultureInfo.InvariantCulture)] = poc[i].Name;
                    }
                }
                else
                {
                    Forms.UserControlForm ucf = poc.GetByWindowsRefName(cmdname);

                    string nextcmd = sp.NextWordLCInvariant(" ");

                    if (nextcmd == null)
                    {
                        ap.ReportError("Missing command after popout name in Popout");
                    }
                    else if (nextcmd.Equals("status"))
                    {
                        ap[prefix + "Exists"] = (ucf != null) ? "1" : "0";

                        if (ucf != null)
                        {
                            ap[prefix + "Transparent"]   = ucf.IsTransparent ? "1" : "0";
                            ap[prefix + "TopMost"]       = ucf.TopMost ? "1" : "0";
                            ap[prefix + "DisplayTitle"]  = ucf.displayTitle ? "1" : "0";
                            ap[prefix + "ShowInTaskbar"] = ucf.ShowInTaskbar ? "1" : "0";
                            ap[prefix + "WindowState"]   = ucf.WindowState.ToString();
                            ap[prefix + "Top"]           = ucf.Top.ToString(System.Globalization.CultureInfo.InvariantCulture);
                            ap[prefix + "Left"]          = ucf.Left.ToString(System.Globalization.CultureInfo.InvariantCulture);
                            ap[prefix + "Width"]         = ucf.Width.ToString(System.Globalization.CultureInfo.InvariantCulture);
                            ap[prefix + "Height"]        = ucf.Height.ToString(System.Globalization.CultureInfo.InvariantCulture);
                        }
                    }
                    else if (ucf != null)        // found a panel with the name
                    {
                        if (nextcmd.Equals("toggle") || nextcmd.Equals("off"))
                        {
                            ucf.Close();
                        }
                        else if (nextcmd.Equals("on"))   // does nothing
                        {
                        }
                        else if (nextcmd.Equals("transparent"))
                        {
                            ucf.SetTransparency(Forms.UserControlForm.TransparencyMode.On);
                        }
                        else if (nextcmd.Equals("opaque"))
                        {
                            ucf.SetTransparency(Forms.UserControlForm.TransparencyMode.Off);
                        }
                        else if (nextcmd.Equals("title"))
                        {
                            ucf.SetShowInTaskBar(true);
                        }
                        else if (nextcmd.Equals("notitle"))
                        {
                            ucf.SetShowInTaskBar(false);
                        }
                        else if (nextcmd.Equals("topmost"))
                        {
                            ucf.SetTopMost(true);
                        }
                        else if (nextcmd.Equals("normalz"))
                        {
                            ucf.SetTopMost(false);
                        }
                        else if (nextcmd.Equals("showintaskbar"))
                        {
                            ucf.SetShowInTaskBar(true);
                        }
                        else if (nextcmd.Equals("notshowintaskbar"))
                        {
                            ucf.SetShowInTaskBar(false);
                        }
                        else if (nextcmd.Equals("minimize"))
                        {
                            ucf.WindowState = FormWindowState.Minimized;
                        }
                        else if (nextcmd.Equals("normal"))
                        {
                            ucf.WindowState = FormWindowState.Normal;
                        }
                        else if (nextcmd.Equals("maximize"))
                        {
                            ucf.WindowState = FormWindowState.Maximized;
                        }
                        else if (nextcmd.Equals("location"))
                        {
                            int?x = sp.NextWordComma().InvariantParseIntNull();
                            int?y = sp.NextWordComma().InvariantParseIntNull();
                            int?w = sp.NextWordComma().InvariantParseIntNull();
                            int?h = sp.NextWord().InvariantParseIntNull();

                            if (x.HasValue && y.HasValue && w.HasValue && h.HasValue)
                            {
                                ucf.Location = new Point(x.Value, y.Value);
                                ucf.Size     = new Size(w.Value, h.Value);
                            }
                            else
                            {
                                ap.ReportError("Location needs x,y,w,h in Popout");
                            }
                        }
                        else if (nextcmd.Equals("position"))
                        {
                            int?x = sp.NextWordComma().InvariantParseIntNull();
                            int?y = sp.NextWord().InvariantParseIntNull();

                            if (x.HasValue && y.HasValue)
                            {
                                ucf.Location = new Point(x.Value, y.Value);
                            }
                            else
                            {
                                ap.ReportError("Position needs x,y in Popout");
                            }
                        }
                        else if (nextcmd.Equals("size"))
                        {
                            int?w = sp.NextWordComma().InvariantParseIntNull();
                            int?h = sp.NextWord().InvariantParseIntNull();

                            if (w.HasValue && h.HasValue)
                            {
                                ucf.Size = new Size(w.Value, h.Value);
                            }
                            else
                            {
                                ap.ReportError("Size needs x,y,w,h in Popout");
                            }
                        }
                        else
                        {
                            ap.ReportError("Unknown option " + nextcmd + " after popout name in Popout");
                        }
                    }
                    else
                    {       // pop out not found..
                        PanelInformation.PanelIDs?id = PanelInformation.GetPanelIDByWindowsRefName(cmdname);

                        if (id != null)
                        {
                            if (nextcmd.Equals("off")) // if off, do nothing
                            {
                            }
                            else if (nextcmd.Equals("toggle") || nextcmd.Equals("on"))
                            {
                                poc.PopOut(id.Value);
                            }
                            else
                            {
                                ap.ReportError("Cannot use command " + nextcmd + " after generic popout name in Popout");
                            }
                        }
                        else
                        {
                            ap.ReportError("Cannot find generic popout name " + cmdname + " in Popout");
                        }
                    }
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Exemple #29
0
        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  = "CL_";
                string cmdname = sp.NextWord();

                if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase))
                {
                    prefix = sp.NextWord();

                    if (prefix == null)
                    {
                        ap.ReportError("Missing name after Prefix");
                        return(true);
                    }

                    cmdname = sp.NextWord();
                }

                int cmdrid = EDCommander.CurrentCmdrID;

                if (cmdname != null && cmdname.Equals("CMDR", StringComparison.InvariantCultureIgnoreCase))
                {
                    string name = sp.NextQuotedWord() ?? "-----!";

                    EDCommander cmdr = EDCommander.GetCommander(name);

                    if (cmdr != null)
                    {
                        cmdrid = cmdr.Nr;
                    }
                    else
                    {
                        ap.ReportError("Commander not found");
                    }

                    cmdname = sp.NextWord();
                }

                List <CaptainsLogClass> cllist = GlobalCaptainsLogList.Instance.LogEntriesCmdrTimeOrder(cmdrid);

                EDDiscoveryForm discoveryform = (ap.actioncontroller as ActionController).DiscoveryForm;

                if (cmdname != null)
                {
                    if (cmdname.Equals("LIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string wildcard = sp.NextQuotedWord() ?? "*";

                        Func <CaptainsLogClass, string, bool> validate = CheckSystemBody;

                        string field = sp.NextQuotedWord() ?? "--";
                        if (field.Equals("Body", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckBody;
                        }
                        else if (field.Equals("System", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckSystem;
                        }
                        else if (field.Equals("Tag", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckTags;
                        }
                        else if (field.Equals("Note", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckNote;
                        }
                        else if (field != "--")
                        {
                            ap.ReportError("Unknown field type to list");
                            return(true);
                        }

                        int count = 1;
                        foreach (CaptainsLogClass cl in cllist)       // only current commander ID considered
                        {
                            if (validate(cl, wildcard))
                            {
                                DumpCL(ap, prefix + count++.ToStringInvariant() + "_", cl);
                            }
                        }

                        ap[prefix + "MatchCount"] = (count - 1).ToStringInvariant();
                        ap[prefix + "TotalCount"] = cllist.Count.ToStringInvariant();
                    }
                    else if (cmdname.Equals("ADDHERE", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string note    = sp.NextQuotedWord();
                        string taglist = sp.NextQuotedWord();

                        HistoryEntry he = discoveryform.history.GetLast;

                        if (he != null)
                        {       // taglist can be null.. note must be set.
                            GlobalCaptainsLogList.Instance.AddOrUpdate(null, cmdrid, he.System.Name, he.WhereAmI, DateTime.UtcNow, note ?? "", taglist);
                        }
                        else
                        {
                            ap.ReportError("History has no locations");
                        }
                    }
                    else if (cmdname.Equals("ADD", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string   systemname = sp.NextQuotedWord();
                        string   bodyname   = sp.NextQuotedWord();
                        DateTime?dte        = sp.NextDateTime(System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal);
                        string   note       = sp.NextQuotedWord();
                        string   taglist    = sp.NextQuotedWord();

                        if (systemname != null && bodyname != null && dte != null)
                        {
                            GlobalCaptainsLogList.Instance.AddOrUpdate(null, cmdrid, systemname, bodyname, dte.Value, note ?? "", taglist);
                        }
                        else
                        {
                            ap.ReportError("Missing parameters in ADD");
                        }
                    }
                    else if (cmdname.Equals("TAGLIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string tags = EDDConfig.Instance.CaptainsLogTags;
                        ap[prefix + "Tags"] = tags;
                    }
                    else if (cmdname.Equals("SETTAGLIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string tags = sp.NextQuotedWord();
                        if (tags != null)
                        {
                            EDDConfig.Instance.CaptainsLogTags = tags;
                        }
                        else
                        {
                            ap.ReportError("Missing tag list");
                        }
                    }
                    else if (cmdname.Equals("APPENDTAGLIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string tags = sp.NextQuotedWord();
                        if (tags != null)
                        {
                            EDDConfig.Instance.CaptainsLogTags = EDDConfig.Instance.CaptainsLogTags.AppendPrePad(tags, ";");
                        }
                        else
                        {
                            ap.ReportError("Missing tag list");
                        }
                    }
                    else
                    {   // ********************** Iterator forms, FROM/LAST/FIRST/TIME [Forward|Backward]
                        long?cid = -1;

                        if (cmdname.Equals("From", StringComparison.InvariantCultureIgnoreCase))
                        {
                            cid = sp.NextWord().InvariantParseLongNull();

                            if (cid == null)
                            {
                                ap.ReportError("Non integer CID after FROM");
                                return(true);
                            }
                        }
                        else if (cmdname.Equals("First", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (cllist.Count > 0) //prevent crash if cllist is empty
                            {
                                var mintime = cllist.Min(x => x.TimeUTC);
                                cid = cllist.First(x => x.TimeUTC == mintime).ID;
                            }
                        }
                        else if (cmdname.Equals("Last", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (cllist.Count > 0)
                            {
                                var maxtime = cllist.Max(x => x.TimeUTC);
                                cid = cllist.Last(x => x.TimeUTC == maxtime).ID;
                            }
                        }
                        else if (cmdname.Equals("Time", StringComparison.InvariantCultureIgnoreCase))
                        {
                            DateTime?dte = sp.NextDateTime(System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal);
                            if (dte != null)
                            {
                                if (cllist.Count > 0)
                                {
                                    var firstafter = cllist.FirstOrDefault(x => x.TimeUTC >= dte);

                                    if (firstafter != null)
                                    {
                                        cid = firstafter.ID;
                                    }
                                }
                            }
                            else
                            {
                                ap.ReportError("Missing US date from Time");
                                return(true);
                            }
                        }
                        else
                        {
                            ap.ReportError("Unknown command");
                            return(true);
                        }

                        int indexof = cllist.FindIndex(x => x.ID == cid);   // -1 if not found..

                        string nextcmd = sp.NextWord();

                        if (nextcmd != null)
                        {
                            if (nextcmd.Equals("FORWARD", StringComparison.InvariantCultureIgnoreCase))
                            {
                                if (indexof >= 0)   // don't ruin -1 if set
                                {
                                    indexof++;
                                }

                                nextcmd = sp.NextWord();
                            }
                            else if (nextcmd.Equals("BACKWARD", StringComparison.InvariantCultureIgnoreCase))
                            {
                                indexof--;      // if -1, its okay to make it -2.

                                nextcmd = sp.NextWord();
                            }
                        }

                        bool validindex = indexof >= 0 && indexof < cllist.Count;

                        if (nextcmd != null)
                        {
                            if (!validindex)     // these must have a valid target..
                            {
                                ap.ReportError("Entry is not found");
                            }
                            else
                            {
                                CaptainsLogClass cl = cllist[indexof];

                                if (nextcmd.Equals("DELETE", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    GlobalCaptainsLogList.Instance.Delete(cl);
                                }
                                else
                                {
                                    string text = sp.NextQuotedWord();

                                    if (text != null && sp.IsEOL)
                                    {
                                        if (nextcmd.Equals("NOTE", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            GlobalCaptainsLogList.Instance.AddOrUpdate(cl, cl.Commander, cl.SystemName, cl.BodyName, cl.TimeUTC,
                                                                                       text, cl.Tags, cl.Parameters);
                                        }
                                        else if (nextcmd.Equals("SYSTEM", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            GlobalCaptainsLogList.Instance.AddOrUpdate(cl, cl.Commander, text, cl.BodyName, cl.TimeUTC,
                                                                                       cl.Note, cl.Tags, cl.Parameters);
                                        }
                                        else if (nextcmd.Equals("BODY", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            GlobalCaptainsLogList.Instance.AddOrUpdate(cl, cl.Commander, cl.SystemName, text, cl.TimeUTC,
                                                                                       cl.Note, cl.Tags, cl.Parameters);
                                        }
                                        else
                                        {
                                            ap.ReportError("Unknown command " + nextcmd);
                                        }
                                    }
                                    else
                                    {
                                        ap.ReportError("Missing text or unquoted spaced text after " + nextcmd);
                                    }
                                }
                            }

                            return(true);
                        }


                        if (nextcmd != null)
                        {
                            ap.ReportError("Unknown iterator or command " + nextcmd);
                        }
                        else
                        {       // straight report
                            if (validindex)
                            {
                                DumpCL(ap, prefix, cllist[indexof]);
                            }
                            else
                            {
                                ap[prefix + "Id"] = "-1";
                            }
                        }

                        return(true);
                    }
                }
                else
                {
                    ap.ReportError("Missing command");
                }
            }
            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  = "CMDR_";
                string cmdname = sp.NextWord();

                if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase))
                {
                    prefix = sp.NextWord();

                    if (prefix == null)
                    {
                        ap.ReportError("Missing name after Prefix");
                        return(true);
                    }

                    cmdname = sp.NextWord();
                }

                int cmdrid = EDCommander.CurrentCmdrID;

                if (cmdname != null && cmdname.Equals("CMDR", StringComparison.InvariantCultureIgnoreCase))
                {
                    string name = sp.NextQuotedWord() ?? "-----!";

                    EDCommander cmdr = EDCommander.GetCommander(name);

                    if (cmdr != null)
                    {
                        cmdrid = cmdr.Nr;
                    }
                    else
                    {
                        ap.ReportError("Commander not found");
                    }

                    cmdname = sp.NextWord();
                }

                EDDiscoveryForm discoveryform = (ap.actioncontroller as ActionController).DiscoveryForm;

                List <EDCommander> cmdrlist = EDCommander.GetCommanders();

                if (cmdname != null)
                {
                    if (cmdname.Equals("LIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string wildcard = sp.NextQuotedWord() ?? "*";

                        int count = 1;
                        foreach (var cmdr in cmdrlist)       // only current commander ID considered
                        {
                            if (cmdr.Name.WildCardMatch(wildcard))
                            {
                                DumpCMDR(ap, prefix + count++.ToStringInvariant() + "_", cmdr);
                            }
                        }

                        ap[prefix + "MatchCount"] = (count - 1).ToStringInvariant();
                        ap[prefix + "TotalCount"] = cmdrlist.Count.ToStringInvariant();
                    }
                    else if (cmdname.Equals("CHANGETO", StringComparison.InvariantCultureIgnoreCase))
                    {
                        discoveryform.ChangeToCommander(cmdrid);                                   // which will cause DIsplay to be called as some point
                    }
                    else
                    {
                        ap.ReportError("Unknown command");
                    }
                }
                else
                {
                    ap.ReportError("Missing command");
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }