This article will help you connect to the FoxHub application via API. This is very advanced. To help you to get started using FoxHub and understand how the application can help you schedule and orchestrate your bots, please read this article. If you experience any issues while setting up FoxHub or when trying to connect to any bots, please reference the FoxHub Deployment/Troubleshoot Guide available as a link in the middle of this article.
FoxHub API
FoxHub includes an API for programmatic integration. This allows you to harness the power of FoxHub and put your workforce of bots to work. This is an easy way to extend the capabilities of your custom built software. To use the FoxHub API, you must copy the FoxHubAPI.dll file into the directory of your .exe file. The FoxHubAPI.dll file is installed with FoxHub and is a 32-bit DLL which was compiled using Microsoft .Net Framework 4.5.1. Add a reference to this DLL file in your project to gain access to the FoxHubAPI namespace. If you upgrade your FoxHub to a newer version, you will be required to recopy the FoxHubAPI.dll into the directory of your .exe file.
Excel can only reference COM-visible DLLs. The FoxHubAPI.dll is not COM-visible therefore cannot be referenced by Excel. Today, you can only reference the DLL from a .NET-aware programming language (such as VB.Net or C#.Net). We have captured an enhancement request to make the DLL COM-visible.
The following API functions are available:
Function |
Description |
GetBots |
Retrieves the list of bots in FoxHub. |
GetJobStatus |
Retrieves the status of a job in the queue. |
Init |
Initializes communication with FoxHub. |
Login |
Instructs FoxHub to log in using the specified credentials. |
QueueDataJob |
Adds a Data job to the queue. |
QueueSoloJob |
Adds a Solo job to the queue. |
RunJob |
Starts a job in the queue. |
StopJob |
Stops a job in the queue. |
For more details on the individual FoxHub API functions, read this article.
The following Events are available:
Event |
Description |
QueueItemComplete |
Informs when a queued job is completed. |
Code: Step by step
In code, instantiate an object of type FoxHubAPI.CFoxHub and pass in the name of the computer running FoxHub. Make sure that the FoxHubAPI.dll file is copied into the same folder as your executable, and a reference to that file is added in your code.
- Step 1: Create a CFoxHub object
Note: When a FoxHubAPI.CFoxHub object is newed, the FoxHub computer name will be saved for subsequent calls to the API.
C#
//Specify the FoxHub computer name: string strComputerName = "TheComputerName";
//Create the CFoxHub object: FoxHubAPI.CFoxHub objFoxHub = new FoxHubAPI.CFoxHub(strComputerName); |
VB.Net
'Specify the FoxHub computer name: Dim strComputerName As String = "TheComputerName"
'Create the CFoxHub object: Dim objFoxHub As New FoxHubAPI.CFoxHub(strComputerName) |
- Step 2: Initialize
If logins have been turned on in Foxtrot Administrator, you will be required to perform this login step. If logins are not turned on, skip this step.
C#
//Initialize communication with FoxHub: if (objFoxHub.Init() == false) { //Communication with FoxHub failed! return; //Abort and do nothing. } |
VB.Net
'Initialize communication with FoxHub: If (objFoxHub.Init() = False) Then 'Communication with FoxHub failed! Return 'Abort and do nothing. End If |
- Step 3: Log into FoxHub
If logins have been turned on in Foxtrot Administrator, you will be required to perform this login step. If logins are not turned on, skip this step.
C#
//Log into FoxHub: objFoxHub.LogIn("jdoe", "mypassword", ""); |
VB.Net
'Log into FoxHub: objFoxHub.LogIn("jdoe", "mypassword", "mydomain") |
- Step 4: Retrieve List of Bots
Next, retrieve the list of bots that have been added into FoxHub:
C#
//Create a Dictionary object to hold the list of bots: Dictionary<int, string> objBotDict;
//Get the list of bots: objBotDict = objFoxHub.GetBots(); |
VB.Net
'Create a Dictionary object to hold the list of bots: Dim objBotDict As New Dictionary(Of Integer, String)
'Get the list of bots: objBotDict = objFoxHub.GetBots() |
- Step 5: Add Job to the Queue
Now, add the Job to the queue in FoxHub.
C#
//Used to capture the Queue Item ID returned by calling QueueJob(): int intQueueItemID;
//Add the job to the queue. Assign all bots to the job: intQueueItemID = objFoxHub.QueueDataJob("New Job", "C:\MyProject.fox", objBotDict.Keys.ToList(), "C:\MyData.accdb", "", true); |
VB.Net
'Used to capture the Queue Item ID returned by calling QueueJob(): Dim intQueueItemID As Integer = 0
'Add the job to the queue. Assign all bots to the job: intQueueItemID = objFoxHub.QueueDataJob("New Job", "C:\MyProject.fox", objBotDict.Keys.ToList(), "C:\MyData.accdb", "", True) |
- Step 6: Run the Job
Now that the job has been added to the queue in FoxHub, we must run the job:
C#
//Run the job: objFoxHub.RunJob(intQueueItemID); |
VB.Net
'Run the job: objFoxHub.RunJob(intQueueItemID) |
- Step 7: Get Job Status
You can get the status of a job at any time.
C#
int intStatus;
//Retrieve the job's status: intStatus = objFoxHub.GetJobStatus(intQueueItemID); |
VB.Net
Dim intStatus As Integer
//Retrieve the job's status: intStatus = objFoxHub.GetJobStatus(intQueueItemID) |
- Step 8: Clean Up
Be sure to clean up your objects:
C#
//Clean up objects: objBotDict = null; objFoxHub = null; |
VB.Net
'Clean up objects: objBotDict = Nothing objFoxHub = Nothing |
Code: Full Example
Below are full code examples you can copy and paste into a procedure in your development environment:
C#
//Note: Remember to copy the FoxHubAPI.dll file into the same folder as // your executable, then add a reference that file in your code.
//Specify the FoxHub computer name: string strComputerName = "TheComputerName";
//Create the CFoxHub object: FoxHubAPI.CFoxHub objFoxHub = new FoxHubAPI.CFoxHub(strComputerName);
//Initialize communication with FoxHub: if (objFoxHub.Init() == false) { //Communication with FoxHub failed! return; //Abort and do nothing. }
//Log into FoxHub: objFoxHub.LogIn("jdoe", "mypassword", "");
//Create a Dictionary object to hold the list of bots: Dictionary<int, string> objBotDict;
//Get the list of bots: objBotDict = objFoxHub.GetBots();
//Used to capture the Queue Item ID returned by calling QueueJob(): int intQueueItemID;
//Add the job to the queue. Assign all bots to the job: intQueueItemID = objFoxHub.QueueDataJob("New Job", "C:\MyProject.fox", dicBots.Keys.ToList(), "C:\MyData.accdb", "", true);
//Run the job: objFoxHub.RunJob(intQueueItemID);
int intStatus;
//Retrieve the job's status: intStatus = objFoxHub.GetJobStatus(intQueueItemID);
//If needed, check intStatus here and respond accordingly.
//Clean up objects: objBotDict = null; objFoxHub = null; |
VB.Net
'Note: Remember to copy the FoxHubAPI.dll file into the same folder as ' your executable, then add a reference that file in your code.
'Specify the FoxHub computer name: Dim strComputerName As String = "TheComputerName"
'Create the CFoxHub object: Dim objFoxHub As New FoxHubAPI.CFoxHub(strComputerName)
'Initialize communication with FoxHub: If (objFoxHub.Init() = False) Then 'Communication with FoxHub failed! Return 'Abort and do nothing. End If
'Log into FoxHub: objFoxHub.LogIn("jdoe", "mypassword", "")
'Create a Dictionary object to hold the list of bots: Dim objBotDict As New Dictionary(Of Integer, String)
'Get the list of bots: objBotDict = objFoxHub.GetBots()
'Used to capture the Queue Item ID returned by calling QueueJob(): Dim intQueueItemID As Integer = 0
'Add the job to the queue. Assign all bots to the job: intQueueItemID = objFoxHub.QueueDataJob("New Job", "C:\MyProject.fox", objBotDict.Keys.ToList(), "C:\MyData.accdb", "", True)
'Run the job: objFoxHub.RunJob(intQueueItemID)
Dim intStatus As Integer
'Retrieve the job's status: intStatus = objFoxHub.GetJobStatus(intQueueItemID)
'If needed, check intStatus here and respond accordingly.
'Clean up objects: objBotDict = Nothing objFoxHub = Nothing |
Comments
0 comments
Please sign in to leave a comment.