private void UpdateState() { Popup popup = (Popup)FindName("popup"); if (popup != null) { popup.IsOpen = false; } BusinessBase businessObject = Source as BusinessBase; if (businessObject != null) { // for some reason Linq does not work against BrokenRulesCollection... List <BrokenRule> allRules = new List <BrokenRule>(); foreach (var r in businessObject.BrokenRulesCollection) { if (r.Property == Property) { allRules.Add(r); } } var removeRules = (from r in BrokenRules where !allRules.Contains(r) select r).ToArray(); var addRules = (from r in allRules where !BrokenRules.Contains(r) select r).ToArray(); foreach (var rule in removeRules) { BrokenRules.Remove(rule); } foreach (var rule in addRules) { BrokenRules.Add(rule); } BrokenRule worst = (from r in BrokenRules orderby r.Severity select r).FirstOrDefault(); if (worst != null) { _worst = worst.Severity; } _isValid = BrokenRules.Count == 0; GoToState(true); } else { BrokenRules.Clear(); _isValid = true; GoToState(true); } }
/// <summary> /// Updates the state on control Property. /// </summary> protected virtual void UpdateState() { if (_loading) { return; } Popup popup = (Popup)FindChild(this, "popup"); if (popup != null) { popup.IsOpen = false; } if (Source == null || string.IsNullOrEmpty(PropertyName)) { BrokenRules.Clear(); RuleDescription = string.Empty; IsValid = true; CanWrite = false; CanRead = false; } else { var iarw = Source as Csla.Security.IAuthorizeReadWrite; if (iarw != null) { CanWrite = iarw.CanWriteProperty(PropertyName); CanRead = iarw.CanReadProperty(PropertyName); } BusinessBase businessObject = Source as BusinessBase; if (businessObject != null) { var allRules = (from r in businessObject.BrokenRulesCollection where r.Property == PropertyName select r).ToArray(); var removeRules = (from r in BrokenRules where !allRules.Contains(r) select r).ToArray(); var addRules = (from r in allRules where !BrokenRules.Contains(r) select r).ToArray(); foreach (var rule in removeRules) { BrokenRules.Remove(rule); } foreach (var rule in addRules) { BrokenRules.Add(rule); } IsValid = BrokenRules.Count == 0; if (!IsValid) { BrokenRule worst = (from r in BrokenRules orderby r.Severity select r).FirstOrDefault(); if (worst != null) { RuleSeverity = worst.Severity; RuleDescription = worst.Description; } else { RuleDescription = string.Empty; } } else { RuleDescription = string.Empty; } } else { BrokenRules.Clear(); RuleDescription = string.Empty; IsValid = true; } } GoToState(true); }