Implementing the DashboardFacade ASP.NET

Dash board Facade provides a single entry point to the entire business layer.It provides easy-to-call methods that run work flows.For example, the NewUserVisit function executes the New User Setup Work flow (see Example).

DashboardFacade.NewUserVisit calls NewUserSetupWorkflow and creates a complete setup for a new user on the first visit

Here the input parameter to the workflow is User Name. Although the User Page Setup object is passed as if it was an input parameter,it’s not an input.You are passing a null object,which the workflow will populate with loaded data.It’s like an out parameter in function calls.The workflow will populate this parameter’s value once it completes the execution.

Other methods, like Load Use rSet up, Delete Wid get Instance, and Move Wid get Instance,behave the same way.They take necessary parameters as input and pass them to their own workflows,e.g., the MoveWidgetInstance function (see Example).

DashboardFacade.MoveWidgetInstance calls MoveWidgetInstanceWorkflow to move a widget from one position to another

However,getting a return object from a workflow is quite complicated.The Add Wid get function in the façade needs to get the newly added widget instance out of the workflow (see Example).

DashboardFacade.AddWidget function calls AddWidgetWorkflow to add a new widget for the user’s current page

DashboardFacade.AddWidget function calls AddWidgetWorkflow to add a new widget for the user’s current page (continued)

A null object is being passed here to the NeWiget property of the work flow: Add Wid get Work flow,which will populate this property with a new instance of Widget when it completes.Once the workflow completes,the object can be taken from the dictionary.

Implementing the WorkflowHelper Class

Work flow Helper is a handy class that makes implementing a work flow a breeze, especially when used with ASP. NET. In the business layer, the workflow needs to be synchronously executed, but the default implementation of WF is to work asynchronously. Also, you need return values from workflows after their execution is complete, which is not so easily supported due to the asynchronous nature of the workflow.Both of these tasks require some tweaking with the workflow run time to successfully run in the ASP.NET environment.

The Work flow Helper.Init function initializes work flow runtime for the ASP.NET environment.It makes sure there’s only one workflow run time per application domain.Work flow run time cannot be created twice in the same application domain,so it stores the reference of the workflow runtime in the application context.Example shows its partial code.

WorkflowHelper.Init, part 1

The initialization takes care of both ASP.NET and the Console/Winforms mode.You will need the Console/Winforms mode when you test the work flows from a console application or from unit tests. After the initialization,it registers Manual Work flow Scheduler Service, which takes care of synchronous execution of the work flow.Call Work flow activity, which is explained in New User Set up Workflow, uses the Activities.Call Work flow Service to run another workflow synchronously within a workflow.These two services make WF usable from the ASP.NET environment(see Example).

  1. Executes the workflow synchronously
  2. Passes parameters to the workflow
  3. Gets output parameters from the workflow and returns them
  4. Handles exceptions raised in the workflow and passes to the ASP.NET exception handler

In the first step,Execute Work flow creates an instance of workflow and passes input parameters to it as shown in Example

ExecuteWorkflow function takes care of initializing workflow runtime and preparing a workflow for execution

Then Manual Work flow Scheduler Service service executes the work flow synchronously.Next, hook the work flow run time’s Work flow Completed and Work flow Terminated events to capture output parameters and exceptions and handle them properly, as shown in Example

Handle the work flow completion event to capture the output parameters from the workflow instance

When the work flow completes,Work flow Completed Event Args produces the Out put Parameters dictionary, which contains all of the workflow’s public properties. Next, read all of the entries in OutputParameters and update the Input Parameters dictionary with the new values.This is required in the AddWidget function of Dash board Facade, where you need to know the widget instance created by the workflow.

Work flow Terminated fires when there’s an exception.When any activity inside the workflow raises an exception, this event fires and the work flow execution aborts.This exception is captured and thrown again so ASP.NET can trap it using its default exception handler, as shown in Example

Handle exceptions raised by the workflow runtime to find out whether there are any exceptions in a particular execution of a workflow instance

This helps show exceptions in the ASP .NET exception handler.Exceptions thrown from work flow instances are captured and rethrown. As a result,they jump up to the ASP.NET exception handler,and you see the “yellow page of death” on your local computer (see Figure).

Handling exceptions in the workflow and escalating them so that they propagate to ASP.NET’s exception handler

Handling exceptions in the workflow and escalating them so that they propagate to ASP.NET’s exception handler

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

ASP.NET Topics