I’m experimenting with WP7 and using a ReadOnlyListBase with the factory methods. Does this work on the WP7 Platform? I keep getting an ArgumentException when the factory method is called. This may be a silly question, I apologize, I’m new to 4.1 and have not been using CSLA since the .Net 2.0 versions.
I have read the books and look through all the examples I could find. If someone has a good example or could direct me to a posting, it would be much appreciated. I'm looking forward to the WP7 book, I hope a draft version is on it's way this fall.
Regards,
Andrew
In WP7 running in local mode the factory methods get a Callback function as last parameter. I believe that is missing in your code and hence you get an ArgumentException.
If you look at the WindowsPhone\cs\SimpleApp in Csla samples download you can add a CustomerFactory like this:
Add object factory attribute to CustomerEdit
[ObjectFactory(typeof(CustomerEditFactory))] public class CustomerEdit : BusinessBase<CustomerEdit>
And add this class
public class CustomerEditFactory : Csla.Server.ObjectFactory { public void Create(Csla.DataPortalClient.FactoryProxy<Library.CustomerEdit>.CompletedHandler callback) { try { var obj = (CustomerEdit)Activator.CreateInstance(typeof(CustomerEdit)); using (BypassPropertyChecks(obj)) obj.Status = "Created " + ApplicationContext.ExecutionLocation.ToString(); MarkNew(obj); callback.Invoke(obj, null); } catch (Exception ex) { callback.Invoke(null, ex); } } public void Fetch(SingleCriteria<CustomerEdit, int> criteria,
Csla.DataPortalClient.FactoryProxy<Library.CustomerEdit>.CompletedHandler callback) { try { var obj = (CustomerEdit)Activator.CreateInstance(typeof(CustomerEdit)); using (BypassPropertyChecks(obj)) { obj.Id = criteria.Value; obj.Name = "Test " + criteria.Value; obj.Status = "Retrieved " + ApplicationContext.ExecutionLocation.ToString(); } MarkOld(obj); callback.Invoke(obj, null); } catch (Exception ex) { callback.Invoke(null, ex); } } public void Update(CustomerEdit obj,
Csla.DataPortalClient.FactoryProxy<Library.CustomerEdit>.CompletedHandler callback) { try { // call something to save the object MarkOld(obj); callback.Invoke(obj, null); } catch (Exception ex) { callback.Invoke(null, ex); } } }
That clears things up. The world has changed in the last 5 years! Thank you very much.
Andrew
Copyright (c) Marimer LLC