I've got the following Async business rule:
Private Class ServerFileNameExistsRule
Inherits Csla.Rules.BusinessRule
Public Shared CurrentP2FFileKeyProperty As Csla.Core.IPropertyInfo
Public Sub New(ByVal primarypropertyServerFileName As Csla.Core.IPropertyInfo, ByVal propertyCurrentP2FFileKey As Csla.Core.IPropertyInfo)
MyBase.New(primarypropertyServerFileName)
IsAsync = (ApplicationContext.ExecutionLocation <> ExecutionLocations.Server)
Priority = 1
CurrentP2FFileKeyProperty = propertyCurrentP2FFileKey
InputProperties = New List(Of Csla.Core.IPropertyInfo)
InputProperties.Add(PrimaryProperty)
InputProperties.Add(CurrentP2FFileKeyProperty)
End Sub
Protected Overrides Sub Execute(ByVal context As Csla.Rules.RuleContext)
MyBase.Execute(context) 'Not sure this is necessary
Dim command As New cmdP2FFileServerFileNameExists(context.InputPropertyValues(PrimaryProperty))
Dim dp As DataPortal(Of cmdP2FFileServerFileNameExists) = New DataPortal(Of cmdP2FFileServerFileNameExists)()
AddHandler dp.ExecuteCompleted, AddressOf ServerFileNameExistsCompleted
dp.BeginExecute(command, context)
End Sub
Private Shared Sub ServerFileNameExistsCompleted(ByVal sender As Object, ByVal e As DataPortalResult(Of cmdP2FFileServerFileNameExists))
Dim context As Csla.Rules.RuleContext = CType(e.UserState, Csla.Rules.RuleContext)
If e.Error IsNot Nothing Then
context.AddErrorResult("Error checking for duplicate ServerFileName" & e.Error.ToString())
Else
If e.Object.ExistsKey > 0 And context.InputPropertyValues(CurrentP2FFileKeyProperty) <> e.Object.ExistsKey Then
context.AddErrorResult("This ServerFileName is already in use!")
End If
End If
context.Complete()
End Sub
End Class
Once the rule completes the ServerFileName property is still flagged as Busy and I am unable to save the business object. Note that context.Complete is called ...
Anyone else encountering this issue?
Thanks!
- Greg
Hi Greg,
Your rule only does async validation!!
The Execute method MUST test for IsAsync and implement both sync and async handling.
IE: Serverside must make a sync dataportal call and client side do an async.
That said, it doesn't explain why the property is still busy.
Did you debug and make sure that the callback is actually called. You may get unexpected
handling on Exceptions that are not serializable from the serverside like IO Exceptions.
That is assuming that your platform is .NET.
Copyright (c) Marimer LLC