Plugin Development
Contents |
Getting Started
You can download the examples at: url.com
Making Your First Plugin
Plugin Interfaces
IUBotCommand
You should implement this interface when creating a new command for your plugin.
public interface IUBotCommand { string CommandName { get; } string Category { get; } IEnumerable<UBotParameterDefinition> ParameterDefinitions { get; } void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters); bool IsContainer { get; } }
IUBotFunction
public interface IUBotFunction { string FunctionName { get; } object ReturnValue { get; } UBotType ReturnValueType { get; } string Category { get; } IEnumerable<UBotParameterDefinition> ParameterDefinitions { get; } void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters); }
IUBotStudio
public interface IUBotStudio { void RunScript(string script); void ChangeUserInterface(string name); IUBotCommand ContainerParent { get; set; } void RunContainerCommands(); void SetVariable(string variableName, string value); void SetList(string listName, List<string> value); void SetTable(string tableName, string[,] value); string GetVariable(string variableName); List<string> GetList(string listName); string[,] GetTable(string tableName); }
IWizard
public interface IWizard { Window WizardWindow { get; } Dictionary<string, string> WizardValues { get; } }
IWizardEnabled
public interface IWizardEnabled { IWizard GenerateWizard(); }
IEventEnabled
public interface IEventEnabled { void StartEventListener(); void StopEventListener(); }
UBotParameterDefinition
public class UBotParameterDefinition { public string Name { get; private set; } public UBotType Type { get; private set; } public IEnumerable<string> Options { get; set; } public object DefaultValue { get; set; } public UBotParameterDefinition(string name, UBotType type) { Name = name; Type = type; } }
UBotType
public enum UBotType { String, UBotVariable, UBotList, UBotTable }
Plugin Examples
Basic Commands and Functions
Command Without Parameters
This is an example of a command that uses Process.Start to open Internet Explorer. It takes no parameters.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using UBotPlugin; using System.Diagnostics; namespace SimpleCommands { /// <summary> /// This command is an example of a command with no parameters. It will open internet explorer when run. /// </summary> public class OpenInternetExplorerCommand : IUBotCommand { public string Category { // This is what category our command is categorized as. // If you choose something not already in the toolbox list, a new category will be created. get { return "Browser Commands"; } } public string CommandName { // The name of our node in UBot Studio. get { return "open internet explorer"; } } public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters) { // Start the Internet Explorer process. Process.Start("iexplore.exe"); } public bool IsContainer { // This command does not have any nested commands inside of it, so it is not a container command. get { return false; } } public IEnumerable<UBotParameterDefinition> ParameterDefinitions { // Since we have no parameters we return an empty list. get { return new List<UBotParameterDefinition>(); } } } }
Command With Parameters
This is an example of a command that displays a MessageBox using the error icon. It takes one parameter, the text that is displayed.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using UBotPlugin; using System.Windows; namespace SimpleCommands { /// <summary> /// This command is an example of a command with one parameter. It will show a MessageBox with an error icon. /// Parameters: The MessageBox text to use for your error. /// </summary> public class ErrorAlertCommand : IUBotCommand { // List to hold the parameters we define for our command. private List<UBotParameterDefinition> _parameters = new List<UBotParameterDefinition>(); public ErrorAlertCommand() { // Add our parameter (Alert Text) with a String type since it is text. _parameters.Add(new UBotParameterDefinition("Alert Text", UBotType.String)); } public string Category { // This is what category our command is categorized as. // If you choose something not already in the toolbox list, a new category will be created. get { return "Flow Commands"; } } public string CommandName { // The name of our node in UBot Studio. get { return "error alert"; } } public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters) { // Grab the value of the Alert Text parameter we defined. string value = parameters["Alert Text"]; // Display the MessageBox with an error icon and the text given. MessageBox.Show(value, "Error Alert", MessageBoxButton.OK, MessageBoxImage.Error); } public bool IsContainer { // This command does not have any nested commands inside of it, so it is not a container command. get { return false; } } public IEnumerable<UBotParameterDefinition> ParameterDefinitions { // We reference our parameter list we defined above here. get { return _parameters; } } } }
Function Without Parameters
This is an example of a function that returns the time of a day (e.g. 3:45:12 PM). It takes no parameters.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using UBotPlugin; using System.Threading; namespace SimpleCommands { /// <summary> /// This command is an example of a command that runs UScript. It will wait 5 seconds and then navigate to the given URL. /// </summary> public class TimeOfDayFunction : IUBotFunction { // List to hold the parameters we define for our command. private List<UBotParameterDefinition> _parameters = new List<UBotParameterDefinition>(); private string _returnValue; public TimeOfDayFunction() { // Add our parameter (URL) with a String type since it is text. _parameters.Add(new UBotParameterDefinition("URL", UBotType.String)); } public string FunctionName { // The name of our node in UBot Studio. // You need to use a $ sign in front of function names. get { return "$time of day"; } } public string Category { // This is what category our command is categorized as. // If you choose something not already in the toolbox list, a new category will be created. get { return "Browser Commands"; } } public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters) { // Set the return value to the current time formatted as 12:00:00 AM _returnValue = DateTime.Now.ToString("HH:mm:ss tt"); } public bool IsContainer { // This command does not have any nested commands inside of it, so it is not a container command. get { return false; } } public IEnumerable<UBotParameterDefinition> ParameterDefinitions { // We reference our parameter list we defined above here. get { return _parameters; } } public object ReturnValue { // We return our variable _returnValue as the result of the function. get { return _returnValue; } } public UBotType ReturnValueType { // Our result is text, so the return value type is String. get { return UBotType.String; } } } }
Function With Parameters
This is an example of a function that returns the square of the number given as input. For example, an input of 3 would return 32 which is 9. It takes one parameter, the number to square.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using UBotPlugin; namespace SimpleCommands { /// <summary> /// This function is an example of a function with one parameter. It will return the square of the input. /// Parameters: The MessageBox text to use for your error. /// </summary> public class SquareNumberFunction : IUBotFunction { // The default return value of our function is 0. string _returnValue = "0"; // List to hold the parameters we define for our function. private List<UBotParameterDefinition> _parameters = new List<UBotParameterDefinition>(); public SquareNumberFunction() { // Add our parameter (Number to Square) with a String type since it is text. _parameters.Add(new UBotParameterDefinition("Number to Square", UBotType.String)); } public string FunctionName { // The name of our node in UBot Studio. // You need to use a $ sign in front of function names. get { return "$square number"; } } public object ReturnValue { // We return our variable _returnValue as the result of the function. get { return _returnValue; } } public UBotType ReturnValueType { // Our result is text, so the return value type is String. get { return UBotType.String; } } public string Category { // This is what category our function is categorized as. // If you choose something not already in the toolbox list, a new category will be created. get { return "Math Functions"; } } public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters) { // Grab the value of the Number to Square parameter we defined. string value = parameters["Number to Square"]; // Parse the input as a double, in case it has a decimal in it. // If we are able to parse it, we square the number double valueAsNumber; if (double.TryParse(value, out valueAsNumber)) { valueAsNumber = valueAsNumber * valueAsNumber; } else { valueAsNumber = 0; } // Set the return value to the number we calculated. _returnValue = valueAsNumber.ToString(); } public IEnumerable<UBotParameterDefinition> ParameterDefinitions { // We reference our parameter list we defined above here. get { return _parameters; } } } }
Container Commands
This is an example of a container command that runs the nodes dragged inside of it twice as many times as specified. It has one parameter, Number of times to loop twice.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using UBotPlugin; namespace ContainerCommands { /// <summary> /// This command is an example of a container command. It runs the nodes dragged inside of it 2 * the number of times specified to loop /// Parameters: Number of times to loop twice /// </summary> public class DoubleLoopCommand : IUBotCommand { // List to hold the parameters we define for our command. private List<UBotParameterDefinition> _parameters = new List<UBotParameterDefinition>(); public DoubleLoopCommand() { // Add our only parameter to the list of parameters. _parameters.Add(new UBotParameterDefinition("Number of times to loop twice", UBotType.String)); } public string Category { // This is what category our command is categorized as. // If you choose something not already in the toolbox list, a new category will be created. get { return "Flow Commands"; } } public string CommandName { // The name of our node in UBot Studio. get { return "double loop"; } } public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters) { // Grab the value of the Number of times to loop twice parameter we defined. string value = parameters["Number of times to loop twice"]; // Since they are giving us a number, we parse it into an integer, and default to 0 if we can't parse it. int valueAsNumber; if (!int.TryParse(value, out valueAsNumber)) { valueAsNumber = 0; } // Loop input * 2 times and run the contained commands for each loop. for (int i = 0; i < valueAsNumber * 2; i++) { ubotStudio.RunContainerCommands(); } } public bool IsContainer { // Since this is a container command (you can drag nodes inside of it), we return true. get { return true; } } public IEnumerable<UBotParameterDefinition> ParameterDefinitions { // We reference our parameter list we defined above here. get { return _parameters; } } } }
Container Commands
This is an example of a container command that runs the nodes dragged inside of it twice as many times as specified. It has one parameter, Number of times to loop twice.