Example #1
0
 public ConditionLists(ConditionLists other)
 {
     foreach (Condition c in other.conditionlist)
     {
         conditionlist.Add(new Condition(c));        //copy, not reference
     }
     groupname = new List <string>(other.groupname);
 }
        // used to start for a condition on an action form (does not need additional names, already resolved)

        public void InitCondition(string t, Icon ic, List <string> varfields, Condition j)
        {
            ConditionLists l = new ConditionLists();

            if (j != null && j.fields != null)
            {
                l.Add(j);
            }
            Init(t, ic, null, varfields, false);
            buttonMore.Visible = true;
            LoadConditions(l);
        }
        public void LoadConditions(ConditionLists clist)
        {
            if (clist != null)
            {
                SuspendLayout();
                this.panelOuter.SuspendLayout();
                panelVScroll.SuspendLayout();

                panelVScroll.RemoveAllControls(new List <Control> {
                    buttonMore
                });                                                                            // except these!

                groups = new List <Group>();

                Condition fe = null;
                for (int i = 0; (fe = clist.Get(i)) != null; i++)
                {
                    Group g = CreateGroupInternal(fe.eventname, fe.action, fe.actiondata, fe.innercondition.ToString(), fe.outercondition.ToString());

                    foreach (ConditionEntry f in fe.fields)
                    {
                        CreateConditionInt(g, f.itemname, ConditionEntry.MatchNames[(int)f.matchtype], f.matchstring);
                    }

                    ExtendedControls.ThemeableFormsInstance.Instance.ApplyToControls(g.panel, SystemFonts.DefaultFont);

                    groups.Add(g);
                }

                System.Runtime.GCLatencyMode lm = System.Runtime.GCSettings.LatencyMode;
                System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.LowLatency;

                foreach (Group g in groups)                         // FURTHER investigation.. when VScroll has been used after the swap, this and fix groups takes ages
                {
                    panelVScroll.Controls.Add(g.panel);             // why? tried a brand new vscroll.  Tried a lot of things.  Is it GC?
                }
                FixUpGroups();                                      // this takes ages too on second load..

                panelVScroll.ResumeLayout();
                this.panelOuter.ResumeLayout();
                ResumeLayout();

                System.Runtime.GCSettings.LatencyMode = lm;
            }

            this.Text = label_index.Text = initialtitle + " (" + groups.Count.ToString() + " conditions)";
        }
        // used to start when inside a condition of an IF of a program action (does not need additional names, already resolved)

        public void InitCondition(string t, Icon ic, List <string> varfields, ConditionLists j = null)
        {
            Init(t, ic, null, varfields, true);
            LoadConditions(j);
        }
        // used to start when just filtering.. uses a fixed event list .. must provide a call back to obtain names associated with an event

        public void InitFilter(string t, Icon ic, List <string> events, AdditionalNames a, List <string> varfields, ConditionLists j = null)
        {
            onAdditionalNames = a;
            this.eventlist    = events;
            events.Add("All");
            Init(t, ic, events, varfields, true);
            LoadConditions(j);
        }
        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);
        }