usefull class idea: strong typing DataFields access in your client code

  • 5 April 2009
  • 2 replies
  • 5 views

Badge +3
I'm playing with client API and find working with DataFields for read or write access a pain because of all the string involved in the process.

Facing this kind of issue, I always involve a DictionaryAdapter component (found in the Castle Project) and define dumb interfaces that serves as proxy to theses manipulations, for example this work great as an ASP.NET Session wrapper, in fact with any object implementing IDictionary or NameValueCollection.

To give an example, I use the TrainingRequest.aspx example from Denallix solution

initially you would have this:

                //Set DataField values
                k2ProcInst.DataFields["TrainingReqID"].Value = theRequestID;
                k2ProcInst.DataFields["EmployeeID"].Value = theEmployeeID;
                k2ProcInst.DataFields["TrainingEndDate"].Value = theEndDate;

with the wrapper you would have:

                public interface ITrainingRequestForm {
                  int TrainingReqID {get;set;}
                  string EmployeeID {get;set;}
                  DateTime TrainingEndDate {get;set;}
                }

and (I'm using c# 3 extension method here)

                var form = k2ProcInst.DataFields.GetAdapter<ITrainingRequestForm>();
                form.TrainingReqID =  theRequestID;
                form.EmployeeID = theEmployeeID;
                form.TrainingEndDate =  theEndDate;

the same thing also work to retrieve your data without casting away every bits :)

If that make sense to anyone else, I would be happy to share this library on blackmarket under opensource licence, I'm also looking to make this available for other loosely typed dictionary that are present in the client API (SmartObjects, etc.)

2 replies

Badge +9
You should be able to request for a site on blackmarket.  Once the admin approves it, you will be able to upload your code to it.
Badge +3

I just set up a googlecode project with an initial implementation:

http://code.google.com/p/smoothdev-k2-blackpearl/ 

feedback is welcome, I'm looking forward to put theses bits on blackmarket with some more explanation  

 

Reply