static public string GetLogicalCondition(BaseUtils.StringParser sp, string delimchars, out LogicalCondition value) { value = LogicalCondition.Or; string condi = sp.NextQuotedWord(delimchars); // next is the inner condition.. if (condi == null) { return("Condition operator missing"); } condi = condi.Replace(" ", ""); if (Enum.TryParse <ConditionEntry.LogicalCondition>(condi.Replace(" ", ""), true, out value)) { return(""); } else { return("Condition operator " + condi + " is not recognised"); } }
private Dictionary <string, string> ReadFromString(BaseUtils.StringParser p, FromMode fm, Dictionary <string, string> altops = null) { Dictionary <string, string> newvars = new Dictionary <string, string>(); while (!p.IsEOL) { string varname = p.NextQuotedWord("= "); if (varname == null) { return(null); } if (altops != null) // with extended ops, the ops are returned in the altops function, one per variable found { // used only with let and set.. if (varname.EndsWith("$+")) { varname = varname.Substring(0, varname.Length - 2); altops[varname] = "$+="; } else if (varname.EndsWith("$")) { varname = varname.Substring(0, varname.Length - 1); altops[varname] = "$="; } else if (varname.EndsWith("+")) { varname = varname.Substring(0, varname.Length - 1); altops[varname] = "+="; } else { altops[varname] = "="; // varname is good, it ended with a = or space, default is = bool dollar = p.IsCharMoveOn('$'); // check for varname space $+ bool add = p.IsCharMoveOn('+'); if (dollar && add) { altops[varname] = "$+="; } else if (dollar) { altops[varname] = "$="; } else if (add) { altops[varname] = "+="; } } } if (!p.IsCharMoveOn('=')) { return(null); } string value = (fm == FromMode.OnePerLine) ? p.NextQuotedWordOrLine() : p.NextQuotedWord((fm == FromMode.MultiEntryComma) ? ", " : ",) "); if (value == null) { return(null); } newvars[varname] = value; if (fm == FromMode.MultiEntryCommaBracketEnds && p.PeekChar() == ')') // bracket, stop don't remove.. outer bit wants to check its there.. { return(newvars); } else if (fm == FromMode.OnePerLine && !p.IsEOL) // single entry, must be eol now { return(null); } else if (!p.IsEOL && !p.IsCharMoveOn(',')) // if not EOL, but not comma, incorrectly formed list { return(null); } } return(newvars); }
// if includeevent is set, it must be there.. // demlimchars is normally space, but can be ") " if its inside a multi. public string Read(BaseUtils.StringParser sp, bool includeevent = false, string delimchars = " ") { Fields = new List <ConditionEntry>(); InnerCondition = OuterCondition = LogicalCondition.Or; EventName = ""; Action = ""; ActionVars = new Variables(); if (includeevent) { string actionvarsstr; if ((EventName = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') || (Action = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') || (actionvarsstr = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',')) { return("Incorrect format of EVENT data associated with condition"); } if (actionvarsstr.HasChars()) { ActionVars = new Variables(actionvarsstr, Variables.FromMode.MultiEntryComma); } } LogicalCondition?ic = null; while (true) { string var = sp.NextQuotedWord(delimchars); // always has para cond if (var == null) { return("Missing parameter (left side) of condition"); } string cond = sp.NextQuotedWord(delimchars); if (cond == null) { return("Missing condition operator"); } ConditionEntry.MatchType mt; if (!ConditionEntry.MatchTypeFromString(cond, out mt)) { return("Condition operator " + cond + " is not recognised"); } string value = ""; if (ConditionEntry.IsNullOperation(mt)) // null operators (Always..) { if (!var.Equals("Condition", StringComparison.InvariantCultureIgnoreCase)) { return("Condition must preceed fixed result operator"); } var = "Condition"; // fix case.. } else if (!ConditionEntry.IsUnaryOperation(mt)) // not unary, require right side { value = sp.NextQuotedWord(delimchars); if (value == null) { return("Missing value part (right side) of condition"); } } ConditionEntry ce = new ConditionEntry() { ItemName = var, MatchCondition = mt, MatchString = value }; Fields.Add(ce); if (sp.IsEOL || sp.PeekChar() == ')') // end is either ) or EOL { InnerCondition = (ic == null) ? LogicalCondition.Or : ic.Value; return(""); } else { LogicalCondition nic; string err = GetLogicalCondition(sp, delimchars, out nic); if (err.Length > 0) { return(err + " for inner condition"); } if (ic == null) { ic = nic; } else if (ic.Value != nic) { return("Cannot specify different inner conditions between expressions"); } } } }
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); }
public string Read(BaseUtils.StringParser sp, bool includeevent = false, string delimchars = " ") // if includeevent is set, it must be there.. { // demlimchars is normally space, but can be ") " if its inside a multi. fields = new List <ConditionEntry>(); innercondition = outercondition = ConditionEntry.LogicalCondition.Or; eventname = ""; action = ""; actiondata = ""; if (includeevent) { if ((eventname = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') || (action = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') || (actiondata = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',')) { return("Incorrect format of EVENT data associated with condition"); } } ConditionEntry.LogicalCondition?ic = null; while (true) { string var = sp.NextQuotedWord(delimchars); // always has para cond if (var == null) { return("Missing parameter (left side) of condition"); } string cond = sp.NextQuotedWord(delimchars); if (cond == null) { return("Missing condition operator"); } ConditionEntry.MatchType mt; if (!ConditionEntry.MatchTypeFromString(cond, out mt)) { return("Condition operator " + cond + " is not recognised"); } string value = ""; if (ConditionEntry.IsNullOperation(mt)) // null operators (Always..) { if (!var.Equals("Condition", StringComparison.InvariantCultureIgnoreCase)) { return("Condition must preceed fixed result operator"); } var = "Condition"; // fix case.. } else if (!ConditionEntry.IsUnaryOperation(mt)) // not unary, require right side { value = sp.NextQuotedWord(delimchars); if (value == null) { return("Missing value part (right side) of condition"); } } ConditionEntry ce = new ConditionEntry() { itemname = var, matchtype = mt, matchstring = value }; fields.Add(ce); if (sp.IsEOL || sp.PeekChar() == ')') // end is either ) or EOL { innercondition = (ic == null) ? ConditionEntry.LogicalCondition.Or : ic.Value; return(""); } else { ConditionEntry.LogicalCondition nic; string err = ConditionEntry.GetLogicalCondition(sp, delimchars, out nic); if (err.Length > 0) { return(err + " for inner condition"); } if (ic == null) { ic = nic; } else if (ic.Value != nic) { return("Cannot specify different inner conditions between expressions"); } } } }