Esempio n. 1
0
 private void CollectBrokenRules(BrokenRulesNode node)
 {
     if (node != null && node.BrokenRules != null)
     {
         foreach (BrokenRule rule in node.BrokenRules)
         {
             _brokenRules.Add(rule, node.Object);
         }
     }
 }
Esempio n. 2
0
        private static void AddNodeToBrukenRules(ref BrokenRulesTree list, ref long counter, object parentKey, object obj, bool errorsOnly, ref long childBrokenRuleCount)
        {
            // is this a single editable object
            if (obj is Csla.Core.BusinessBase)
            {
                var  nodeKey = counter++;
                var  bo      = (Csla.Core.BusinessBase)obj;
                long myChildBrokenRuleCount = bo.BrokenRulesCollection.Count;
                var  node = new BrokenRulesNode()
                {
                    Parent = parentKey, Node = nodeKey, BrokenRules = bo.BrokenRulesCollection, Object = obj
                };
                list.Add(node);

                // get managed child properties
                foreach (var child in ((IManageProperties)bo).GetChildren())
                {
                    AddNodeToBrukenRules(ref list, ref counter, nodeKey, child, errorsOnly, ref myChildBrokenRuleCount);
                }

                // remove node if it has no child with broken rules.
                if (!errorsOnly && myChildBrokenRuleCount == 0)
                {
                    list.Remove(node);
                }
                if (errorsOnly && bo.IsValid)
                {
                    list.Remove(node);
                }
                childBrokenRuleCount += myChildBrokenRuleCount;
            }

            // or a list of EditableObject (both BindingList and ObservableCollection)
            else if (obj is IEditableCollection)
            {
                var nodeKey = counter++;
                var isValid = ((ITrackStatus)obj).IsValid;
                var node    = new BrokenRulesNode()
                {
                    Parent = parentKey, Node = nodeKey, Object = obj, BrokenRules = new BrokenRulesCollection(true)
                };
                long myChildBrokenRuleCount = 0;

                list.Add(node);

                foreach (var child in (IEnumerable)obj)
                {
                    AddNodeToBrukenRules(ref list, ref counter, nodeKey, child, errorsOnly, ref myChildBrokenRuleCount);
                }

                // remove node if it has no child with broken rules.
                if (!errorsOnly && myChildBrokenRuleCount == 0)
                {
                    list.Remove(node);
                }
                if (errorsOnly && isValid)
                {
                    list.Remove(node);
                }
                childBrokenRuleCount += myChildBrokenRuleCount;
            }
            return;
        }
Esempio n. 3
0
    private static void AddNodeToBrukenRules(ref BrokenRulesTree list, ref long counter, object parentKey, object obj, bool errorsOnly, ref long childBrokenRuleCount)
    {
      // is this a single editable object 
      if (obj is Csla.Core.BusinessBase)
      {
        var nodeKey = counter++;
        var bo = (Csla.Core.BusinessBase)obj;
        long myChildBrokenRuleCount = bo.BrokenRulesCollection.Count;
        var node = new BrokenRulesNode() { Parent = parentKey, Node = nodeKey, BrokenRules = bo.BrokenRulesCollection, Object = obj };
        list.Add(node);

        // get managed child properties 
        foreach (var child in ((IManageProperties)bo).GetChildren())
        {
          AddNodeToBrukenRules(ref list, ref counter, nodeKey, child, errorsOnly, ref myChildBrokenRuleCount);
        }

        // remove node if it has no child with broken rules. 
        if (!errorsOnly && myChildBrokenRuleCount == 0)
        {
          list.Remove(node);
        }
        if (errorsOnly && bo.IsValid)
        {
          list.Remove(node);
        }
        childBrokenRuleCount += myChildBrokenRuleCount;
      }

      // or a list of EditableObject (both BindingList and ObservableCollection)
      else if (obj is IEditableCollection)
      {
        var nodeKey = counter++;
        var isValid = ((ITrackStatus)obj).IsValid;
        var node = new BrokenRulesNode() { Parent = parentKey, Node = nodeKey, Object = obj };
        long myChildBrokenRuleCount = 0;

        list.Add(node);

        foreach (var child in (IEnumerable)obj)
        {
          AddNodeToBrukenRules(ref list, ref counter, nodeKey, child, errorsOnly, ref myChildBrokenRuleCount);
        }

        // remove node if it has no child with broken rules. 
        if (!errorsOnly && myChildBrokenRuleCount == 0)
        {
          list.Remove(node);
        }
        if (errorsOnly && isValid)
        {
          list.Remove(node);
        }
        childBrokenRuleCount += myChildBrokenRuleCount;
      }
      return;
    }