无论是UiPath, Automation Anywhere, BluePrism都提供了接口(API)来部署任务到机器人。
Automation Anywhere Control Room APIs
Automation Anywhere的接口分为以下几种:
- Authentication 认证接口
- Bot Login Credentials 可以更改control room上的 credential vault
- Bot Deployment 部署任务到runner
- Export and Import Bots for Bot Lifecycle Management
- Export Import Workload Management Configuration
- Get list of all queues
- Get list of all work items in a given queue
- Insert work item data to a given queue
UiPath Orchestrator APIs
UiPath的API是基于 OData (Open Data Protocol)协议的;套路基本上跟AA一样的:
- 先获取Authentication token;
- Get Release Key
- Get Bot Id
- 就可以部署一个任务到特定一个或几个机器人了;
详细请参考:Swagger
https://platform.uipath.com/swagger/ui/index#/
C#调用console发起BluePrism任务
没有找到BluePrism调用API的接口,只能通过cmd命令行的方式来发起一个任务。命令行如下:
cd C:\Program Files (x86)\Blue Prism Limited\Blue Prism Automate
AutomateC /run "HelloWorld" /resource YourPCHostName /user admin password /startp "<inputs><input name='Comment' type='text' value='Hello World' /></inputs>"
其中,input就是任务所需的参数;
最终还是要用Java或者C#来实现接口的调用或者是命令行的方式。
Tips: C# Json String转XML
首先,我们需要NewtonSoft.json这样一个NuGet的包,如果是visual studio 2017,可以直接搜索安装:
当然,如果像我一样用的是Visual Studio 2012,那么需要从网上找一下Newtonsoft.Json.dll (https://www.newtonsoft.com/json), 然后本地项目我们用的是.NET Framework4.5。
String jsonData = "{ \"name\":\"Jane\",\"age\":\"20\",\"English\":\"70\",\"Math\":\"80\" }";
dynamic obj = JsonConvert.DeserializeObject<dynamic>(jsonData );
foreach (var item in obj)
{
var name = item.Name;
var value = item.Value;
Console.WriteLine(name + ":" + value);
}
将json string序列化转为xml的目的是作为Blue Prism的输入,从console上调起一个BP的任务:
string strCmdText1;
strCmdText1 = "cd C:\\Program Files\\Blue Prism Limited\\Blue Prism Automate";
string inputParameters = "\"<inputs><input name='Comment' type='text' value='Hello World' /></inputs>\"";
string strCmdText2 = "AutomateC /run "+taskname+" /resource robotname /user username password /startp " + inputParameters;
ExecuteCommand(strCmdText1, strCmdText2);
public void ExecuteCommand(string command1,string command2)
{
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
process.StartInfo.RedirectStandardOutput = true;
process.Start();
process.StandardInput.WriteLine(command1);
process.StandardInput.WriteLine(command2);
process.StandardInput.Flush();
process.StandardInput.Close();
process.WaitForExit();
Console.WriteLine(process.StandardOutput.ReadToEnd());
/*Console.ReadKey();*/
}