Skip to main content

Extension Laiye Automation Platform Command

Speaking of Plugins , Many people will think of IE/Chrome/Firefox browser plug-ins, Eclipse, Visual Studio, Sublime Text and other plug-ins of various programming tools. These plug-ins at the application tool level rely on the original platform to run, but Extension the functions of the original platform, greatly enriching the original tools and platforms. Based on plugins, users can even customize personalized browsers and programming tools.

In fact, the vast majority of programming languages also provide such a plugin mechanism, which we generally refer to as Class Library . For example, the Java language not only provides the most basic language features, but also provides an extremely rich core library that covers various aspects such as network communication, file processing, encryption and decryption, serialization, logging, and almost everything. However, even with such a comprehensive and powerful Java official core library, many users still feel that it is not enough or difficult to use in their specific application scenarios. Therefore, some users with programming ability make some functions very powerful according to their own application demand and scenario characteristics, making up for or exceeding the official core library. These users extract and contribute this part of the functionality, forming a recognized third-party class library. Together with the official core library, these third-party class libraries form a prosperous Java ecosystem. The same applies to JavaScript and Python languages.

Let's go back to Laiye Automation Platform. As mentioned earlier, Laiye Automation Platform is essentially a platform tool. This platform has several characteristics. The first is Strong , Laiye Automation Platform provides a very rich number of spare parts to build RPA process, including a complete set of functional modules, large and small, from basic keyboard and mouse operations, various UI elements operations, to the automation of common office software and browsers, from various data processing, to file processing, network and system operations. But this platform also has a second characteristic, which is Simple , Laiye Automation Platform extracts the most common, common, basic and core functions and integrates them into the platform to form a concise and capable core library. If you blindly stack functions and integrate all functions, large and small, into the Laiye Automation Platform framework, the Laiye Automation Platform framework will become very bloated and the difficulty of learning will increase significantly.

So what should users do if they encounter a problem that the Laiye Automation Platform framework cannot solve directly? Similar to Java or JavaScript, Laiye Automation Platform also provides Plugins Mechanism. If you are good at General-purpose programming language on the market, you can use these programming languages to implement specific functions, and then use this function in Laiye Automation Platform.

More interestingly, Laiye Automation Platform also supports writing plug-ins in many different programming languages. This includes Python language, Java language, C # language, and C/C++language. You can choose any language you like within this range. Plug ins written in any language are almost the same in Laiye Automation Platform.

Of course, due to the great differences between different programming languages, the methods of writing plug-ins for Laiye Automation Platform using different programming languages are also different. This article introduces the methods of writing plug-ins for Laiye Automation Platform using Python, Java, and C #. Considering that the C/C++language is relatively difficult to learn, and given the length, this article will not introduce the plugin mechanisms of these two languages.

In the following description, the file directory is often involved. Unless otherwise specified, it refers to the relative path to the installation directory of "Laiye Automation Creator" or "Laiye Automation Worker". For ease of writing, we use / The symbol is used as the path separator instead of the Windows custom \ Symbols.

Writing plugins in Python

Writing method

It is easiest to write a Laiye Automation Platform plug-in in Python. Just use any text editor to write a file with the Extension of. py (hereinafter referred to as py file), save it in UTF-8 format, and place it in the extend/python directory Call the function defined in this py file in the form of.

Attention, here's the Plugin Name It refers to the part of the file name after removing the extension. py. For example, if the file name is test. py, the plugin name is test.

Let's take a complete example:

  1. Write plugin source code . Open the extend/Python directory, create a test. py file in this directory, use Notepad to open the test. py file, and write the following content:
def Add(n1, n2):
return n1 + n2
  1. Save the test.py file as UTF-8 encoding format, as shown in the following figure:

Python plugin writing

  1. Calling plugin functions . Open Laiye Automation Platform, create a new process, and write code in the source code view:
Traceprint test.add(1, 1)
  1. Verify if the plugin functionality is correct . Run this process, and the results are shown below, which means that the plug-in call is normal.

Python plugin run results

Plugin API

When writing plug-ins in Python, in addition to calling the functions of Python itself, plug-ins can also call some functions of Laiye Automation Platform in turn. We call these called functions plugin APIs.

The calling method of the plugin API is as follows:

  1. Write the following code in the Python plugin:
import UiBot
  1. Directly call the plugin API, for example:
