Writing the Application Layer

The application layer should implement the client user interface, providing the required functionality to the end user.

This layer should be largely independent of the BPM API, as it can call adapter functions to invoke BPM services to obtain data.

The application layer is provided by the BPMTestApplication project. This project provides the following functionality:

File Description
BPMTestApplication.cs Creates and manages the BPMTestApplication object. This contains the program entry point method, Main, which manages the user’s login and displays their work list.
LoginForm.cs Creates and manages the LoginForm object, which provides the LoginForm dialog.
WorkList.cs Creates and manages the WorkList object, which controls the user’s interaction with the work list.
ViewWorkItem.cs Creates and manages the ViewWorkItem object, which controls the user’s interaction with a specific work item.
FormRedirect.htm Manages the user’s interaction with the form that is displayed when a user opens a specific work item. See Rendering a Form for a Work Item for more information.

The ShowWorkList method (defined in WorkList.cs) illustrates how adapter functions are used to insulate the application layer from the implementation details of the BPM services.

private void ShowWorkList()
{
   workListTable.Enabled = false;
   workListTable.ForeColor = Color.Gray;
   try
   {
      WorkItem[] items = _adapter.GetWorkList(_guid);
      _items = items;
      DataSet dsForDGV = new DataSet();
      BindingSource bs = new BindingSource();
      DataTable dataTable1 = ConvertWorkItemsToDataTable(items);
      dsForDGV.Tables.Add(dataTable1);
      bs.DataSource = dsForDGV;
      bs.DataMember = dsForDGV.Tables[0].TableName;
      workListTable.DataSource = bs;
      workListTable.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
   }
   catch (Exception ex)
   {
      MessageBox.Show(this,"Error getting work list: "+ex.Message,"Error");
   }
   workListTable.Enabled = true;
   workListTable.ForeColor = Color.Black;
}

ShowWorkList is called by the Main method when a user has successfully logged in.

  • ShowWorkList retrieves the contents of the user’s work list by calling the Adapter.GetWorkList method (which in turn calls the getWorkListItems operation provided by the WorkListService).
  • The response, stored in items, is a getWorkListItemsResponse object, which contains full details of all the work items in the work list.
  • ShowWorkList presents the data using a .NET dataTable. The ConvertWorkItemsToDataTable method is used to filter and convert the data returned in the getWorkListItemsResponse object into a dataTable object containing just the data to be displayed in the work list.
    private DataTable ConvertWorkItemsToDataTable(WorkItem[] items)
    {
       dataTable dataTable1 = new DataTable("MyTable");
       dataTable1.Columns.Add(new DataColumn("Work Item ID"));
       dataTable1.Columns.Add(new DataColumn("State"));
       dataTable1.Columns.Add(new DataColumn("Name"));
       dataTable1.Columns.Add(new DataColumn("Description"));
       dataTable1.Columns.Add(new DataColumn("Process Template"));
       dataTable1.Columns.Add(new DataColumn("Work Item Priority"));
       dataTable1.Columns.Add(new DataColumn("Attribute 2"));
       int i = 0;
       foreach (WorkItem item in items)
       {
          dataTable1.Rows.Add(item.id);
          dataTable1.Rows[i][0] = item.id.id;
          dataTable1.Rows[i][1] = item.state;
          dataTable1.Rows[i][2] = item.header.name;
          dataTable1.Rows[i][3] = item.header.description;
          dataTable1.Rows[i][4] = item.header.itemContext.appName;
          dataTable1.Rows[i][5] = item.header.priority;
          if ((item.attributes != null) && (item.attributes.attribute2 != null))
          {
             dataTable1.Rows[i][6] = item.attributes.attribute2;
          }
          else
          {
             dataTable1.Rows[i][6] = "";
          }
          i++;
       }
       return dataTable1;
    }