IsAsync acting weird

IsAsync acting weird

Old forum URL: forums.lhotka.net/forums/t/10147.aspx


hanspret posted on Wednesday, March 09, 2011

Hi

I've got an Async rule that checks the database for an existing item. I use IsAsync in this rule but realised somethings going weird when I use this.

In my view I've got an undo button. The IsEnabled is bind to CanCancel (I am usind bxf).  When I add the rule with the IsAsync in it to the AddBusinessRules method and I run the application and I create a new item on the view mentioned above, the Undo button is disabled as expected. When I edit the field that is linked to the Async rule, and I tab of it the Undo button is enabled and I can click it and undo happens as expected. If I edit a different field that is not linked to the Async rule and tab of it, the undo button will not enable. This means that CanCancel stays false.

Lets say I remove the rule completely. When I run the application and create a new item on the view the undo button is enabled from the beginning. I can click it and it will stay enabled.

It is if I am missing something. It feels almost like I should mark all the properties with a similar IsAsync

Here is the rule:

 

 

private class BarcodeExistRule : Csla.Rules.BusinessRule

{

 

 

private Csla.Core.IPropertyInfo _PrimaryProperty;

 

 

public BarcodeExistRule(Csla.Core.IPropertyInfo PrimaryProperty)

:

 

base(PrimaryProperty)

{

IsAsync =

 

true;

_PrimaryProperty = PrimaryProperty;

InputProperties =

 

new List<Csla.Core.IPropertyInfo> { PrimaryProperty };

}

 

 

protected override void Execute(Csla.Rules.RuleContext context)

{

 

 

var dp = new DataPortal<ExistsCommand>();

dp.ExecuteCompleted += (o, e) =>

{

 

 

if (e.Error != null)

{

context.AddErrorResult(e.Error.Message);

}

 

 

else

{

 

 

if (e.Object.AssetCodeExists)

{

context.AddErrorResult(

 

"This barcode already exists");

}

context.Complete();

};

};

dp.BeginExecute(

 

new ExistsCommand(context.InputPropertyValues[PrimaryProperty]));

}

}

 

If any one has some input it will be appreciated. I am using Silverlight

Copyright (c) Marimer LLC