Plugin Development

From UBot Studio
Jump to: navigation, search

Contents

Getting Started

UBot Studio API Terms of Use

All use of the UBot Studio API is governed by the following Terms of Use: UBot Studio API TOS

Confirming Your Plugin Key

BEFORE you begin development, you will need to open a support ticket for review of your intended plugin. There is NO guarantee you will receive a key to develop your plugin, so it is extremely recommended that you do this first. Please see the section below on "Unreviewed Plugins" and follow the instructions there.

Recommended Software

The following software is recommended for creating UBot Studio plugin.

  1. A .NET compiler that supports .NET 4.0:
    • Microsoft Visual Studio 2010
    • Microsoft Visual C# 2010 Express
    • Microsoft Visual Basic 2010 Express
    • Microsoft Visual Studio 2012
    • Microsoft Visual Studio Express 2012 for Windows Desktop
  2. UBot Studio
    • This is needed to test the plugins you create, and verify they are working correctly inside of UBot Studio.

Installing Visual C#/Visual Basic 2010 Express

You can download Visual C# 2010 and Visual Basic 2010 express from: http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

Downloading The UBotPlugin.dll Library

You can download the UBotPlugin.dll from http://www.ubotstudio.com/files/plugins/UBotPlugin.dll. You will need this library to create UBot Studio plugins.

Making Your First Plugin

Creating The Project

  1. Download UBotPlugin.dll from http://www.ubotstudio.com/files/plugins/UBotPlugin.dll
  2. Open Microsoft Visual C# 2010 Express and choose New Project... (Screenshot)
  3. Choose the WPF Application template and name your project MyFirstPlugin (Screenshot)
  4. From the Solution Explorer delete App.xaml and MainWindow.xaml (Screenshot)
  5. From the Main Menu choose Project -> MyFirstPlugin Properties... (Screenshot)
  6. In the Application Tab change the Output type to Class Library (Screenshot)
  7. From the Main Menu choose File -> Save All (Screenshot)
  8. If desired, change the location where the project is saved. Make a note of the location as you will need it in a later step then click Save. (Screenshot)
  9. From the Solution Explorer right click on the project and choose Add Reference... (Screenshot)
  10. Select the UBotPlugin.dll downloaded in the first step and click OK (Screenshot)