def CommanderInfo():
return UiBot.GetCommanderInfo()

The plugin APIs currently available in Python plugins include:

  • UiBot. IsStop()

This function is used to detect whether the current process needs to be stopped immediately (for example, the user presses the "Stop" button). When you need to stop, go back True , Otherwise, return False .

When a plug-in function needs to be executed for a long time, if the user decides to stop the process during the execution process, but the plug-in function has not been executed, the process will not be stopped immediately. Therefore, it is recommended to consider the long execution time of plug-in functions when writing plug-ins, and call the plug-in API regularly during function execution to determine whether the process needs to stop. If you want to stop, you should immediately exit the plugin function.

  • UiBot.GetString (string_path)

This function is used to obtain a string in the current language version. The Parameter is a string path (explained below), and the return value is the obtained string.

We may use strings in plugins, and some string contents require language version differentiation. For example, we prompt an error message in the plugin, which should include Chinese, English, or other language versions. If the user uses the Chinese version of Laiye Automation Platform, a Chinese error will be reported; If the user uses the English version of Laiye Automation Platform, an English error is reported.

How to achieve this? We can see it in the installation directory of Laiye Automation Platform lang/en-us/extend.json and lang/zh-cn/extend.json These two files (similar paths are also available in other language versions and will not be repeated) represent the English and Chinese versions of the strings to be used in the plugin. You can write different language versions of the strings we want to use into these files separately, and then use them in the plugin UiBot.GetString() To obtain the required string.

Of course, Laiye Automation Platform has many plug-ins, and each plug-in also has many strings. So many strings are placed in one file. How can we ensure that there is no conflict? It's easy to see, this file is JSON format Multiple nested JSON objects are used to distinguish different strings. When we need to use a string, we just need to UiBot.GetString() Filled in the Parameter of String Path That's it. so-called String Path , It refers to the combination of the Object where this string is located and the Key of the objects at the upper level, where / Separation. such as UiBot.GetString('App/Prefix') What is obtained is the string with Key 'Prefix' in the JSON Objet with Key 'App' in this file.

  • UiBot.GetCommanderInfo()

When Laiye Automation Platform Worker runs the process and has established a connection with Laiye Automation Platform Commander, some information of the Commander, such as URL, can be obtained through this API. Except for the Laiye Automation Platform official, the Laiye Automation Platform Commander is not used by ordinary users' plug-ins, so this API is not required.

Import module for plugins

A simple py file often has limited functionality. Only by importing other Python modules through the import statement in the py file can its functionality be more enriched.

In fact, in the Laiye Automation Platform installation directory lib/site-packages Under the path, there are already many pre installed Python modules (or Python packages. Please refer to the relevant instructions for the definition and differences between Python packages and modules, which will not be explained in this article). These modules can be directly used in Python plugins. If we need to import other modules in the plugin, one way is to place them in the lib/site-packages There is another way to place it under the path extend/python/<插件名>.lib Under the path. Pay attention here <插件名>.lib It is also a directory. If we have a Python plugin with the file name test. py, then this directory is test.lib .

When writing plug-ins, we recommend that the modules imported into the plug-in (assuming that these modules are not preset by Laiye Automation Platform itself) be placed in the extend/python/<插件名>.lib Under the path, instead of lib/site-packages Under the path. because lib/site-packages It is a public directory, and when we delete a plugin, it is difficult to distinguish which module is being used by the plugin, and it is no longer needed. But if these modules are placed in extend/python/<插件名>.lib In the path, it is very clear, because when deleting a plug-in, you only need to use the same name as the plug-in, and the Extension name is .lib Delete the directory together to ensure that it is good and not leaked.

In addition, it is worth noting that some py files will import some modules with the Extension pyd, which are actually Dynamic-link library in binary format. Please note that the Dynamic-link library distinguishes between the 32-bit version and the 64 bit version. If the Laiye Automation Platform you are using is a 32-bit version, these pyd modules should also be a 32-bit version; Otherwise, the pyd module should be a 64 bit version.

Hide Source Code

For py files, their source code is completely public. What if we want others to use the Python plugin we have written without wanting the source code of the plugin to be seen by others?

We only need to call this plug-in at least once in the process creator, and we will see that there is a extend/python/__pycache__ The directory has been created. Go to this directory and take a look. There are some plugins that start with the name, and in the middle are things like .cpython-37 Such content, with an extension .pyc Ending file. For example, if our py file is test.py, it will automatically create a file like this: extend/python/__pycache/test.cpython-37.pyc .

