|
|
Using a BlueSky Integration Studio Job Component in your .NET application |
(For a complete description of all the properties and methods your job component supplies, see About Job Components) |
BlueSky Integration Studio gives you the capability to compile your jobs to .NET components! A component is a .dll that you can reference from you own custom .NET applications including VB.NET, C# and ASP.NET. Creating a component is just as easy as creating an executable, you simply click the Build->Component menu option instead. The job will compile the same way, only it will compile to a local .dll component instead of a .exe file on the server.
Once the component is compiled you will be prompted for a location to copy the component to. There could be several dependency files, as well as the job component itself. Copy these files into your application directory, reference the job component and you have instant access to all of its functionality!
Let's walk through a simple example.
1. Supposed you design a job that exports your Budget table to a text file. Once your job design is complete, click on the Build->Component menu option (or click the Build Component icon on the toolbar).
2. Once the compiler has completed building the component you will be prompted to select a directory where you want the files to be downloaded. The compilation process is actually performed by the BlueSky Integration Studio Server. Select a directory (usually your application's directory) and Click OK.
3. Open your .NET project or solution and add a reference to your application to the job component. In this example, the job component file name would be ExportBudgetJob.dll. In Visual Studio®, you will select the Project->Add Reference menu option, then click the Browse button and select the job component file.
4. Now that you have successfully referenced the job component, you can create an instance of the object and begin using it. BlueSky Integration Studio job components have built in properties and methods that make it easy to interact with the job component. The first thing to do is to add an Import or using statement. The namespace for the job components default to VisualIntegrationStudio.<appdomain>. The <appdomain> is the BlueSky Integration Studio application domain where the job was originally designed.
[Visual Basic .NET]
Imports VisualIntegrationStudio.SharedDomain
[C#]
using VisualIntegrationStudio.SharedDomain;
5. The easiest way to run a job is to simply create an instance of the job component and call the RunJob method.
[Visual Basic .NET]
Public Sub RunMyJob() |
Dim js As ExportBudget.CRJobStatus |
Dim myExportBudgetJob As ExportBudget |
|
myExportBudgetJob = New ExportBudget() |
myExportBudgetJob.JobPaths.JobStatusFileName = "ExportJobStatus.xml" |
myExportBudgetJob.RunJob() |
|
js = myExportBudgetJob.GetJobStatus() |
|
If Not (js Is Nothing) Then |
MsgBox("Job is done, Status: " + js.JobStatus.ToString) |
Else |
MsgBox("Job is done") |
End If |
|
End Sub |
|
[C#]
private void RunMyJob() |
{ |
ExportBudget.CRJobStatus js; |
ExportBudget myExportBudgetJob; |
|
myExportBudgetJob = new ExportBudget(); |
myExportBudgetJob.JobPaths.JobStatusFileName = "ExportJobStatus.xml"; |
myExportBudgetJob.RunJob(); |
|
js = myExportBudgetJob.GetJobStatus(); |
|
if (js != null) |
{ |
MessageBox.Show("Job is done, Status: " + js.JobStatus.ToString()); |
} |
else |
{ |
MessageBox.Show("Job is done"); |
} |
|
} |
|
That's it! Compile your job and run it.
Running the job in the background
You can also run your job in the background by calling the RunJobThreaded method, instead of the RunJob method. The RunJobThreaded method will run the job and continue on with your code. To know when your job is done, simply add a handler to the JobCompleted event, or you can check the status in timer event by calling the GetJobStatus method
Below is the same program as above, however this time it will be run in the background using the RunJobThreaded method. Note some of the core changes, the instance of the object is created in the scope of the class so it doesn't get cleaned up by the garbage collector or go out of scope of the function running it.
[Visual Basic .NET]
Imports VisualIntegrationStudio.SharedDomain |
|
Public Class Form1 |
Inherits System.Windows.Forms.Form |
|
Private myExportBudgetJob As ExportBudget |
|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load |
myExportBudgetJob = New ExportBudget() |
myExportBudgetJob.JobPaths.JobStatusFileName = "ExportJobStatus.xml" |
|
AddHandler myExportBudgetJob.JobCompleted, AddressOf JobIsDone |
End Sub |
|
Private Sub btnRunJob_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRunJob.Click |
myExportBudgetJob.RunJobThreaded() |
End Sub |
|
Private Sub JobIsDone(ByVal obj As Object) |
|
If Not (obj Is Nothing) Then |
MsgBox("Job is done, Status: " + CType(obj, ExportBudget.ReturnStatusTypes).ToString) |
Else |
MsgBox("Job is done") |
End If |
|
End Sub |
|
End Class |
|
[C#]
|
using System; |
|
using System.Drawing; |
|
using System.Collections; |
|
using System.ComponentModel; |
|
using System.Windows.Forms; |
|
using System.Data; |
|
using VisualIntegrationStudio.SharedDomain; |
|
|
|
namespace MyApplicationCs |
|
{ |
|
public class Form1 : System.Windows.Forms.Form |
|
{ |
|
private System.Windows.Forms.Button btnRunJob; |
|
private System.ComponentModel.Container components = null; |
|
|
|
private ExportBudget myExportBudgetJob; |
|
|
|
public Form1() |
|
{ |
|
InitializeComponent(); |
|
} |
|
|
|
protected override void Dispose( bool disposing ) |
|
{ |
|
if( disposing ) |
|
{ |
|
if (components != null) |
|
{ |
|
components.Dispose(); |
|
} |
|
} |
|
base.Dispose( disposing ); |
|
} |
|
|
|
[STAThread] |
|
static void Main() |
|
{ |
|
Application.Run(new Form1()); |
|
} |
|
|
|
private void Form1_Load(object sender, System.EventArgs e) |
|
{ |
|
myExportBudgetJob = new ExportBudget(); |
|
myExportBudgetJob.JobPaths.JobStatusFileName = "ExportJobStatus.xml"; |
|
|
|
myExportBudgetJob.JobCompleted += new ExportBudget.JobCompletedEventHandler(JobIsDone); |
|
} |
|
|
|
private void btnRunJob_Click(object sender, System.EventArgs e) |
|
{ |
|
myExportBudgetJob.RunJobThreaded(); |
|
} |
|
|
|
private void JobIsDone(object obj, System.EventArgs e) |
|
{ |
|
MessageBox.Show("Job is done, Status: " + ((ExportBudget.ReturnStatusTypes)obj).ToString()); |
|
} |
|
|
|
} |
|
} |
|
|
© 2003 - 2007 Relational Solutions, Inc. - All rights reserved