Creating The Command

  1. From the Solution Explorer right click on the project and choose Add -> Class... (Screenshot)
  2. For the name of the class enter MyFirstCommand.cs (Screenshot)
  3. Modify your class to implement the IUBotCommand interface, and add a using directive: using UBotPlugin; at the bottom of the other using directives. Your script should now look like:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using UBotPlugin;
     
    namespace MyFirstPlugin
    {
        public class MyFirstCommand : IUBotCommand
        {
        }
    }
  4. Right click on the interface IUBotCommand, and choose Implement Interface->Implement Interface. Your script should now look like:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using UBotPlugin;
     
    namespace MyFirstPlugin
    {
        public class MyFirstCommand : IUBotCommand
        {
            public string Category
            {
                get { throw new NotImplementedException(); }
            }
     
            public string CommandName
            {
                get { throw new NotImplementedException(); }
            }
     
            public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters)
            {
                throw new NotImplementedException();
            }
     
            public bool IsContainer
            {
                get { throw new NotImplementedException(); }
            }
     
            public IEnumerable<UBotParameterDefinition> ParameterDefinitions
            {
                get { throw new NotImplementedException(); }
            }
     
            public UBotVersion UBotVersion
            {
                get { throw new NotImplementedException(); }
            }
        }
    }
  5. Create a private member variable _parameters as a List<UBotParameterDefinition>. Then, create a constructor for your command. Your script should now look like:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using UBotPlugin;
     
    namespace MyFirstPlugin
    {
        public class MyFirstCommand : IUBotCommand
        {
            private List<UBotParameterDefinition> _parameters = new List<UBotParameterDefinition>();
     
            public MyFirstCommand()
            {
     
            }
     
            public string Category
            {
                get { throw new NotImplementedException(); }
            }
     
            public string CommandName
            {
                get { throw new NotImplementedException(); }
            }
     
            public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters)
            {
                throw new NotImplementedException();
            }
     
            public bool IsContainer
            {
                get { throw new NotImplementedException(); }
            }
     
            public IEnumerable<UBotParameterDefinition> ParameterDefinitions
            {
                get { throw new NotImplementedException(); }
            }
     
            public UBotVersion UBotVersion
            {
                get { throw new NotImplementedException(); }
            }
        }
    }
  6. Inside the constructor we are going to define the parameters our command uses. Our command is going to take the user's name as input, and display a message "Hello, name", where name is the name they entered. Since our command takes the input of the user's name, we will add one parameter Name, of type String to our _parameters list. Your constructor should now look like:
    public MyFirstCommand()
    {
        _parameters.Add(new UBotParameterDefinition("Name", UBotType.String));
    }
  7. Next, we are going to define the category this command will be in. Since we want this command to be in the Action Commands category we will modify the Category property to return "Action Commands".
    public string Category
    {
        get { return "Action Commands"; }
    }
  8. Now we are going to define the command name. This is the name we will see in the toolbox when we want to use our name. The convention is to use all lowercase letters. Set the CommandName property to return "hello".
    public string CommandName
    {
        get { return "hello"; }
    }
  9. Next is the Execute method. This method is called when a user runs your command inside of UBot Studio. It is sent an instance of an IUBotStudio interface which can be used for getting and setting values of variables, lists and tables. For this tutorial we are going to ignore this. The second parameter contains the parameters that were passed from UBot Studio to our command. This is where we will be able to access the name the user typed. We can access the value by referencing parameters["Name"] since we defined our parameter as "Name" above. We will use this value along with a MessageBox.Show command to show a message "Hello name".
    public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters)
    {
        string name = parameters["Name"];
        System.Windows.MessageBox.Show("Hello " + name);
    }
  10. The IsContainer property should be next. Since this command will not have other commands contained inside of it, we will set it to false.
    public bool IsContainer
    {
        get { return false; }
    }
  11. Next, the ParameterDefinitions property needs to return the _parameters list we defined above.
    public IEnumerable<UBotParameterDefinition> ParameterDefinitions
    {
        get { return _parameters; }
    }
  12. Finally, the UBotVersion property needs to return the version that this command should be available in. If you are using commands that are only available in UBot Studio Professiona/Developer editions, then you should choose your version accordingly. For this example we will choose Standard.
    public UBotVersion UBotVersion
    {
        get { return UBotVersion.Standard; }
    }
  13. Your finished script should now look like:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using UBotPlugin;
     
    namespace MyFirstPlugin
    {
        public class MyFirstCommand : IUBotCommand
        {
            private List<UBotParameterDefinition> _parameters = new List<UBotParameterDefinition>();
     
            public MyFirstCommand()
            {
                _parameters.Add(new UBotParameterDefinition("Name", UBotType.String));
            }
     
            public string Category
            {
                get { return "Action Commands"; }
            }
     
            public string CommandName
            {
                get { return "hello"; }
            }
     
            public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters)
            {
                string name = parameters["Name"];
                System.Windows.MessageBox.Show("Hello " + name);
            }
     
            public bool IsContainer
            {
                get { return false; }
            }
     
            public IEnumerable<UBotParameterDefinition> ParameterDefinitions
            {
                get { return _parameters; }
            }
     
            public UBotVersion UBotVersion
            {
                get { return UBotVersion.Standard; }
            }
        }
    }

Testing In UBot Studio

  1. From the Main Menu choose Debug->Build Solution. This will create the library dll file that you can use in UBot Studio. (Screenshot)
  2. Open up UBot Studio, and from the Main Menu choose Tools->Plugins. (Screenshot)
  3. Click the Add... button and choose the plugin dll you built. This should be located in the project path specified in Creating The Project - Step 8, inside the following directory: MyFirstPlugin/bin/Debug/MyFirstPlugin.dll. (Screenshot)
  4. Close the Plugins dialog box.
  5. Open the toolbox, and expand the Action Commands group. You should see your hello command there. (Screenshot)
  6. Drag the hello command into your script, fill out the Name parameter, and click run. You should see Hello name pop up in a MessageBox. (Screenshot)
  7. Congratulations, you've now successfully created your first plugin. Keep in mind, when you update your plugin, you will need to complete steps 1-4 of the Testing In UBot Studio section of this tutorial each time.