Rename this file to test.pyc , And put it in the extend/python Under the directory, delete the original test.py (Please back up before deleting), we can still use the test plug-in in Laiye Automation Platform, and the usage remains unchanged. Because its code has been saved in binary format test.pyc Got it. We only need to send this file to others for use to avoid being directly read into the source code.

Of course, test.pyc Actually, it is not encrypted and may still be decompiled by someone to obtain a portion of the source code. If a more thorough encryption is to be done, it is necessary to cooperate with other means, and this article will not elaborate further.

Other precautions

  1. If N Parameter are defined in the function of the Python plug-in, less than N Parameter can be passed in when calling in Laiye Automation Platform, and the extra Parameter will be automatically filled with None. However, no more than N Parameter can be passed in.

  2. You can take the array or dictionary type in Laiye Automation Platform as a Parameter and pass it into the Python plug-in, which corresponds to the list or dict type in Python. You can also use the list, tuple, or dict types in Python as return values and return them to Laiye Automation Platform. The former two types are converted to array types, and the latter to dictionary types.

Whether Parameter are passed in or values are returned, these composite types are passed by value between Python plug-ins and Laiye Automation Platform, rather than by reference.

  1. Exceptions can be thrown in functions of Python plugins, which can be caught by the Python plugin itself or not. If the Python plug-in does not capture, the exception will be automatically passed to Laiye Automation Platform, and Laiye Automation Platform can capture it.

If Laiye Automation Platform does not capture, the process will exit with an error, and the error message will indicate that it is caused by an exception in the Python plug-in, so as to troubleshoot the problem.

  1. The Running Environment of Python has been built in Laiye Automation Platform, so there is no need to install Python additionally. Even if installed, Laiye Automation Platform will not use the Python you installed. At present, the built-in Python of Laiye Automation Platform is version 3.7.1.

  2. Variables and functions in Python are case sensitive, but when using Python plug-ins in Laiye Automation Platform, you can still call functions in Python case insensitive. For example, in the previous example, you can write in Laiye Automation Platform test.add(1,1) , You can also write Test.ADD(1,1) , The effect is exactly the same.

  3. You can use Global variable in Python, for example, you can write variables out of functions. The value of the Global variable is shared by all functions in the Python plug-in, but different plug-ins do not share the Global variable.

  4. It is easy to write Laiye Automation Platform plug-ins in Python, but Python itself is an independent programming language, and it is inconvenient to use a text editor for development and debugging. Therefore, it is recommended to use the Integrated development environment, such as Visual Studio Code, for Python plug-in development.

Writing plugins in Java

Writing method

The Laiye Automation Creator also supports writing Laiye Automation Platform plug-ins in the Java language. Readers who have used Java know that Java source code files are generally .java End of Extension, need to use JDK (Java Development Kit) Compiled into a Extension named .class Byte Code file before it can be run. When running, it is not necessary to install JDK, and it can only be installed JRE (Java Runtime Environment).

Due to copyright restrictions, Laiye Automation Platform does not have a built-in JDK, but it has a built-in JRE version 1.7 released by Oracle. So, in order to write plugins in Java, you need to download and install Oracle JDK version 1.7 yourself. The methods of downloading and installing are extensively discussed on the internet, and this article will not repeat them.

In order to facilitate you to write Laiye Automation Platform plug-ins in Java language, we have designed an example plug-in and put its source code on GitHub. Click here To obtain. If you are accustomed to using git, you can also pull from this URL: https://github.com/Laiye-UiBot/extend-example The subsequent content will revolve around this example.

According to the specifications of the Java language, first we need to design a plugin name and then name the source code file <插件名>.java , And write a Java class in the file, whose name must also be the plugin name. In the example, we can see that the plugin name is JavaPlugin, so the source code file name must be JavaPlugin.java, and a class named JavaPlugin will be defined in this file:

public class JavaPlugin
{
}

In order for Laiye Automation Platform to use this class normally, this class must be public and cannot be included in any package. Class can define public, private or protected functions, but only public functions can be directly called by Laiye Automation Platform. For example, we defined a function called Add in the example. This function is public, so it can be called in Laiye Automation Platform.

How to call it? You need to first use the Javac program in JDK to compile this source file, and enter:

javac -encoding utf8 JavaPlugin.java

