Today I want to show how we can use “Enterprise Architect” and the LieberLieber “Amuse” Plug-In to integrate “ASP.NET Mvc Web Application” into a flowchart.

Here you can see the final solution.
[mediaplayer src=’/wp-content/uploads/AmuseMvcExample.wmv’ autoLoad=1 autoPlay=1]

To download the video click here.

If you haven’t seen my previous posts please check out “LieberLieber AMUSE – Using Statemachines to Build Winforms flows” and “LieberLieber AMUSE – Using Statemachines and ASP.NET WebServices”.

Ok, first of all have a look at the Asp.net Mvc Solution.

clip_image001

As you can see I added an AuthenticationController (provides the controller methods), AuthenticationService (provides the authentication logic) and AuthenticationViewModel (provides the view model for the web form) to the solution.

The authentication workflow looks similar like in my first example.

clip_image002

First we want to show the login form (ValidateUser.aspx) which provides username and password.

clip_image004

If the user enters the wrong username and password we want to show him the access denied form (AccessDenied.aspx).

clip_image006

If the authentication succeeds we want to show the user the succeed form (LoginSuccessful.aspx).

clip_image008

In “Enterprise Architect” I created 4 “Packages” and loaded the necessary source files to have a good overview of the Asp.net Mvc solution.
clip_image009

1. “AmuseMvc” which holds the “StateMachine”.
clip_image010

2. “Controllers” which contains the Asp.net Mvc controllers.
clip_image011

3. “Models” which contains the Asp.net Mvc view models and authentication service.
clip_image012

4. “Views” which contains the Asp.net Mvc views.
clip_image013

If you want to use your “Asp.net Mvc Web Application” in Amuse you have to build it and load it under “External References” at the “State Machine” diagram.

1. “Add-Ins” – “Amuse” – “External Reference”.

2. Now select your Asp.net Mvc library. In our example “AmuseMvcExample.dll”.

3. Then import all three “Types” into “Enterprise Architect”:

a. “AmuseMvcExample.Controllers. AuthenticationController”

b. “AmuseMvcExample.Models. AuthenticationViewModel”

c. “AmuseMvcExample.Models. AuthenticationService”

But hold on, one important reference is missing. Maybe you remember my last post
LieberLieber AMUSE – Using Statemachines and ASP.NET WebServices” where we used the
“ASP.NET Development Server” and had to use a batch file to start the “ASP.NET Web Development Server”? To avoid this and make it more confortable I created a “WebDevServer” class which provides the necessary functionality (for example: Start, Stop and RedirectToAction). You can find this in the “AmuseMvc.dll”
So add also “AmuseMvc. WebDevServer” to the “StateMachine” diagram.

After we loaded all the external references, your “Project Browser” should look like in the following screenshot:

clip_image014

Ok now I declared the attributes.

Name: “ValidUser”
Type: “bool”
Scope: “Public”
Initial: “false”

Name: “MyAuthenticationViewModel”
Type: “AuthenticationViewModel”
Scope: “Public”

Name: “MyAuthenticationService”
Type: “AuthenticationService”
Scope: “Public”
Initial: “new AuthenticationService()”

Name: “MyAuthenticationController”
Type: “AuthenticationController”
Scope: “Public”
Initial: “new AuthenticationController ()”

Name: “MyWebDevServer”
Type: “WebDevServer”
Scope: “Public”
Initial: “new WebDevServer(“C:\YourProjectPath“)

–> The WebDevServer needs the path to the “Asp.net Mvc Web Application” (without last backslash)!

Now we create the operations:

Name: “StartWebDevServer”
Return Type: “void”
Behavior – Initial Code: “MyWebDevServer.Start();”

Name: “StopWebDevServer”
Return Type: “void”
Behavior – Initial Code: “MyWebDevServer.Stop();”

Name: “OpenLoginForm”
Return Type: “void”
Behavior – Initial Code:
“MyAuthenticationViewModel =
(AuthenticationViewModel) MyDevServer.GetViewModelFromAction(“Authentication”, “ValidateUser”,typeof (AuthenticationViewModel))

–> This operation redirects to the action and get the entered values back.

Name: “ValidateUser”
Return Type: “void”
Behavior – Initial Code: “ValidUser = MyAuthenticationService.ValidateUser(
MyAuthenticationViewModel.UserName,MyAuthenticationViewModel.Password);”

–> This operation validates against our “AuthenticationService” and set the “ValidUser” attribute.

Name: “OpenAccessDeniedForm”
Return Type: “void”
Behavior – Initial Code: “MyDevServer.RedirectToAction(“Authentication”,”AccessDenied”);”

–> This operation opens the access denied form and we don’t need any return value.

Name: “OpenAccessDeniedForm”
Return Type: “void”
Behavior – Initial Code: “MyDevServer.RedirectToAction(“Authentication”,”LoginSuccessful”);”

–> This operation opens the login successful form and we don’t need any return value.

So now we can call the operations in the workflow but first we will add two new “States” for “StartDevServer” and “StopDevServer” like in the following screenshot.

clip_image015

So now we call the operations on the states:

clip_image016

Before we can start the flowchart we have to do two more things.

First import the namespaces in the “AmuseMvc” class.
using AmuseMvcExample.Controllers;
using AmuseMvcExample.Models;
using AmuseMvc;

And second in the “Asp.net Mvc Web Application”, we have to add the “AmuseMvcWeb.dll” which provides the “AmuseHandler “. You have to set up this handler in the web.config.
Add following line to the <httpHandlers> section:

<add verb="*" path="*.amusemvc" type="AmuseMvcWeb.AmuseHandler"/>

And also don’t forget to add following line into the “Global.asax.cs” – “RegisterRoutes” method:

 Public class MvcApplication : System.Web.HttpApplication {
   public static void RegisterRoutes(RouteCollection routes) {
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
     routes.IgnoreRoute("{resource}.amusemvc/{*pathInfo}");

The library also contains the “AmuseAttribute” for the controller classes. So if you want to use the controller in Amuse please mark the controller class with [Amuse]:

In our example over the “AuthenticationController”.

[Amuse]
public class AuthenticationController : Controller {
  private readonly IauthenticationService _authenticationService;
  public AuthenticationController() {
    _authenticationService = new AuthenticationService();
  }

After that we are ready to go and you can start the flowchart!

If you want to try this example please make sure that you change the path for the WebDevServer to the Asp.net Mvc Application first!!

Attribute: MyWebDevServer = new MyWebDevServer(“YOURPATH”);

To pass the validation use:
Username:amuse
Password:mvc

Here is the source code.