Unreviewed Plugins

Submitting A Plugin For Review

When you create a new plugin it will show up in UBot Studio as unreviewed. In order to have your plugin reviewed, you must submit a ticket to http://support.ubotstudio.com. You may be emailed and asked to provide more information. Once approved, you will receive a plugin key.

Using A Plugin Key

Once you have your plugin key, you need to add a PluginInfo class into your plugin with a HashCode property that returns your plugin key.

public class PluginInfo
{
    public static string HashCode { get { return "Put your plugin key here"; } }
}

After recompiling your plugin, it should no longer show up as unreviewed in the list of plugins.

Plugin Interfaces

IUBotCommand

/// <summary>
/// This interface is for implementing UBot Studio commands in a plugin.
/// </summary>
public interface IUBotCommand
{
    /// <summary>
    /// The name of the command as it will displayed in the UBot Studio toolbox.
    /// This should be lowercase to match the other commands.
    /// </summary>
    string CommandName { get; }
    /// <summary>
    /// The category the command should be placed in.
    /// If you name a category not already in the toolbox, a new category will be created.
    /// </summary>
    string Category { get; }
    /// <summary>
    /// The parameters the command takes when used in UBot Studio.
    /// </summary>
    IEnumerable<UBotParameterDefinition> ParameterDefinitions { get; }
    /// <summary>
    /// This method is called when UBot Studio executes your command when a user runs a script.
    /// </summary>
    /// <param name="ubotStudio">A reference to UBot Studio that allows you do things such as get and set variables.</param>
    /// <param name="parameters">A dictionary where the key is the parameter name defined in the ParameterDefinitions above, and the value is the value given in UBot Studio.</param>
    void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters);
    /// <summary>
    /// Whether or not your command allows other commands to be dragged inside of it.
    /// </summary>
    bool IsContainer { get; }
    /// <summary>
    /// The version of UBot Studio that this command is available to.
    /// </summary>
    UBotVersion UBotVersion { get; }
}

IUBotFunction

/// <summary>
/// This interface is for implementing UBot Studio functions in a plugin.
/// </summary>
public interface IUBotFunction
{
    /// <summary>
    /// The name of the function as it will displayed in the UBot Studio toolbox.
    /// This should be lowercase and start with $ to match the other commands.
    /// </summary>
    string FunctionName { get; }
    /// <summary>
    /// This property is accessed after Execute is called, and should return the value of your function.
    /// </summary>
    object ReturnValue { get; }
    /// <summary>
    /// The type that your function returns. Supported types are strings and lists.
    /// </summary>
    UBotType ReturnValueType { get; }
    /// <summary>
    /// The category the function should be placed in.
    /// If you name a category not already in the toolbox, a new category will be created.
    /// </summary>
    string Category { get; }
    /// <summary>
    /// This method is called when UBot Studio executes your command when a user runs a script.
    /// </summary>
    /// <param name="ubotStudio">A reference to UBot Studio that allows you do things such as get and set variables.</param>
    /// <param name="parameters">A dictionary where the key is the parameter name defined in the ParameterDefinitions above, and the value is the value given in UBot Studio.</param>
    IEnumerable<UBotParameterDefinition> ParameterDefinitions { get; }
    /// <summary>
    /// This method is called when UBot Studio executes your function when a user runs a script.
    /// </summary>
    /// <param name="ubotStudio">A reference to UBot Studio that allows you do things such as get and set variables.</param>
    /// <param name="parameters">A dictionary where the key is the parameter name defined in the ParameterDefinitions above, and the value is the value given in UBot Studio.</param>
    void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters);
    /// <summary>
    /// The version of UBot Studio that this command is available to.
    /// </summary>
    UBotVersion UBotVersion { get; }
}

IUBotStudio

