Introducing SOA.UI Helpers

Posted Tue Dec 1, 2009 @ 11:44 AM

 

The SOA.UI library has, since its introduction, defined its standard UI-serving services not only in terms of interfaces and DataContracts, but as a set of base classes to be inherited. This approach provides the automatic inheritance of the relevant interface and DataContract, but also allows for more helpful functionality to be built into the base class and leveraged by the end developer. With ComponentArt SOA.UI 2009.3 SP1, released yesterday, we have begun to add some of that functionality.

One of the most common tasks that we ourselves have had to solve when writing our control samples is the standard approach to performing a SoaDataGridService.Select operation in a way that supports paging, sorting and filtering. The approach to doing this was as follows:

public override SoaDataGridSelectResponse Select(SoaDataGridSelectRequest request)
{
  // load all the data into a data set (from database or elsewhere)
  DataSet oDS = LoadData();
  DataView oView = new DataView(oDS.Tables[0]);

  // apply order and filters to view
  oView.Sort = request.Sortings.ToSqlString();
  oView.RowFilter = request.Filters.ToSqlString();

  SoaDataGridSelectResponse response = new SoaDataGridSelectResponse();

  List<List<object>> arItems = new List<List<object>>();

  // chop the requested part of the record set
  for (int i = request.Offset; i < request.Offset + request.Count && i < oView.Count; i++)
  {
    // load data row
    List<object> item = new List<object>();
    foreach (SoaDataGridColumn oColumn in request.Columns)
    {
      item.Add(oView[i][oColumn.Name]);
    }

    arItems.Add(item);
  }

  response.ItemCount = oView.Count;
  response.Data = arItems;

  return response;
}

 

The solution was pretty much always the same in the context of our demos, so it made sense to package it in a way that's usable right out of the box. So, in applications where all the data is accessible to the service in the form of a DataTable, we can now implement SoaDataGridService.Select in just a couple of lines. First, we load the DataSet (or just DataTable), and take a look at what tools we have inherited:

 

The new SelectFromDataTable protected method can be called right away on the DataTable which contains our data, and it performs all the typical processing automatically. Our final Select implementation looks like this:

 

A similar helper method has been added for the Group operation (GroupFromDataTable), to handle the "ConstantGroups" grouping mode via SOA.UI.

Our intention is to introduce helper functionality to SOA.UI base classes in a conservative manner, starting from where the time-saving potential is greatest. The initial buildout, this being a minor service pack release, is modest and highly focused, but we welcome your feedback on the sorts of functionality you'd like to see!

Posted to For the Love of Data by milos

Posted on Tue Dec 1, 2009 @ 11:44 AM

Filed under: ,

Comments

Posted on Tue Dec 1, 2009 @ 11:44 AM

Great, I have been looking for this from day one. While I realize that overall the amount of code stays the same it does make a huge difference in keeping my code clean & lean and easy to support.

I hope you guys can add more of these common scenarios into your packages as the majority of my code is the plain vanilla implementation that you mentioned from working on the CA demos.

Posted on Tue Dec 1, 2009 @ 11:44 AM

Great post! The documentation is not very generous and this kind of articles are welcome. Thank you, Milos!

Anonymous comments are not allowed. Click here to log in or create an account.