Silverlight CommandBase questions

Silverlight CommandBase questions

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


DanB posted on Thursday, July 29, 2010

First, I'm getting an error:

"Attempt by method 'Csla.Core.FieldManager.FieldDataManager.ForceStaticFieldInit(System.Type)' to access field 'BLayer.Email.ToggleReadFlagCommand.FolderNameProperty' failed."

Yes, I have my backing fields as public static readonly.  What else would cause that?

 

Secondly, the Rolodex sample is using a command for an async business rule.  I'm trying to make one for an actual simple separate thing - updating a value in the database.  So I'm guessing much of the AsyncValidationRuleContext code is not applicable.  I also don't really need a result back other than to know if there was an exception.

So, my command class is pretty simple.  The fields/properties, constructor to pass them in, and the DataPortal_Execute method.

The code using it looks like this:

public void SetFlagBegin(bool newValue, Action<Exception> callback)
{
   MyCommand command = new MyCommand( // set properties)
   DataPortal<MyCommand> dp = new DataPortal<MyCommand>();
   dp.ExecuteCompleted += (o,e) =>
   {
      if (e.Error != null)
         { callback(e.Error); }
      else
         { callback(null); }
   };
   dp.BeginExecute(command)

Does that look right?

 

RockfordLhotka replied on Thursday, July 29, 2010

Is it possible that the business object type itself isn't public? Silverlight reflection can only work on public elements - public types, public members, etc.

I don't see a problem with SetFlagBegin(), though if this is inside some other business object (and I suspect it is) then you might want to mark the object as busy/idle so it is possible for the UI (or other code) to know that something is going on.

DanB replied on Friday, July 30, 2010

Palm-forehead slap of the day.  My command class wasn't marked public.  Doh!  (Big clue was when I removed all the properties and then it failed in the ctor.)

Thanks for the heads up on MarkBusy/MarkIdle.  My hopes that would bubble up through the ViewModel to my BusyIndicator were confirmed.  Excellent!

Copyright (c) Marimer LLC