/// <summary>
/// An instance of this interface is passed to Execute to allow you to do such things as get and set variables.
/// </summary>
public interface IUBotStudio
{
    /// <summary>
    /// This method allows you to ask UBot Studio to run specific code view scripts.
    /// </summary>
    /// <param name="script">The code view script to run.</param>
    void RunScript(string script);
    /// <summary>
    /// This method allows you to ask UBot Studio to change the current interface.
    /// </summary>
    /// <param name="name">The name of the interface to change to, such as Browser.</param>
    void ChangeUserInterface(string name);
    /// <summary>
    /// This property will return the parent IUBotCommand if your command is inside of a container command.
    /// </summary>
    IUBotCommand ContainerParent { get; set; }
    /// <summary>
    /// This method allows you to ask UBot Studio to run the commands contained in the current command if it is a container.
    /// </summary>
    void RunContainerCommands();
    /// <summary>
    /// This method will set a variable in UBot Studio.
    /// </summary>
    /// <param name="variableName">The name of the variable, such as #variable.</param>
    /// <param name="value">The value to set the variable.</param>
    void SetVariable(string variableName, string value);
    /// <summary>
    /// This method will set a list in UBot Studio.
    /// </summary>
    /// <param name="listName">The name of the list, such as %list.</param>
    /// <param name="value">The value to set the list.</param>
    void SetList(string listName, List<string> value);
    /// <summary>
    /// This method will set a table in UBot Studio
    /// </summary>
    /// <param name="tableName">The name of the table, such as &table.</param>
    /// <param name="value">The value to set the table.</param>
    void SetTable(string tableName, string[,] value);
    /// <summary>
    /// Gets the value of a variable in UBot Studio.
    /// </summary>
    /// <param name="variableName">The name of the variable, such as #variable.</param>
    /// <returns>The value of the variable.</returns>
    string GetVariable(string variableName);
    /// <summary>
    /// Gets the value of a list in UBot Studio.
    /// </summary>
    /// <param name="listName">The name of the list, such as %list.</param>
    /// <returns>The value of the list.</returns>
    List<string> GetList(string listName);
    /// <summary>
    /// Gets the value of a table in UBot Studio.
    /// </summary>
    /// <param name="tableName">The name of the table, such as &table.</param>
    /// <returns>The value of the table.</returns>
    string[,] GetTable(string tableName);
}

IWizard

/// <summary>
/// This interface should be implemented for each wizard window you create.
/// </summary>
public interface IWizard
{
    /// <summary>
    /// This property should return an instance of a WPF Window that displays your wizard.
    /// </summary>
    Window WizardWindow { get; }
    /// <summary>
    /// This property should access your WPF Window to return the results of what the user typed into the wizard.
    /// The keys should be the parameter name you want to fill out, and the values should be the values the user entered in the wizard.
    /// </summary>
    Dictionary<string, string> WizardValues { get; }
}

IWizardEnabled

/// <summary>
/// This interface can be used with an IUBotCommand or IUBotFunction.
/// It allows you to add a wizard to your command.
/// </summary>
public interface IWizardEnabled
{
    /// <summary>
    /// This method is called when dragging a command with a wizard into a script, or from clicking the Wizard button for a command.
    /// </summary>
    /// <returns>You should return a new instance of an IWizard that you have defined.</returns>
    IWizard GenerateWizard();
}

IEventEnabled

/// <summary>
/// This interface can be used with an IUBotCommand or IUBotFunction.
/// It allows you to setup event listeners for things like global hotkeys while the bot is running.
/// </summary>
public interface IEventEnabled
{
    /// <summary>
    /// This method is called when a user clicks the Run button on a bot.
    /// </summary>
    void StartEventListener();
    /// <summary>
    /// This method is called when the bot is stopped or finishes.
    /// </summary>
    void StopEventListener();
}

UBotParameterDefinition

/// <summary>
/// A definition for a plugin parameter.
/// </summary>
public class UBotParameterDefinition
{
    /// <summary>
    /// The name of the parameter. This is displayed in UBot Studio above the value textbox.
    /// </summary>
    public string Name { get; private set; }
    /// <summary>
    /// The type of the parameter, such as string, variable, list or table.
    /// </summary>
    public UBotType Type { get; private set; }
    /// <summary>
    /// This can be used to define a list of values that the user can select from with a dropbox.
    /// </summary>
    public IEnumerable<string> Options { get; set; }
    /// <summary>
    /// This can be used to define a default parameter value when the user drags a node into their script.
    /// </summary>
    public object DefaultValue { get; set; }
 
