the following code is in my buisnesslistbase class which is a collection of my AssignMent object. Basically when the collection that of Assignment objects changes i.e
Protected Overrides Sub OnCollectionChanged(e As System.Collections.Specialized.NotifyCollectionChangedEventArgs) MyBase.OnCollectionChanged(e) If Me.AssignmentCollectionChanged IsNot Nothing Then Me.AssignmentCollectionChanged.Invoke() End If End Sub
I invoke the callback function that checks the rules in the dataportal fetch. of the holder
Me.Assignments.AssignmentCollectionChanged = Sub() Me.BusinessRules.CheckRules()
now this happens intermitently , if the rule is broken the following line is executed :
I have a buisnes s rule that when the rule fails the following function is executed
If returnMessage.Length > 2 Then returnMessage = returnMessage.Substring(0, returnMessage.Length - 1) context.AddErrorResult(returnMessage) End If
Now for some reason the method that does is building the collection does not for always retain the error result when the the following check is run:
For Each assignment In assignmentCollection.Assignments If assignment.BrokenRulesCollection.Count > 0 Then canSave = False For Each assignErr In assignment.BrokenRulesCollection errorMessages.Add(assignErr.Description) Next End If NextSomtimes it works and the broken rules collection does contain the errors raisedany ideas ?
Hi,
1: You should never call BusinessRules.CheckRules() on a background thread. The CheckRules method may raise OnPropertyChanged and you will get cross thread exception when databound to UI (rich client).
2: You should not run async rules on the serverside of the data portal. If deployed in a 3 tier layer your object will be serialized and returned to the client in the middle of rule checking (and possible in an indetermined/invalid state).
3: If deployed in a 3 tier layer or using the AutoCloneOnUpdate (which is on by default) you must reestablish the AssignmentCollectionChanged event in the OnDeserialized event.
4: You could also look at the BusinessRules.GetAllbrokenRules() method that will safely traverse your object structure and return the broken rules.
5: Is your (parent object) rules depending on values from Assignments)? If they are then I'd rather call <bo>.CheckObjectRules() or PropertyHasChanged(propertyInfo) for that specific property. When running in a rich client these 2 methods are the ONLY ones that will notify the UI of changes in property/rules.
I'm not using a rich client thankfully, it is just a jquery html grid application , I did not write the original code, so I am trying to navigate it and figure out what they were doing prior to my arrival.
I have a feeling you are right that the issue is due to where the checkRules is being called from, I am really at a loss here trying to figure out what the contractor was thinking lol.
I am thinking of just prevalidating from the UI instead of having to re-write thier CSLA code.
First I will try the BusinessRules.GetAllbrokenRules() to see if the broken rulues are captured there I guess
I don't think I can use your option 5 becase I do not have a rich client like silverlight.
let me know what you think and thanks
Copyright (c) Marimer LLC