示例#1
0
        // if aclist has one action, action selector not shown.
        public void Init(string t, string aclist, bool outc, EDDiscovery2.EDDTheme th, JSONFilter j = null)
        {
            // outc selects if group outer action can be selected, else its OR
            theme = th;
            actionlist = aclist;
            allowoutercond = outc;
            hoffset = (actionlist.Split(';').Count()>1) ? (288) : (160);
            panelwidth = hoffset + 620;
            result = j;

            if (result != null)
            {
                foreach (JSONFilter.FilterEvent fe in result.filters)
                {
                    Group g = CreateGroup(fe.eventname, fe.action, fe.innercondition.ToString(), fe.outercondition.ToString());

                    foreach (JSONFilter.Fields f in fe.fields)
                    {
                        CreateCondition(g, f.itemname, JSONFilter.MatchNames[(int)f.matchtype], f.contentmatch);
                    }
                }
            }

            bool winborder = theme.ApplyToForm(this, SystemFonts.DefaultFont);
            statusStripCustom.Visible = panelTop.Visible = !winborder;
            this.Text = label_index.Text = t;
        }
示例#2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            JSONFilter jf = new JSONFilter();

            string errorlist = "";

            foreach (Group g in groups)
            {
                string innerc = g.innercond.Text;
                string outerc = g.outercond.Text;
                string action = g.actionlist.Text;
                string evt = g.evlist.Text;
                System.Diagnostics.Debug.WriteLine("Event {0} inner {1} outer {2}", evt, innerc, outerc);

                JSONFilter.FilterEvent fe = new JSONFilter.FilterEvent();

                if (evt.Length > 0)
                {
                    if (fe.Create(evt, action, "", innerc, outerc))
                    {
                        bool ok = true;

                        for (int i = 0; i < g.panel.Controls.Count && ok; i++)
                        {
                            Control c = g.panel.Controls[i];
                            if (c.Name == "Field")
                            {
                                string fieldn = c.Text;
                                string condn = g.panel.Controls[i + 1].Text;
                                string valuen = g.panel.Controls[i + 2].Text;

                                System.Diagnostics.Debug.WriteLine("  {0} {1} {2}", fieldn, condn, valuen);

                                if (fieldn.Length > 0)
                                {
                                    JSONFilter.Fields f = new JSONFilter.Fields();
                                    ok = (fieldn.Length > 0 && f.Create(fieldn, condn, valuen));

                                    if (ok)
                                    {
                                        if (valuen.Length == 0)
                                            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 in " + fe.eventname + Environment.NewLine;
                            }
                        }

                        if (ok)
                        {
                            if (fe.fields != null)
                                jf.Add(fe);
                            else
                                errorlist += "No valid filters found in group '" + fe.eventname + "'" + Environment.NewLine;
                        }
                    }
                    else
                        errorlist += "Should not happen create failed" + Environment.NewLine;
                }
                else
                    errorlist += "Ignored group with empty name" + Environment.NewLine;
            }

            if (errorlist.Length > 0)
            {
                bool anything = jf.Count > 0;

                string acceptstr = (!anything) ? "Click Retry to correct errors, or Cancel to abort" : "Click Retry to correct errors, Abort to cancel, Ignore to accept what filters are valid";
                DialogResult dr = MessageBox.Show("Filters produced the following warnings and errors" + Environment.NewLine + Environment.NewLine + errorlist + Environment.NewLine + acceptstr,
                                        "Warning", (anything) ? MessageBoxButtons.AbortRetryIgnore : MessageBoxButtons.RetryCancel);

                if (dr == DialogResult.Retry)
                    return;
                if (dr == DialogResult.Abort || dr == DialogResult.Cancel)
                {
                    DialogResult = DialogResult.Cancel;
                    Close();
                    return;
                }
            }

            result = jf;
            DialogResult = DialogResult.OK;
            Close();
        }