    public UBotParameterDefinition(string name, UBotType type)
    {
        Name = name;
        Type = type;
    }
}

UBotType

/// <summary>
/// This is used when defining parameters and correlates to the types of UBot variables.
/// </summary>
public enum UBotType
{
    String,
    UBotVariable,
    UBotList,
    UBotTable
}

Plugin Examples

You can download all of the examples listed below at: http://www.ubotstudio.com/files/plugins/PluginExamples.zip

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>(); }
        }
 
        public UBotVersion UBotVersion
        {
            // This is the lowest version of UBot Studio that this command can run in.
            get { return UBotVersion.Standard; }
        }
    }
}

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; }
        }
 
        public UBotVersion UBotVersion
        {
            // This is the lowest version of UBot Studio that this command can run in.
            get { return UBotVersion.Standard; }
        }
    }
}

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; }
        }
 
        public UBotVersion UBotVersion
        {
            // This is the lowest version of UBot Studio that this function can run in.
            get { return UBotVersion.Standard; }
        }
    }
}

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; }
        }
 
        public UBotVersion UBotVersion
        {
            // This is the lowest version of UBot Studio that this function can run in.
            get { return UBotVersion.Standard; }
        }
    }
}

Function With List Parameters

This is an example of a command that takes a list parameter. It randomly shuffles the list and returns it as the result.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UBotPlugin;
 
namespace SimpleCommands
{
    /// <summary>
    /// This command is an example of a command using list parameters.
    /// It shuffles the input list sent to it..
    /// Parameters: The hexadecimal color to use to display the window.
    /// </summary>
    public class ShuffleListFunction : IUBotFunction
    {
        // List to hold the parameters we define for our command.
        private List<UBotParameterDefinition> _parameters = new List<UBotParameterDefinition>();
        private List<string> _returnValue;
 
        public ShuffleListFunction()
        {
            // Add our parameter (List To Shuffle) with a UBotList type since it is a list.
            _parameters.Add(new UBotParameterDefinition("List To Shuffle", UBotType.UBotList));
        }
 
        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 "Variable Functions"; }
        }
 
        public string FunctionName
        {
            // The name of our node in UBot Studio.
            // You need to use a $ sign in front of function names.
            get { return "$shuffle list"; }
        }
 
        public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters)
        {
            // Get the name of the list they are using.
            var listName = parameters["List To Shuffle"];
 
            // Get the list items from the list by using the list variable name.
            var list = ubotStudio.GetList(listName);
 
            // Shuffle the list
            var randomGenerator = new Random();
            list = list.OrderBy(x => randomGenerator.Next()).ToList();
 
            // Set the return value to the shuffled list.
            _returnValue = list;
        }
 
        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 a list, so the return value type is UBotList.
            get { return UBotType.UBotList; }
        }
 
        public UBotVersion UBotVersion
        {
            // This is the lowest version of UBot Studio that this function can run in.
            get { return UBotVersion.Standard; }
        }
    }       
}

Command With Table Parameters

This is an example of a command that uses a table parameter. It will download the response headers from a URL and store the results in a table. It has two parameters: URL, and Table.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UBotPlugin;
using System.Net;
 
namespace SimpleCommands
{
    /// <summary>
    /// This command is an example of a command with a table parameter.
    /// It will download the response headers from a URL and store them in a table.
    /// Parameters: The URL to download the headers from.
    /// </summary>
    public class CreateTableFromHeadersCommand : IUBotCommand
    {
        // List to hold the parameters we define for our command.
        private List<UBotParameterDefinition> _parameters = new List<UBotParameterDefinition>();
 
