Description
Activities are the core unit of behavior in Windows Workflow Foundation. The execution logic of an activity can be implemented in managed code or it can be implemented by using other activities. This topic demonstrates how to create an activity.
There are two steps required to create a custom activity:
- Writing the custom activity code.
- Package your activity
- Register the assembly (.dll) to akaBot Platform.
Write Activity Code
To develop your custom activity, you will need to use Microsoft Visual Studio with WF extension package installed and do the following steps:
- Open Microsoft Visual Studio.
- In the New Project dialog, under the Installed category, select Visual C# > Workflow (or Visual Basic > Workflow).
- Select the Activity Library project template. Type “RCA.Activities.Demo” in the Name box. Select .NET Framework 4.5.2 and then click OK.
- Right-click Activity1.xaml in Solution Explorer and choose Delete. Click OK to confirm.
- Choose Add New Item from the Project menu.
- In the Installed > Common Items node, select Workflow. Select Code Activity from the Workflow list.
- Type SumInt into the Name box and then click Add.
- Replace the existing SumInt definition with the following definition.
- Click Build Solution. You should see no error and there is an assembly file RCA.Activities.Demo.dll in build output directory.
C#
using System.Activities;
namespace RCA.Activities.Demo
{
public sealed class SumInt : CodeActivity
{
public InArgument<int> Number1 { get; set; }
public InArgument<int> Number2 { get; set; }
public OutArgument<int> Total { get; set; }
protected override void Execute(CodeActivityContext context)
{
int num1 = context.GetValue(this.Number1);
int num2 = context.GetValue(this.Number2);
context.SetValue(Total, num1 + num2);
}
}
}
Package Your Activity
To package your activity, please complete the following steps:
- Download nuget.exe
Download nuget.exe from https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - Generate .nupkg file
- Open command prompt at your project folder
Figure 1 Click on address bar -> type ‘cmd’ -> press Enter
- Use following command to generate .nuspec file : %PATH%\nuget spec (%PATH% is the directory where nuget.exe file is placed).
- Open created .nuspec file, remove all example data and input at least Author, Description
Figure 2 Edit Author, Description
- Add file element for any file the user desires to be copied
Figure 3 Add additional files to be copied
- Use following command to generate .nupkg file : %PATH%\nuget pack (%PATH% is the directory where nuget.exe file is placed).
Register your package
To register your package, you need to copy generated .nupkg file to ProgramData Folder: C:\ProgramData\akaBot\Packages\
Install Your Package
To install your package, please complete the following steps:
1. Open Package Manager
Figure 4 Open Package Manager
2. Select your package from Local tab -> select version -> click install -> click save
Figure 5 Choose Package from list -> select version -> click install -> click save
3. Confirm restart studio
4. Custom activities would appear in the toolbox