Of course, here we need the Javac program to be in the current search path. In addition, the JavaPlugin. java in the example is UTF-8 encoded and contains Chinese characters, so it needs to be added -encoding utf8 Options for. If there are no Chinese characters, this option can be omitted.

If the compilation is successful, a file named JavaPlugin.class will be automatically generated and placed in the extend/java Directory, and then you can use it just like using Python plugins. For example, we can open Laiye Automation Platform, create a new process, and write code in the source view:

Traceprint javaPlugin.add(1, 1)

Run this process, and the results are shown below, which means that the plug-in call is normal.

Java plugin run results

Plugin API

Similar to the Python plug-in, the plug-in API can also be used in the Java plug-in, which in turn calls some functions of Laiye Automation Platform. If you want to call the plug-in API, you don't need to import any package. You just need to copy the Laiye Automation Platform directory in the plug-in example to the directory where the source code of the Java plug-in is located when compiling the Java plug-in.

The plugin APIs currently available in Java plugins include:

  • UiBot. API. IsStop()

It is used to detect whether the current process needs to be stopped immediately (for example, the user presses the "Stop" button). When you need to stop, go back True , Otherwise, return False .

For specific functions, please refer to the UiBot. IsStop() function used in Python plug-ins.

  • UiBot.API.GetString (string_path)

It is used to obtain a string in the current language version. The Parameter is a string path (explained below), and the return value is the obtained string.

For specific functions, please refer to the UiBot. GetString() function used in Python plug-ins. In addition, in the plug-in example, we also used this API to obtain the string whose string path is' Excel/SaveBook ', that is, the string named' SaveBook 'in the JSON object named' Excel 'in the extend.json file.

The following code will first call the GetString() function in the Java plug-in, and then call UiBot. API. GetString() in Laiye Automation Platform in turn. You can enter this code in Laiye Automation Platform and run it to see what results can be obtained.

Traceprint JavaPlugin.getString()
  • UiBot. API. GetCommanderInfo()

When the "Laiye Automation Worker" has established a connection with the "Laiye Automation Commander" when running the process, some information of the Laiye Automation Commander can be obtained through this API. Except for the official Laiye Automation Platform plug-in, the Laiye Automation Commander is not used by ordinary users, so this API is not required.

Transmission of variables

Java is a programming language of static type, that is, variables need to be defined before use, and the type of variables (integer, Floating-point arithmetic, string, etc.) must be specified when defining. When running, variables can only be of this type. Moreover, arrays typically only contain data of the same type.

However, this is very different from Laiye Automation Platform. Laiye Automation Platform's variables are dynamically typed, and you can specify no type. You can also change the type at will when running. The array can also contain various types of data.

Therefore, in order to successfully use the Java plug-in in Laiye Automation Platform, the following requirements must be met:

  • If the Parameter of the Java plug-in is an integer, a Floating-point arithmetic, a string, or a Boolean type, the Parameter passed in by Laiye Automation Platform must also be of the same type (except for the exceptions described in the following articles), otherwise an error will occur
  • If the Parameter of the Java plug-in is a Floating-point arithmetic number, an integer can be passed in without error. But the opposite is not true, that is, if the Parameter of the Java plug-in is an integer, you cannot pass in a Floating-point arithmetic number
  • If the Parameter of the Java plug-in is a long integer, an integer less than 2 ^ 31 can be passed in without error. But the opposite is not true, that is, if the Parameter of the Java plug-in is an integer (int), an integer greater than or equal to 2 ^ 31 cannot be passed in
  • If the dictionary or array type needs to be transferred from Laiye Automation Platform to the Java plug-in, the Parameter type in the Java plug-in can only use org.json.JSONArray (corresponding array) or org.json.JSONObject (corresponding dictionary)
  • If the dictionary or array type needs to be transferred from the Java plug-in to Laiye Automation Platform, the return value type in the Java plug-in can only use org.json.JSONArray or org.json.JSONObject. Laiye Automation Platform will automatically convert the return value of org.json.JSONArray type into an array in Laiye Automation Platform, and convert the return value of org.json.JSONObject type into a dictionary in Laiye Automation Platform
  • Whether Parameter are passed in or values are returned, these composite types are passed by value between the Java plug-in and Laiye Automation Platform, rather than by reference
  • Can be written in Java source code import org.json.*; , This way, you can directly use JSONArray or JSONObject types to avoid org.json Prefix for. This is how it is written in the plugin example. In addition, the package org.json has been included in the Running Environment by Laiye Automation Platform, and no additional download and installation is required.

