public string ToString(bool includeaction = false, bool multi = false) // multi means quoting needed for ) as well as comma space { string ret = ""; if (includeaction) { ret += eventname.QuoteString(comma: true) + ", " + action.QuoteString(comma: true) + ", " + actiondata.QuoteString(comma: true) + ", "; } for (int i = 0; fields != null && i < fields.Count; i++) { if (i > 0) { ret += " " + innercondition.ToString() + " "; } if (ConditionEntry.IsNullOperation(fields[i].matchtype)) { ret += "Condition " + ConditionEntry.OperatorNames[(int)fields[i].matchtype]; } else { ret += (fields[i].itemname).QuoteString(bracket: multi) + // commas do not need quoting as conditions at written as if always at EOL. " " + ConditionEntry.OperatorNames[(int)fields[i].matchtype]; if (!ConditionEntry.IsUnaryOperation(fields[i].matchtype)) { ret += " " + fields[i].matchstring.QuoteString(bracket: multi); // commas do not need quoting.. } } } return(ret); }
public void IndicateValuesNeeded(ref ConditionVariables vr) { foreach (ConditionEntry fd in fields) { if (!ConditionEntry.IsNullOperation(fd.matchtype) && !fd.itemname.Contains("%")) // nulls need no data.. nor does anything with expand in { vr[fd.itemname] = null; } } }
private string Check() { result = new ConditionLists(); string errorlist = ""; foreach (Group g in groups) { string innerc = g.innercond.Text; string outerc = g.outercond.Text; string evt = (eventlist != null) ? g.evlist.Text : "Default"; //System.Diagnostics.Debug.WriteLine("Event {0} inner {1} outer {2} action {3} data '{4}'", evt, innerc, outerc, actionname, actiondata ); Condition fe = new Condition(); if (evt.Length == 0) // must have name { errorlist += "Ignored group with empty name" + Environment.NewLine; } else { if (fe.Create(evt, "", "", innerc, outerc)) // create must work { for (int i = 0; i < g.condlist.Count; i++) { Group.Conditions c = g.condlist[i]; string fieldn = c.fname.Text; string condn = c.cond.Text; string valuen = c.value.Text; if (fieldn.Length > 0 || ConditionEntry.IsNullOperation(condn)) { ConditionEntry f = new ConditionEntry(); if (f.Create(fieldn, condn, valuen)) { if (valuen.Length == 0 && !ConditionEntry.IsUnaryOperation(condn) && !ConditionEntry.IsNullOperation(condn)) { errorlist += "Do you want filter '" + fieldn + "' in group '" + fe.eventname + "' to have an empty value" + Environment.NewLine; } fe.Add(f); } else { errorlist += "Cannot create filter '" + fieldn + "' in group '" + fe.eventname + "' check value" + Environment.NewLine; } } else { errorlist += "Ignored empty filter " + (i + 1).ToString(System.Globalization.CultureInfo.InvariantCulture) + " in " + fe.eventname + Environment.NewLine; } } if (fe.fields != null) { result.Add(fe); } else { errorlist += "No valid filters found in group '" + fe.eventname + "'" + Environment.NewLine; } } else { errorlist += "Cannot create " + evt + " not a normal error please report" + Environment.NewLine; } } } return(errorlist); }
void FixUpGroups(bool calcminsize = true) // fixes and positions groups. { SuspendLayout(); panelVScroll.SuspendLayout(); int panelwidth = Math.Max(panelVScroll.Width - panelVScroll.ScrollBarWidth, 10); int y = panelymargin; for (int i = 0; i < groups.Count; i++) { Group g = groups[i]; g.panel.SuspendLayout(); // for all groups, see if another group below it has the same event selected as ours bool showouter = false; if (eventlist != null) { for (int j = i - 1; j >= 0; j--) { if (groups[j].evlist.Text.Equals(groups[i].evlist.Text) && groups[i].evlist.Text.Length > 0) { showouter = true; } } showouter &= allowoutercond; // qualify with outer condition switch } else { showouter = (i > 0) && allowoutercond; // and enabled/disable the outer condition switch } g.outercond.Enabled = g.outercond.Visible = g.outerlabel.Visible = showouter; // and enabled/disable the outer condition switch // Now position the conditions inside the panel int vnextcond = panelymargin; int farx = (g.evlist != null) ? (g.evlist.Right - g.innercond.Width + 8) : 0; // innercond cause below adds it back on for (int condc = 0; condc < g.condlist.Count; condc++) { Group.Conditions c = g.condlist[condc]; c.fname.Location = new Point(condxoffset, vnextcond + 2); c.fname.Enabled = !ConditionEntry.IsNullOperation(c.cond.Text); if (!c.fname.Enabled) { c.fname.Text = ""; } c.cond.Location = new Point(c.fname.Right + 4, vnextcond); c.value.Location = new Point(c.cond.Right + 4, vnextcond + 2); c.value.Size = new Size(panelwidth - condxoffset - c.fname.Width - 4 - c.cond.Width - 4 - c.del.Width - 4 - c.more.Width - 4 - g.innercond.Width - 4 - g.upbutton.Width + 8, 24); c.value.Enabled = !ConditionEntry.IsNullOperation(c.cond.Text) && !ConditionEntry.IsUnaryOperation(c.cond.Text); if (!c.value.Enabled) { c.value.Text = ""; } c.del.Location = new Point(c.value.Right + 4, vnextcond); c.more.Location = new Point(c.del.Right + 4, vnextcond); c.more.Visible = (condc == g.condlist.Count - 1); vnextcond += conditionhoff; farx = c.more.Left + 4; // where the more button is } // and the outer/inner conditions g.innercond.Visible = (g.condlist.Count > 1); // inner condition on if multiple g.innercond.Location = new Point(farx, panelymargin); // inner condition is in same place as more button farx = g.innercond.Right + 4; // move off // and the up button.. g.upbutton.Location = new Point(farx, panelymargin); g.upbutton.Visible = (i != 0); farx = g.upbutton.Right; // allocate space for the outercond if req. if (g.outercond.Enabled) { g.outercond.Location = new Point(panelxmargin, vnextcond); g.outerlabel.Location = new Point(g.outercond.Location.X + g.outercond.Width + 4, g.outercond.Location.Y + 3); vnextcond += conditionhoff; } // pos the panel g.panel.Location = new Point(panelxmargin, y + panelVScroll.ScrollOffset); g.panel.Size = new Size(Math.Max(panelwidth - panelxmargin * 2, farx), Math.Max(vnextcond, panelymargin + conditionhoff)); g.panel.BorderStyle = (g.condlist.Count > 1) ? BorderStyle.FixedSingle : BorderStyle.None; y += g.panel.Height + 2; // and make sure actions list is right g.panel.ResumeLayout(); } buttonMore.Location = new Point(panelxmargin, y + panelVScroll.ScrollOffset); buttonMore.Visible = allowoutercond || groups.Count == 0; Rectangle screenRectangle = RectangleToScreen(this.ClientRectangle); int titleHeight = screenRectangle.Top - this.Top; y += buttonMore.Height + titleHeight + ((panelTop.Enabled) ? (panelTop.Height + statusStripCustom.Height) : 8) + 16 + panelOK.Height; if (calcminsize) { this.MinimumSize = new Size(1000, y); this.MaximumSize = new Size(Screen.FromControl(this).WorkingArea.Width - 100, Screen.FromControl(this).WorkingArea.Height - 100); if (Bottom > Screen.FromControl(this).WorkingArea.Height) { Top = Screen.FromControl(this).WorkingArea.Height - Height - 50; } } panelVScroll.ResumeLayout(); ResumeLayout(); }
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"); } } } }