Esempio n. 1
0
 public static BehaviorRule AndRule(BehaviorRule r1, BehaviorRule r2)
 {
     return((Entity checkEntity) =>
     {
         return r1(checkEntity) && r2(checkEntity);
     });
 }
Esempio n. 2
0
 public BehaviorType(string fullName, string description, string longDescription, string iconName, Type type,
                     BehaviorRule rule = null)
     : base(fullName, description, longDescription, iconName, type)
 {
     if (rule == null)
     {
         this.rule = DefaultRule;
     }
     else
     {
         this.rule = rule;
     }
 }
Esempio n. 3
0
        public Action ApplyBehavior(IDictionary <string, IControlHolder> namedControlHolders, BehaviorRule rule)
        {
            if (null == namedControlHolders)
            {
                throw new ArgumentNullException(nameof(namedControlHolders));
            }

            if (null == rule)
            {
                throw new ArgumentNullException(nameof(rule));
            }

            return(null);
        }
Esempio n. 4
0
        public Action ApplyBehavior(IDictionary <string, IControlHolder> namedControlHolders, BehaviorRule rule)
        {
            if (null == namedControlHolders)
            {
                throw new ArgumentNullException(nameof(namedControlHolders));
            }

            if (null == rule)
            {
                throw new ArgumentNullException(nameof(rule));
            }

            if (null == rule.Trigger)
            {
                throw new BadTemplateException("null == rule.Trigger");
            }

            if (null == rule.AffectedControls)
            {
                throw new BadTemplateException("null == rule.AffectedControls");
            }

            if (null == rule.Action)
            {
                throw new BadTemplateException("null == rule.Action");
            }

            if (!"CheckedChanged".Equals(rule.Trigger, StringComparison.Ordinal))
            {
                return(null);
            }

            Action action;

            switch (rule.Action)
            {
            case "Enable":

                action = () =>
                {
                    foreach (var affectedControl in rule.AffectedControls)
                    {
                        IControlHolder namedControlHolder;

                        if (!namedControlHolders.TryGetValue(affectedControl, out namedControlHolder))
                        {
                            return;
                        }

                        namedControlHolder.Control.Enabled = Checked;
                    }
                };

                break;

            case "Disable":

                action = () =>
                {
                    foreach (var affectedControl in rule.AffectedControls)
                    {
                        IControlHolder namedControlHolder;

                        if (!namedControlHolders.TryGetValue(affectedControl, out namedControlHolder))
                        {
                            return;
                        }

                        namedControlHolder.Control.Enabled = !Checked;
                    }
                };

                break;

            default:
                throw new BadTemplateException("rule.Type == " + rule.Action);
            }

            CheckedChanged += (sender, args) =>
            {
                action();
            };

            return(action);
        }
Esempio n. 5
0
        public Action ApplyBehavior(IDictionary <string, IControlHolder> namedControlHolders, BehaviorRule rule)
        {
            if (null == namedControlHolders)
            {
                throw new ArgumentNullException(nameof(namedControlHolders));
            }

            if (null == rule)
            {
                throw new ArgumentNullException(nameof(rule));
            }

            if (null == rule.Trigger)
            {
                throw new BadTemplateException("null == rule.Trigger");
            }

            if (null == rule.ActivationСondition)
            {
                throw new BadTemplateException("null == rule.ActivationСondition");
            }

            if (null == rule.AffectedControls)
            {
                throw new BadTemplateException("null == rule.AffectedControls");
            }

            if (null == rule.Action)
            {
                throw new BadTemplateException("null == rule.Action");
            }

            if (!"SelectedIndexChanged".Equals(rule.Trigger, StringComparison.Ordinal))
            {
                return(null);
            }

            switch (rule.Action)
            {
            case "SetVisibility":
            {
                void SetVisibility()
                {
                    var selectedItem = SelectedItem as ComboBoxItem;

                    if (null == selectedItem)
                    {
                        return;
                    }

                    if (!rule.ActivationСondition.Equals((string)selectedItem.Value, StringComparison.Ordinal))
                    {
                        return;
                    }

                    var visibility = bool.Parse(rule.ActionParameter);

                    var parents = new List <Control>();

                    foreach (var affectedControl in rule.AffectedControls)
                    {
                        if (!namedControlHolders.TryGetValue(affectedControl, out var namedControlHolder))
                        {
                            continue;
                        }

                        var parent = namedControlHolder.Control.Parent;

                        if (!parents.Contains(parent))
                        {
                            parents.Add(parent);
                            parent.SuspendLayout();
                        }

                        if (null != namedControlHolder.Label)
                        {
                            namedControlHolder.Label.Visible = visibility;
                        }

                        namedControlHolder.Control.Visible = visibility;
                    }

                    foreach (var parent in parents)
                    {
                        parent.ResumeLayout();

                        if (ApplicationUtility.IsRunningOnMono)
                        {
                            var submitForm = parent.FindForm() as SubmitForm;
                            submitForm?.UpdateSize();
                        }
                    }
                }

                SelectedIndexChanged += (sender, args) =>
                {
                    SetVisibility();
                };

                return(SetVisibility);
            }

            default:
                throw new BadTemplateException("rule.Type == " + rule.Action);
            }
        }
Esempio n. 6
0
 public BehaviorType(string fullName, Type type)
     : base(fullName, type)
 {
     this.rule = DefaultRule;
 }
Esempio n. 7
0
 public BehaviorType(string fullName, string description, string longDescription, string iconName, Type type,
                     BehaviorRule rule)
     : base(fullName, description, longDescription, iconName, type)
 {
     this.rule = rule;
 }
Esempio n. 8
0
 public BehaviorType(string fullName, string description, string iconName, Type type)
     : base(fullName, description, iconName, type)
 {
     this.rule = DefaultRule;
 }