In the plug-in example, there is a Concat function, which is used to demonstrate how to transfer two arrays from Laiye Automation Platform to the Java plug-in, and how to return the results of connecting two arrays to Laiye Automation Platform. Readers are advised to read carefully.

Reference module for plugins

Similar to Python, a simple Java file often has limited functionality. Only by importing other Java packages through the import statement in the source code can its functionality be more enriched.

We have built Oracle JRE 1.7 into Laiye Automation Platform, and of course, it also includes the packages that come with JRE, such as com.sun.javafx Etc. In addition, we have built the org. json package to be used in Laiye Automation Platform. In addition to the above content, other third-party Java packages can be .class The file in the format exists, and can also be .jar A file in format exists. Readers familiar with the Java language should have a sufficient understanding of the two types of files mentioned above. The former is a Byte Code of Java code, and the latter is a compressed file packaged from multiple Byte Codes.

When starting Laiye Automation Platform, it will automatically extend/java Add the directory to Java's classpath. In addition, when loading a Java plugin, it will also extend/java/<插件名>.lib This directory, and under this directory All The Extension is .jar All files are automatically added to Java's classpath. For example, we have a Java plugin called A.class , And placed in extend/java Under the directory. So, extend/java catalogue extend/java/A.lib Catalog, and extend/java/A.lib/*.jar , Will be added to the classpath. If any third-party Java packages need to be referenced in our plugin, simply place the package under these paths and comply with Java's Classpath specification , Ready to use.

Other precautions

  1. The functions in the Java plug-in do not support variable Parameter or default Parameter. When calling, the specified number and type of Parameter must be passed in.

  2. Exceptions can be thrown in the functions of Java plugins, which can be caught by the Java plugin itself or not. If the Java plug-in does not capture, the exception will be automatically passed to Laiye Automation Platform, and Laiye Automation Platform can capture it. If Laiye Automation Platform does not capture, the process will exit with an error, and the error message will indicate that it is caused by an exception in the Java plug-in, so as to troubleshoot the problem.

  3. Variables and functions in Java are case sensitive. However, when using the Java plug-in in Laiye Automation Platform, you can still call functions in Java case insensitive. For example, in the previous example, you can write in Laiye Automation Platform javaPlugin.add(1,1) , You can also write JavaPlugin.ADD(1,1) , The effect is exactly the same.

  4. When writing a Java plug-in, you actually define a Java class and give the public function in the class to Laiye Automation Platform to call. This class can have constructors or Member variable, and their initialization will be automatically completed when the process just starts running.

  5. Oracle JRE version 1.7 is built in Laiye Automation Platform. You need to download Oracle JDK version 1.7 to compile the Java plug-in. Although sometimes the versions of JDK and JRE are inconsistent and can work, it is recommended to use the same version to reduce trouble. In addition, it is also recommended to use the Integrated development environment to develop Java plug-ins, such as Eclipse or IntelliJ IDEA.

Writing plugins in C #. Net

Writing method

Part of Laiye Automation Platform's own code is based on Microsoft's. Net framework and is written in C # language. Therefore, Laiye Automation Platform plug-ins (hereinafter referred to as. Net plug-ins) can also be written in C # language. In fact, Microsoft's. Net framework supports multiple programming languages, including VB. Net, C++/CLI, and so on. These programming languages all follow the specifications of the. Net framework and can be used to write. Net plugins. However, since C # is Microsoft's main programming language, this article uses C # as an example. Experienced readers can also port it to other languages on the. Net framework. In addition, Laiye Automation Platform's support for. Net plug-ins is also constantly upgrading. This article takes Laiye Automation Creator version 5.1 as an example. If some examples may not work properly on the old version of Laiye Automation Platform, please upgrade in time.

For your convenience in writing. Net plugins in C # language, we have designed a template for the plugin and placed its source code on GitHub. Click here To obtain. If you are accustomed to using git, you can also pull from this URL: https://github.com/Laiye-UiBot/extend-example . It is recommended that when writing. Net plugins, you directly build on this template instead of starting from scratch. The subsequent content will also revolve around the examples in this template.

Similar to Java plug-ins,. Net plug-ins also need to be compiled into Extension named .dll Can be used by Laiye Automation Platform. Microsoft's Integrated development environment, Visual Studio, has both writing and compiling functions, and also provides a free community version, which is recommended to download. The template we provide is based on the 2015 version of Visual Studio. You can choose this version or a higher version of Visual Studio, but it is not recommended to use a version of Visual Studio earlier than 2015.

After installing Visual Studio and downloading our. Net plugin template, you can double-click UiBotPlugin.sln File, this is a "solution", and the so-called solution in Visual Studio is actually a collection of multiple associated files. After opening this solution using Visual Studio. As you can see, it contains a lot of content. The only thing we need to modify is the UiBotPlugin.cs file. Other files, references, and properties can be left untouched. As shown in the following figure:

. Template for Net plugin

Stay UiBotPlugin.cs In the file, there is a file called UiBotPlugin The namespace contains an interface and a class. To avoid confusion, we recommend changing the name of this namespace to your plugin name. For example, the final plugin file is DotNetPlugin.dll , So the plugin name is DotNetPlugin , The name of this namespace has also been changed to DotNetPlugin It is advisable.

From the template, it can be seen that three functions are declared in the interface and their implementations are written in the class. These three functions are all examples, and you can remove their declarations and implementations at any time and add your own plugin functions. But please pay special attention: when adding a function, you should also maintain a similar writing method. You need to declare it in the interface and implement it in the class. Otherwise, Laiye Automation Platform cannot recognize the plug-in function properly.

Using the Add function in the example, we try to compile the plug-in and call this function in Laiye Automation Platform:

  1. Select the "Build" menu item of Visual Studio. After compiling the solution, you will see a directory called Release under the plug-in directory, in which a file called UiBotPlugin.dll is generated.
  2. Manually rename this file to your plugin name and keep it .dll The extension of. If renamed as DotNetPlugin.dll .
  3. Put this file in Laiye Automation Platform's extend/DotNet Under the directory.
  4. Open Laiye Automation Platform, create a new process, and write code in the source code view:
Traceprint DotNetPlugin.add(1, 1)

Run this process, and the results are shown below, which means that the plug-in call is normal.

. Net plugin run results

You may notice that in the previous examples of Python plug-ins and Java plug-ins, there is an example function called Add. Except for the plug-in name, there is no difference between the way Laiye Automation Platform calls them and the running results. In fact, there are significant differences in the internal implementation of different plugins. For example, in the Python language, UTF-8 encoding is used by default to save strings, while in. Net, UTF-16 encoding is used by default. But Laiye Automation Platform has helped you smooth out these differences, so that you don't have to care about these details in the process of use.

Plugin API

Similar to Python and Java plug-ins, the plug-in API can also be used in. Net plug-ins, which in turn calls some functions of Laiye Automation Platform. If you want to call the plugin API, simply base it on Template provided by Laiye Automation Platform You can write plug-ins without any other Settings.

. The name, Parameter and meanings of the plug-in API that can be used in the Net plug-in are identical to those of the Java plug-in. For example, you can use UiBot.API.IsStop() To check whether the current process needs to stop immediately, etc. Please refer to the explanation of the plugin API in Java plugins and do not elaborate further.

In the template, you may see a file called DotNetAdapter.dll The file for. In fact, this file is included in every version of Laiye Automation Platform. Starting from Laiye Automation Platform version 5.1, the. Net plug-in API you call is actually implemented in this file. Therefore, when your plug-in is released, you do not need to include this file, because Laiye Automation Platform already comes with it.

At the same time, if your Laiye Automation Platform is updated to a higher version, DotNetAdapter.dll It may also include more plugin APIs. You can get the new version of the DotNetAdapter.dll File and place it in the directory where the source code of the plugin you wrote is located to use the new version of the plugin API.

Transmission of variables

Similar to Java, C #. Net is also a statically typed programming language, and variables need to be defined before use, and the type of the variable must be specified during definition. Moreover, arrays typically only contain data of the same type. This is very different from the dynamic type of Laiye Automation Platform.

Therefore, when writing and using. Net plugins, it is necessary to comply with the following regulations:

  • For Parameter of basic types such as integer, Floating-point arithmetic, string, and boolean, Laiye Automation Platform does not strictly check the type of the. Net plug-in. It will try its best to convert, and will not report an error even if the conversion is unsuccessful. Therefore, please pay special attention to the type of each Parameter when using it to avoid passing in incorrect values without timely discovery.
  • If the dictionary or array type needs to be transferred from Laiye Automation Platform to the. Net plug-in, the Parameter type in the. Net plug-in can only use Newtonsoft. Json. Linq. JArray (corresponding array) or Newtonsoft. Json. Linq. JObject (corresponding dictionary). In the template, as we have already written using Newtonsoft.Json.Linq; , So you can omit the prefix and abbreviate it as JArray (corresponding array) or JOObject (corresponding dictionary), which is also used in the following simplified notation.
  • If the dictionary or array type needs to be transferred from the. Net plug-in to Laiye Automation Platform, the return value type in the. Net plug-in can only use JArray (corresponding array) or JObject (corresponding array). Laiye Automation Platform will automatically convert the return value of JArray type into an array in Laiye Automation Platform, and The return value of the JObject type is converted to the dictionary in Laiye Automation Platform.
  • Whether Parameter are passed in or values are returned, these composite types are passed by value between the. Net plug-in and Laiye Automation Platform, rather than by reference.

In the plug-in template, there is a Concat function as an example, which is used to demonstrate how to transfer two arrays from Laiye Automation Platform to the. Net plug-in, and how to return the results of the connection of two arrays to Laiye Automation Platform. Readers are advised to read carefully.

Reference module for plugins

Laiye Automation Platform itself depends on the. Net Framework, and it is assumed that the user has installed the version of. Net Framework 4.5.2 or above. If the. Net Framework is not installed or the version is wrong, Laiye Automation Platform itself cannot run, and of course, the plug-in you wrote cannot be used. So, when writing plugins, as long as your plugin also relies on the. Net Framework version 4.5.2, there is no need to worry about environment mismatch issues.

Microsoft has already built in a very rich range of features in the. Net Framework, but it is inevitable that some features are still not included, and third-party. Net DLL files need to be referenced.

Similar to the Java plug-in, when Laiye Automation Platform loads a. Net plug-in, if the. Net plug-in references a third-party. Net dll file, Laiye Automation Platform will first try to search the directory where the. Net plug-in is located for the referenced dll file. If we don't find it, we'll come back again <插件名>.lib Go down this directory and look for it again. For example, we have a. Net plugin called A.dll , Place in extend/DotNet In the directory, and referenced B.dll . Then Laiye Automation Platform will try to find extend/DotNet/B.dll , Try again to find extend/DotNet/A.lib/B.dll . If neither directory is found, an exception will be thrown.

Other precautions

  1. JArray and JOObject are not built-in to the. Net Framework, but use open-source Json. Net . During compilation and runtime, a dependency named Newtonsoft.Json.dll The file for. stay Template provided by Laiye Automation Platform This file is already included in. At the same time, this file will also come with each version of Laiye Automation Platform. Therefore, you can directly use JArray and JOObject without including this file in the plugin.

  2. When compiling plugins, the compiler may warn" DotNetAdapter Information such as' processor architecture mismatch '. Actually, it has no impact and there is no need to ignore this warning.

  3. . The functions in the Net plug-in support default Parameter. When calling, if some Parameter have default values, you can not transfer values, and this Parameter will automatically take the default values.

  4. Exceptions can be thrown in the functions of the. Net plugin, which can be caught by the. Net plugin itself or not. If the. Net plug-in does not capture, the exception will be automatically sent to Laiye Automation Platform, and Laiye Automation Platform can capture it. If Laiye Automation Platform does not capture, the process will exit with an error, and the error message will indicate that it is caused by an exception in the. Net plug-in, so as to troubleshoot the problem.

  5. . The variables and functions in Net are case sensitive. However, when using the. Net plug-in in Laiye Automation Platform, you can still call the functions in Net case insensitive. For example, in the previous example, you can write in Laiye Automation Platform DotNet.add(1,1) , You can also write dotnet.ADD(1,1) , The effect is exactly the same.

Sharing of plugins

No matter which language the plugin is written in, it can be placed in the extend In the corresponding path of the directory, for example, the Python plugin is placed in the extend/python In the directory, you can use it directly.

But this situation is only suitable for your own use and cannot be shared with others. In addition, if the process using this plug-in is packaged and run on Laiye Automation Platform Worker, the plug-in will not be packaged, but needs to be copied to Laiye Automation Platform Worker separately extend In the corresponding path of the directory.

If your plug-in really has the meaning of sharing, we recommend that you share it with the Laiye Automation Platform command center for others on the Internet to learn. You can also find some plug-ins shared by others in the Laiye Automation Platform command center. When running on Laiye Automation Platform Worker, if these plug-ins are used, they do not need to be copied to Laiye Automation Platform Worker.

Suppose we write a plug-in of "Elementary arithmetic" in Python, with the file name of Arith.py , The content is as follows:

def Add(a, b):
return a+b

def Sub(a, b):
return a-b

def Mul(a, b):
return a*b

def Div(a, b):
return a/b

Follow the following steps to share this plugin with other users:

  1. Open any process with the Laiye Automation Creator, and then open any process block;

  2. Find the button "Laiye Automation Platform Command Center" in the left panel, click this button, and select "Custom Plug in" under "Custom", as shown in the red box in the following figure;

  3. Select 'Add Custom Plugin' and fill in the dialog box referring to the content shown in the figure:

Add custom plugins

Due to our plugin file name being Arith.py , So, the main file name is Arith . You can Arith.py The files and the files it depends on are compressed into a zip file (any third-party compression tool or the compression function provided by Windows can be used to complete it). The name of the zip file is arbitrary. Then select the zip file, fill in the main file name, and the most critical information is completed. Other columns, such as "Plug in Name", "Plug in Home Page" and "Plug in Description", are for User to read. You can fill in them carefully and appropriately according to your habits.

  1. After saving, a plug-in is added. You can see the information of the new plug-in on the UI. In order to make the User understand the specific usage of the plug-in more clearly, we also need to configure each function (in the view of the User, each command) in the plug-in. The configuration method is as follows:
  • You can see on the UI that after the plug-in is added, a "Add Command" button will appear. This button allows us to add some configuration information for the functions ("commands" in the User's view) in the plug-in for use.

  • Click on the "Add Command" button to enter the "Add Command" page. On the left is the explanatory information about the command. Please fill in according to the prompts and requirements on the page. Among them, "Add% 1 and% 2" filled in the visual translation, "% 1" and "% 2" indicate reading the first and second attribute respectively.

Add Command

  • You can also further fill in the attribute information of the command. Locate the attribute Edit window on the right. Click the "Add" button on the right side of "Required attribute", add the first attribute "a" and its attribute description through the "attribute Edit" dialog box, and select "Number" for the Parameter type; Select 'Input Box' for component type; Fill in 0 as the default value. Similarly, add the second attribute "b". These two values represent the addend and the addend, respectively.

New attribute

  • The information of other commands will be added in succession, so that when User use your plug-in, they can clearly show the meaning of the command in the visual view, and clearly explain the meaning of each attribute. It is easy enough to use.

So far, we have made all preparations for the release of the plug-in. Click the "Install and Debug" button at the top right of the dialog box to install the plug-in into the current process. Back in the UI of writing process, you can find the "Elementary arithmetic" we added in the command list on the left, as well as the four commands in it: my addition, my subtraction, my multiplication and my division. For User, just like using the general Laiye Automation Platform preset command, drag it to the visual view of Laiye Automation Platform and configure its attribute.

Let's try. Drag the "My Add" command, and Settings the first addend as "2" and the second addend as "3" in the attribute column. As shown in the figure:

My Add command attribute Settings

You can also drag in another 'output to debug window' command to output the results. In this way, the display effect of the visualization view is similar to that shown in the following figure. It can be seen that our Settings have taken effect. Plug in translation is easy to understand when using plug-ins.

Display in visualization view

Running this process, you can see that the results of the output column meet the expectations, indicating that the custom command meets the requirements and can be released.

Next, open the "Command Center" again, find the plugin we just added, and click "Publish". After filling in the description and version number on the "Publish Command" page, click the "Submit" button. After that, please wait for our review. If the review is approved, you can find the plugin and its commands you published in the "installable" column of the command center.

In addition to the plugins you have published, you can also see plugins published by other users, which contain various specific functions. You can select the plug-in you like to install and use in your process.

It is worth noting that it is similar to the "Library" mentioned above: if we use a plug-in or Library when writing a process block, the plug-in or Library is available in all process blocks in the current process. However, if another process is changed, it needs to be reinstalled or imported; In addition, when process that use plug-ins or Library are packaged for Laiye Automation Worker, the Library will be automatically packaged without additional processing.