Managed Operations. Getting Started
In this lesson you will learn, how to implement an application method using the Managed Operations service. We will design the SimpleOperation class that exposes the ExecuteCore method. We will implement execution of this method as a Synchronous Managed Operation with a progress bar. The launch of the operation will be initiated using the Simple Action startSimpleOperation. Then we will look at other ways to display a running process. Follow the steps described below.
- Add XafariManagedOperationsModule and XafariManagedOperationsCfgModule to the required project (for instance, to the Module Project). XafariManagedOperationsCfgModule provides a viewing and editing the Managed Operations at runtime. To learn more, refer to the Managed Operations in Application topic.
- Add XafariManagedOperationsWinModule to the Windows Forms Application Project.
- Add XafariManagedOperationsWebModule to the Web Application Project.
- Add a new class to the Module Project, name it SimpleOperation. Replace the automatically generated code with the following code.
- c#
- VB
using System.Threading;
using DevExpress.ExpressApp;
using Xafari.ManagedOperations;
//...
[NonPersistent]
class SimpleOperation
{
public int Count { get; set; }
public int Timeout { get; set; }
public SimpleOperation(XafApplication application)
{
Count = 10;
Timeout = 3;
}
public void ExecuteCore(IManagedOperation operation)
{
operation.TotalStep = Count;
for (int i = 1; i <= Count; i++)
{
operation.NextStep(string.Format("Stage {0}", i), i);
Thread.Sleep(Timeout * 1000);
}
}
}
Imports System.Threading
Imports DevExpress.ExpressApp
Imports Xafari.ManagedOperations
'...
<NonPersistent> _
Friend Class SimpleOperation
Public Property Count As Integer
Public Property Timeout As Integer
Public Sub New(ByVal application As XafApplication)
Count = 10
Timeout = 3
End Sub
Public Sub ExecuteCore(ByVal operation As IManagedOperation)
operation.TotalStep = Count
Dim i As Integer = 1
While i <= Count
operation.NextStep(String.Format("Stage {0}", i), i)
Thread.Sleep(Timeout * 1000)
i += 1
End While
End Sub
End Class
- Add a new View Controller to the Module Project, name it StartManagedOperationViewController.
- Add a new Simple Action to the StartManagedOperationViewController View Controller, name it startSimpleOperation. Use the following code to handle the startSimpleOperation_Execute event:
- c#
- VB
//...
using DevExpress.ExpressApp;
using Xafari.ManagedOperations;
//...
public partial class StartManagedOperationViewController : ViewController
{
//...
private void StartSimpleOperation_Execute(object sender, SimpleActionExecuteEventArgs e)
{
var simpleOperation = new SimpleOperation(this.Application);
var managedOperation = new ManagedOperation(this.Application) { ZoneType = ManagedOperationZoneTypes.Local, Name = "Managed operation with progress bar", ProcessCode = (simpleOperation.ExecuteCore), TotalStep = simpleOperation.Count, TraceLevel = TraceLevel.Verbose };
managedOperation.Start();
SyncManagedOperationHelper.CreateHelper(managedOperation).InitShowViewParametersProgress(e.ShowViewParameters, false);
}
//...
}
'...
Imports DevExpress.ExpressApp
Imports Xafari.ManagedOperations
'...
Public Partial Class StartManagedOperationViewController
Inherits ViewController
'...
Private Sub StartSimpleOperation_Execute(ByVal sender As Object, ByVal e As SimpleActionExecuteEventArgs)
Dim simpleOperation = New SimpleOperation(Me.Application)
Dim managedOperation = New ManagedOperation(Me.Application) With {.ZoneType = ManagedOperationZoneTypes.Local, .Name = "Managed operation with progress bar", .ProcessCode = (simpleOperation.ExecuteCore), .TotalStep = simpleOperation.Count, .TraceLevel = TraceLevel.Verbose}
managedOperation.Start()
SyncManagedOperationHelper.CreateHelper(managedOperation).InitShowViewParametersProgress(e.ShowViewParameters, False)
End Sub
'...
End Class
- It is necessary to ensure user access to the Managed Operations List View. To do this, invoke the Model Editor, navigate to the NavigationItems|Items|Default|Items node, add a new Navigation Item, and set the View property to "ManagedOperationStorage_ListView", as shown in the figure below.
- To see the result, run the WinForms or ASP.NET application.
- Select Operations in the main menu and click the startSimpleOperation action. You can see the launch and execution of the ExecuteCore method under the Managed Operations.
Note:
Select the local type (Local) of the displayed operations in the ManagedOperationStorage_ListView toolbar.
- After termination you can invoke a Detail View of the executed operation and see the log.
Win:
You can view the code used in this topic in the Operation1.cs file and SyncManagedOperationsWindowController.cs file (SyncProgress_Execute method) of the Xafari Northwind demo installed with Xafari.
Note:
In this example, the execution of the Synchronous Managed Operation was displayed in the progress bar. It is also possible to use the infinite scrolling bar or the Detail View of the executed operation. The respective examples are included in the Xafari Northwind demo application.
Display modes are provided by the SyncManagedOperationHelper class. It is possible to change the display mode in the StartSimpleOperation_Execute event handler (see the code above).
- infinite scrolling bar:
- example
SyncManagedOperationHelper.CreateHelper(managedOperation).InitShowViewParametersMarquee(e.ShowViewParameters, true);
- Detail View:
- example
SyncManagedOperationHelper.CreateHelper(managedOperation).InitShowViewParameters(e.ShowViewParameters, false);
Note:
We saw an example of creating a Synchronous Managed Operation. The Asynchronous Managed Operation gives the end user more possibilities to control the execution. Examples of such operations are included in demo application Xafari Northwind.
The Learn More topic explains, how to implement an Asynchronous Managed Operation.