Application Server
.NET Application-server is a program that manages your business applications, native workflow/business processes, jobs and performs the “magic” of converting .Net Console Application into native workflow that can be run on it.
Like IIS, the application-server is responsible for running your business processes,native workflows, jobs and services. Provides uniform methods for communication, logging, debugging and managing the entire system. It allows you to run business processes on different server nodes (on different physical machines).
Getting started - step by step - creating a business native workflow
.Net Native workflow is similar to .Net Console Application but has two differences:
.Net Virtual Machine is used in the background - to hibernate the entire process while it's waiting - and save it to storage as a hard disk. Once exterlnal trigger received (user interaction, timers ...), the process can be loaded from storage into the virtual machine and restored. Hibernated process can be restored on any another machine.
Below is an example process with three steps. 1) View and get user data. 2) Put the process to sleep for 2 years. 3) Send an email to the address provided earlier.
View from the process - step 1:
Code for the sample native workflow process:
public class SimpleTestProcess : BaseProcess
{
protected override object Start(object inputParameter)
{
//prepare model to show in MVC frontend
var model = new HelloWorlsModel(); //code below
model.MessageToTheWorld = "Hello World";
model.AnotherMessage = "Message from process";
model.DateTimeFromProcess = DateTime.Now;
//show MVC view HelloWorldView with model
var response = ShowForm("HelloWorldView", model); //we show form and waiting for user to submit form
//after user submit form, save to property user data
UserEmail = response.UserEmail;
UserMessage = response.MessageFromUser;
//go to deep sleep - 2 years
Sleep(TimeSpan.FromDays(365 * 2));
//after wakeup if it's Sunday
if ( DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
{
//go to sleep for a day
Sleep(TimeSpan.FromDays(1));
}
//after 2 year sleeping, send email to user with notification
sendEmail();
//end process
return null;
}
private void sendEmail()
{
Log($"Sending email to user {UserEmail}, {UserMessage}");
//you should do real sending ...
//var emailService = new EmailService();
//emialService.SendEmail(UserEmail,UserMessage);
}
#region Process properties
public string UserEmail { get; set; }
public string UserMessage { get; set; }
#endregion
}
public class HelloWorlsModel
{
public string MessageToTheWorld { get; set; }
public string AnotherMessage { get; set; }
public DateTime DateTimeFromProcess { get; set; }
public string UserEmail { get; set; }
public string MessageFromUser { get; set; }
}
Blazor page - HelloWordView - view for step 1
<div class="row">
<div class="col-lg-8 mx-auto">
<h1 class="pt-5 pb-3">Hello World View</h1>
<p>
@Model.MessageToTheWorld
Message from process: @Model.AnotherMessage at @Model.DateTimeFromProcess
</p>
<EditForm Model="@Model" OnValidSubmit="@OnSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<div class="form-group mt-5">
<h3>User data form</h3>
</div>
<div class="form-group">
<label asp-for="Model.UserEmail" class="control-label">Email</label>
<InputText class="form-control" @bind-Value="Model.UserEmail" />
</div>
<div class="form-group">
<label asp-for="Model.MessageFromUser" class="control-label">Message</label>
<InputText class="form-control" @bind-Value="Model.MessageFromUser" />
</div>
<button class="btn btn-primary btn-block mt-2" type="submit"> Confirm </button>
</EditForm>
</div>
</div>
Advantages of Native workflow:
Disadvantages:
Let's assume that we have a customer who wants to get a bank loan. The diagram below provides a general overview of all steps in the process. The steps are performed by the customer and/or the bank's system. This diagram is drawn in the Business Process Model Notation (BPMN - https://en.wikipedia.org/wiki/Business_Process_Model_and_Notation) and starts in the top left blank circle. Actions and steps are represented by a rounded rectangle and performed in the direction of the arrow. So first we have "Registration and approvals ...", then "Send verification code by e-mail ..." and so on. These kinds of diagrams do not show all the details. They are used to show high-level functionality. The BPMN diagram is then "converted" by the developer to the native workflow / business process shown in Diagram 2.
Diagram 1 - BPMN Bank loan process Diagram 2 - Native workflow in C#Code for Registration step:
protected void Registration()
{
SetStepData("Registration", "Get email, phone number and agreements from Custromer");
var registration = getRegistrationStepModel();
var registrationResponse = ShowForm("Registration", registration);
SetStepData("Registration-response", "Custromer put contact data");
Log("check, just in case, whether approved consents");
validateRegistrationStepResponse(registrationResponse);
SetStepData("Registration-approve", "Custromer approve consents");
Log("Save the Customer selections");
SelectedProduct = registrationResponse.SelectedProduct;
ClientEmail = registrationResponse.Email;
ClientPhoneNumber = registrationResponse.PhoneNumber;
}
Registration .Net Core Asp.Net MVC - Registration View
PM> Install-Package Cvl.ApplicationServer -Version 0.9.1
NuGet package Cvl.VirtualMachine
PM> Install-Package Cvl.ApplicationServer.Server -Version 0.9.1
NuGet package Cvl.VirtualMachine.Server
Getting started - step by step - creating a business native workflow