public override void Initialize(EntityExtensions extensions)
        {
            if (!RuleDebugger.CheckNoNotifyPropertyChangedWarning(extensions.Target))
            {
                return;
            }

            var r = new RecursionObject {
                Extensions = extensions, Strategy = this
            };

            // Wire notify property changed
            ((INotifyPropertyChanged)extensions.Target).PropertyChanged += r.OnPropertyChanged;

            // Wire notify collection changed
            foreach (var collection in GetCollections(extensions.Target))
            {
                if (RuleDebugger.CheckNoNotifyCollectionChangedWarning(collection))
                {
                    ((INotifyCollectionChanged)collection).CollectionChanged += r.OnCollectionChanged;
                }
            }

            // Set parent
            foreach (var childObject in GetAllChildObjects(extensions.Target))
            {
                childObject.Parent = extensions;
            }
        }
示例#2
0
        public bool Validate(bool forceValidate = false)
        {
            if (!(forceValidate || Condition(Extensions.Target)))
            {
                return(BrokenRule == null);
            }

            RuleDebugger.Info("Validating rule " + Name);

            bool status;

            using (new RuleEvaluationContext(this))
                status = OnValidate();

            if (!status)
            {
                if (BrokenRule == null)
                {
                    OnRuleBroke();
                }
                else
                {
                    UpdateBrokenRule(BrokenRule);
                }
            }
            else if (status && BrokenRule != null)
            {
                OnRuleRepaired();
            }

            RuleDebugger.Info("Validation status: " + (status ? "valid" : "failed"));

            return(status);
        }
示例#3
0
        public static T Suppresses <T>(this T rule, Rule rule2)
            where T : Rule
        {
            if (string.IsNullOrEmpty(rule.Name))
            {
                rule.Name = "tempName_" + Guid.NewGuid();
                RuleDebugger.Warning("Rule was given a temporary name for the sake of suppression.");
            }

            rule2.SuppressedRules.Add(rule.Name);
            return(rule);
        }
            internal void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                var extensions = Strategy.GetProperty(Extensions.Target, e.PropertyName);

                if (extensions != null)
                {
                    // Set parent to null
                    object oldValue;
                    _objects.TryGetValue(e.PropertyName, out oldValue);
                    if (oldValue != null)
                    {
                        ((IEntityExtensions)oldValue).Parent = null;
                    }

                    // Set parent to value
                    extensions.Parent        = Extensions;
                    _objects[e.PropertyName] = extensions;
                }

                var collection = Strategy.GetCollection(Extensions.Target, e.PropertyName);

                if (RuleDebugger.CheckNoNotifyCollectionChangedWarning(collection))
                {
                    var ncc = (INotifyCollectionChanged)collection;

                    // Unwire collection
                    object oldValue;
                    if (_objects.TryGetValue(e.PropertyName, out oldValue))
                    {
                        var oldncc = (INotifyCollectionChanged)oldValue;
                        oldncc.CollectionChanged -= OnCollectionChanged;

                        // Set old to null
                        foreach (var element in Strategy.GetCollectionElements((IEnumerable)oldncc))
                        {
                            element.Parent = null;
                        }
                    }

                    // Wire new
                    ncc.CollectionChanged += OnCollectionChanged;

                    // Set child parent to value
                    foreach (var element in Strategy.GetCollectionElements(collection))
                    {
                        element.Parent = Extensions;
                    }
                }

                //// Todo: Item[]
            }
示例#5
0
        private bool WireCollectionElement(object obj)
        {
            var npc = obj as INotifyPropertyChanged;

            if (npc != null)
            {
                npc.PropertyChanged += OnCollectionElementChanged;
                return(true);
            }

            var message = string.Format(
                "{0}: \"{1}\" doesn't imlement INotifyCollectionChanged.",
                obj.GetType().Name, obj);

            RuleDebugger.CheckInternal(RuleDebugger.NoNotifyPropertyChangedWarning, message);

            return(false);
        }
示例#6
0
        public bool Validate()
        {
            RuleDebugger.Info("Validating rule " + Name);

            bool status;

            using (new RuleEvaluationContext(this))
                status = OnValidate();

            if (!status && BrokenRule == null)
            {
                OnRuleBroke();
            }
            else if (status && BrokenRule != null)
            {
                OnRuleRepaired();
            }

            RuleDebugger.Info("Validation status: " + (status ? "valid" : "failed"));

            return(status);
        }
示例#7
0
        protected override Expression VisitConstant(ConstantExpression c)
        {
            RuleDebugger.CheckClosureWarning(c.Type, _expression);

            return(base.VisitConstant(c));
        }