阅读和查看 Automation Anywhere 文档

Automation Anywhere

关闭内容

内容

打开内容

构建和测试 DLL

  • 已更新:5/10/2019
    • 11.3.x
    • 版本
    • Enterprise

构建和测试 DLL

构建调用 REST API 来返回以美元和欧元为单位的最新比特币价格的 DLL。MetaBot

先决条件

  • 基本了解编程并具有相关经验
  • 访问集成开发环境 (IDE) 来开发代码示例以作为支持 C# 的 DLL。IDE 的一个示例是 Microsoft Visual Studio 社区版
  • 访问 Automation Anywhere Enterprise client
  • Bot Creator权限
  • 十分了解 Automation Anywhere RPA 平台,包括基本了解TaskBotMetaBot以及它们做什么。
    提示: 请查看使用 Enterprise client 构建基本机器人来基本了解机器人

有四个程序是更广泛的解决方案 (MyApp4Lib) 的一部分。输入并构建此示例代码。

创建了两个 DLL:
  • MyApp4Lib.dll
  • RestSharp.dll

过程

  1. 编译用于测试方法的代码。
    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MyApp4Lib; namespace MyApp4Test { class Program // Test program for the classes { static void Main(string[] args) { VisibleBotMethods vbm = new VisibleBotMethods(); String UsdPrice = vbm.GetPriceOfBitcoin("usd"); Console.WriteLine("\nPrice of Bitcoin in USD: " + UsdPrice); Console.ReadKey(); } } } 
  2. 编译协调 REST 调用并检索比特币价格的代码。
    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyApp4Lib { public class VisibleBotMethods { public String GetPriceOfBitcoin(String Currency) { // Make GET call -- the Currency is the variable: // usd for $Dollars, eur for Euros String URL = "https://api.cryptonator.com/api/ticker/btc-" + Currency; // Instantiate objects RestUtils ru = new RestUtils(); JsonUtils ju = new JsonUtils(); // Make the REST call and return the JSON response String JsonResp = ru.CallRestGETNoAuth(URL); // Retrieve just the price from the JSON as a String String BCPrice = ju.GetDataFromJsonResponse(JsonResp); return BCPrice; } } } 
  3. 编译方法以进行 REST 调用。
    using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace MyApp4Lib { public class RestUtils { public String CallRestGETNoAuth(String URL) { // Setting up a web request on the URL that we pass as a parameter, // specifying a GET request for a JSON response System.Net.HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(URL); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "GET"; // Submitting the request, getting the response, turning it into a string, // and returning the response try { var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new System.IO.StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); return result; } } catch (System.Net.WebException e) // Catch error if URL is not valid { return "Error:" + e.Message; } } } } 
  4. 编译处理 Json 响应并返回比特币价格的代码。
    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyApp4Lib { class JsonUtils // Includes methods to process JSON { public String GetDataFromJsonResponse(String JsonResp) { RestSharp.RestResponse response = new RestSharp.RestResponse(); response.Content = JsonResp; // Turning JSON structure into object / class structure JsonDeserializer deserial = new JsonDeserializer(); StdJsonResponseForCurrCheck x = deserial.Deserialize<StdJsonResponseForCurrCheck>(response); String Resp = ""; // Identifying price within the class structure, and then return it Resp = x.ticker.price; return Resp; } } // Taking JSON response and turning it into classes public class Ticker { public string @base { get; set; } public string target { get; set; } public string price { get; set; } public string volume { get; set; } public string change { get; set; } } public class StdJsonResponseForCurrCheck { public Ticker ticker { get; set; } public int timestamp { get; set; } public bool success { get; set; } public string error { get; set; } } } 

后续步骤

将多个 DLL 添加到MetaBot中将在此任务中创建的 DLL 添加到MetaBot
发送反馈