Factory Command object failing in e-book sample

Factory Command object failing in e-book sample

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


blc303 posted on Friday, December 09, 2011

Hi,

I'm getting back into CLSA after a long pause (last used 2.0). I was working through the samples from the e-book and noticed that the PersonsUpdater file was missing in the FactoryImplementation from the DataAccess book.

I tried to recreate it, but the tests are still failing.

Here is my implementation.

namespace Library
{
  [Csla.Server.ObjectFactory("PersonDal")]
  [Serializable]
  public class PersonsUpdater : CommandBase<PersonsUpdater>
  {
    public static readonly PropertyInfo<PersonEdit> Person1Property = RegisterProperty<PersonEdit>(c => c.Person1);
    public PersonEdit Person1
    {
      get { return ReadProperty(Person1Property); }
      private set { LoadProperty(Person1Property, value); }
    }

    public static readonly PropertyInfo<PersonEdit> Person2Property = RegisterProperty<PersonEdit>(c => c.Person2);
    public PersonEdit Person2
    {
      get { return ReadProperty(Person2Property); }
      private set { LoadProperty(Person2Property, value); }
    }

    public static void Update(PersonEdit person1, PersonEdit person2, EventHandler<DataPortalResult<PersonsUpdater>> callback)
    {
      var cmd = new PersonsUpdater { Person1 = person1, Person2 = person2 };
      DataPortal.BeginExecute<PersonsUpdater>(cmd, callback);
    }

#if !SILVERLIGHT
    public static PersonsUpdater Update(PersonEdit person1, PersonEdit person2)
    {
      var cmd = new PersonsUpdater { Person1 = person1, Person2 = person2 };
      return DataPortal.Execute<PersonsUpdater>(cmd);
    }
#endif
  }
}

The test is failing with the following exception

Test method Test.Library.Net.PersonsUpdaterTest.PersonsUpdaterUpdateTest threw exception:
Csla.DataPortalException: DataPortal.Update failed (System.ArgumentException: Target object must implement IManageProperties
   at Csla.Server.ObjectFactory.LoadProperty[P](Object obj, PropertyInfo`1 propertyInfo, P newValue)
   at DataAccess.SqlCe.PersonDal.Execute(PersonsUpdater obj) in C:\Programme\Marimer LLC\CSLA .NET\Books\Using CSLA\Samples\03-DataAccess-110311\03-DataAccess-110311\FactoryImplementation\DataAccess.SqlCe\PersonDal.cs:line 186
   at lambda_method(Closure , Object , Object[] )
   at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Boolean hasParameters, Object[] parameters)) ---> Csla.Reflection.CallMethodException: Execute method call failed ---> System.ArgumentException: Target object must implement IManageProperties

What am I missing?

Thanks

Ben

 

JonnyBee replied on Friday, December 09, 2011

It's a known issue that CommandBase does not implement IManageProperties (yet).

http://www.lhotka.net/cslabugs/edit_bug.aspx?id=890

blc303 replied on Friday, December 09, 2011

Thank you. I'll look into what that is going to take.

 

blc303 replied on Friday, December 09, 2011

So as I see it, it looks a little like trying to find the lesser of two evils.

You can do a copy and paste implementation of the BusinessBase implemenation with a couple of 'tweeks'. First you are not doing any BusinessRule or Authorisation checks. Argueably, that's OK, because the CommandBase is, by definition, controlled by the CanExecute authorisation.

Thus, here the implentation in the hope that it gets into the next release.

    #region IManageProperties Members

    bool IManageProperties.HasManagedProperties
    {
        get { return (FieldManager != null && FieldManager.HasFields); }
    }

    List<IPropertyInfo> IManageProperties.GetManagedProperties()
    {
        return FieldManager.GetRegisteredProperties();
    }

    object IManageProperties.GetProperty(IPropertyInfo propertyInfo)
    {
        return ReadProperty(propertyInfo);
    }

    object IManageProperties.ReadProperty(IPropertyInfo propertyInfo)
    {
        return ReadProperty(propertyInfo);
    }

    P IManageProperties.ReadProperty<P>(PropertyInfo<P> propertyInfo)
    {
        return ReadProperty<P>(propertyInfo);
    }

    void IManageProperties.SetProperty(IPropertyInfo propertyInfo, object newValue)
    {
        FieldManager.SetFieldData(propertyInfo, newValue);
    }

    void IManageProperties.LoadProperty(IPropertyInfo propertyInfo, object newValue)
    {
        LoadProperty(propertyInfo, newValue);
    }

    List<object> IManageProperties.GetChildren()
    {
        return FieldManager.GetChildren();
    }
    #endregion

 

Differences are bolded.

Have a nice day.

blc303 replied on Friday, December 09, 2011

Sorry, forgot two Interfaces

 

    bool IManageProperties.FieldExists(Core.IPropertyInfo property)
    {
        return FieldManager.FieldExists(property);
    }

   P IManageProperties.ReadProperty<P>(PropertyInfo<P> propertyInfo)
    {
        return ReadProperty<P>(propertyInfo);
    }

JonnyBee replied on Friday, December 09, 2011

Thanks, 

issue 890 is now checked in to repository and will be included with Csla 4.3.

 

cwinkelmann replied on Tuesday, November 04, 2014

Did this ever get fixed? I re-downloaded the v1.0 source file/examples and the file is still missing. So to use the example you have to implement this solution?

 

JonnyBee replied on Tuesday, November 04, 2014

Which version of CSLA did you download? 

CommandBase does implement managed properties from CSLA 4.3 and later.

Copyright (c) Marimer LLC