Jobs client
The Scripting SDK provides a Jobs client to perform CRUD operations on entities.
To help you update code from the Entities client to the Jobs client, we provide several examples.
GetTargetsAsync
This method retrieves the targets for a job and supports the JobTargetQuery
request parameter. This parameter is the job target query request and represents a request for job targets with various filtering options. It allows you to specify criteria to narrow down the job targets you are interested in.
The properties supported by this method are listed in the following table.
Property |
Type |
Description |
---|---|---|
|
long |
The unique ID of the job. |
|
string |
The state of the job target (optional). This can be used to filter targets based on their current state. |
|
string |
The condition of the job target (optional). This can be used to filter targets based on specific conditions. |
|
string |
The type of the job target (optional). This can be used to filter targets based on their type. |
|
string |
The location of the job target (optional). This can be used to filter targets based on their geographical location. |
|
int |
The number of records to skip. This is useful for pagination. |
|
int |
The number of records to take. This is useful for pagination. The default value is 25. |
|
CultureInfo[] |
The cultures information to load the entity (optional). If no cultures are provided, multi-language properties won't be included. The default value is an array containing |
In the following example, the JobTargetQuery
is used to request job targets for a specific job (JobId = 123
) with various filters applied, such as state, condition, type, and location. The query will skip 0 records and take 50 records, and it will include multi-language properties for English (US) and French (FR) cultures.
var jobTargetQuery = new JobTargetQuery(123)
{
State = "Waiting",
Condition = "Pending",
Type = "System",
Location = "67890",
Skip = 0,
Take = 50,
Cultures = new[] { new CultureInfo("en-US"), new CultureInfo("fr-FR") }
};
This example calls the client method.
using Stylelabs.M.Sdk.Contracts.Jobs;
var jobTargetQuery = new JobTargetQuery(123)
{
State = "Waiting",
Skip = 0,
Take = 10
};
IEntityCollectionResult targets = await MClient.Jobs.GetTargetsAsync(jobTargetQuery);
The method returns the collection of job targets Task<IEntityCollectionResult>
. . The following exceptions can occur:
-
ArgumentNullException
- if the request isnull
. -
ArgumentOutOfRangeException
- if therequest.Take
or therequest.Skip
values are negative numbers, or the request.JobId is not a valid ID. -
ArgumentException
- if any request.cultures are null or the job entity is not found.
GetTargetAsync
This method retrieves a specific target for a job.
The properties supported by this method are listed in the following table.
Property |
Type |
Description |
---|---|---|
|
long |
The unique ID of the job. |
|
long |
The target ID. |
|
CultureInfo[] |
The cultures information to load the entity (optional). If no cultures are provided, multi-language properties won't be included. The default value is an array containing CultureInfo.InvariantCulture. |
In the following example,
IEntity description = await MClient.Jobs.GetTargetAsync(jobId, targetId);
The method returns the specific target entity Task<IEntity>
. The following exceptions can occur:
-
ArgumentException
- if theJobId
orTargetId
are not valid. -
WebApiException
- if the HTTP request fails.
SaveTargetAsync
This method creates or updates a target for a job. It supports the following parameters.
Parameter |
Type |
Description |
---|---|---|
|
long |
The job ID. |
|
IEntity |
The target entity. |
The method returns the ID of the saved target Task<long>
. The following exceptions can occur:
-
ArgumentNullException
- if the target isnull
. -
ArgumentException
- if the job entity is not found. -
ArgumentOutOfRangeException
- if the job ID is not a valid ID.
Use the following syntax with this method.
long targetId = await MClient.Jobs.SaveTargetAsync(123, targetEntity);
DeleteTargetAsync
This method deletes a target for a job. It supports the following parameters:
Parameter |
Type |
Description |
---|---|---|
|
long |
The job ID. |
|
long |
The target ID. |
The method returns a task that represents the asynchronous operation. The following exceptions can occur:
-
ArgumentException
- if the job ID or target ID are invalid. -
ArgumentOutOfRangeException
- if the job ID or target ID are not a valid IDs.
Use the following syntax with this method.
await MClient.Jobs.DeleteTargetAsync(123, 456);
GetDescriptionAsync
This method retrieves the description of a job. It supports the following parameters:
Parameter |
Type |
Description |
---|---|---|
|
long |
The job ID. |
|
CultureInfo[] |
Optional cultures for the description. |
The method returns the job description entity Task<IEntity>
. The following exceptions can occur:
-
ArgumentException
- if the job ID is invalid. -
ArgumentOutOfRangeException
- if the job ID is not a valid ID.
Use the following syntax with this method.
IEntity jobDescription = await MClient.Jobs.GetDescriptionAsync(123);
SaveDescriptionAsync
This method creates or updates the description of a job. It supports the following parameters:
Parameter |
Type |
Description |
---|---|---|
|
long |
The job ID. |
|
IEntity |
The job description entity. |
The method returns the ID of the saved job description Task<long>
. The following exceptions can occur:
-
ArgumentNullException
- if the job description is null. -
ArgumentException
- if the job ID or job description ID is invalid. -
ArgumentOutOfRangeException
- if the if the job ID is not a valid ID.
Use the following syntax with this method.
long descriptionId = await MClient.Jobs.SaveDescriptionAsync(123, jobDescriptionEntity);
DeleteDescriptionAsync
This method deletes the description of a job. It supports the following parameter.
Parameter |
Type |
Description |
---|---|---|
|
long |
The job ID. |
The method returns a task representing the asynchronous operation. The following exceptions can occur:
-
ArgumentException
- if the job or description entities are not found. -
ArgumentOutOfRangeException
- if the job ID is not a valid ID.
Use the following syntax with this method.
await MClient.Jobs.DeleteDescriptionAsync(123);