        public CreateTableFromHeadersCommand()
        {
            // Add our parameter (URL) with a String type since it is text.
            _parameters.Add(new UBotParameterDefinition("URL", UBotType.String));
 
            // Add our parameter (Table) with a UBotTable type since it is a table.
            _parameters.Add(new UBotParameterDefinition("Table", UBotType.UBotTable));
        }
 
        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 "create table from headers"; }
        }
 
        public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters)
        {
            // Grab the value of the parameter we defined.
            string url = parameters["URL"];
 
            // Get the name of the table they are using.
            string tableName = parameters["Table"];
 
            // Create an HttpWebRequest for the specified URL. 
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
 
            // Set method to HEAD since we only want the headers.
            request.Method = "HEAD";
 
            // Send the HttpWebRequest and wait for the response, closing it when done.
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                // Create a table to store the headers returned.
                string[,] table = new string[response.Headers.Count, 2];
 
                for (int i = 0; i < response.Headers.Count; i++)
                {
                    // Store the header name in column 0 for the current row.
                    table[i, 0] = response.Headers.Keys[i];
                    // Store the header value in column 1 for the current row.
                    table[i, 1] = response.Headers[i];
                }
 
                // Set the new table in UBot Studio for the table name given.
                ubotStudio.SetTable(tableName, table);
            }
        }
 
        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 UBotVersion UBotVersion
        {
            // This is the lowest version of UBot Studio that this command can run in.
            get { return UBotVersion.Standard; }
        }
    }
}

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
            // We 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; }
        }
 
        public UBotVersion UBotVersion
        {
            // This is the lowest version of UBot Studio that this command can run in.
            get { return UBotVersion.Standard; }
        }
    }
}

Wizard Commands

This is an example of a command that uses a wizard along with displaying a WPF window when it is executed. The command uses a wizard to allow a user to choose a color with a color picker. It then displays a WPF window with the background set to that color.

For information on the WPF windows used in this example, download the Example Files.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UBotPlugin;
using System.Windows.Media;
using System.Windows;
using System.Windows.Threading;
 
namespace WizardCommands
{
    /// <summary>
    /// This command is an example of a command with a wizard.
    /// It will show a window with a background color that you choose.
    /// Parameters: The hexadecimal color to use to display the window.
    /// </summary>
    public class ColoredWindowCommand : IUBotCommand, IWizardEnabled
    {
        // List to hold the parameters we define for our command.
        private List<UBotParameterDefinition> _parameters = new List<UBotParameterDefinition>();
 
        // This holds our wizard Window.
        private ColorPickerWizardWindow _wizardWindow;
 
        public ColoredWindowCommand()
        {
            // Add our parameter (Color) with a String type since it is text.
            _parameters.Add(new UBotParameterDefinition("Color", 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 "colored window"; }
        }
 
        public void Execute(IUBotStudio ubotStudio, Dictionary<string, string> parameters)
        {
            // Grab the value of the Color parameter we defined.
            string value = parameters["Color"];
 
            // Create a colored window and set the background color to the color they choose.
            var window = new ColoredWindow();
            window.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#" + value));
 
            // Display the colored window.
            window.ShowDialog();
        }
 
        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 IWizard GenerateWizard()
        {
            return new ColoredWindowWizard();
        }
 
        public UBotVersion UBotVersion
        {
            // This is the lowest version of UBot Studio that this command can run in.
            get { return UBotVersion.Standard; }
        }
    }
 
    /// <summary>
    /// This wizard contains a color picker control that allows a user to choose a color by clicking it.
    /// </summary>
    public class ColoredWindowWizard : IWizard
    {
        private ColorPickerWizardWindow _wizardWindow = new ColorPickerWizardWindow();
 
        public Dictionary<string, string> WizardValues
        {
            // This property is checked after the wizard is displayed.
            // We return a Dictionary of values corresponding to the parameters.
            get
            {
                var parameterValues = new Dictionary<string, string>();
                // We use our _wizardWindow reference to access the color they selected in the wizard.
                // We then add that color value to our list of parameter values from our wizard.
                parameterValues["Color"] = _wizardWindow.MainColorPicker.SelectedColor.ToString().Substring(1);
                return parameterValues;
            }
        }
 
        public Window WizardWindow
        {
            // This property is accessed to determine which window to display for the wizard.
            get
            {
                return _wizardWindow;
            }
        }
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox