←Select platform

AddJobs Method

Summary

Adds a batch of jobs to the JobProcessor database by calling the IJobService WCF Service.

Syntax

C#
VB
C++
[FaultContractAttribute(System.Type)] 
[OperationContractAttribute()] 
public AddJobsResponse AddJobs( 
   AddJobsRequest request 
) 
  
<FaultContractAttribute(DetailType=Leadtools.Services.JobProcessor.FaultContracts.CloudFault,  
   Action="",  
   Name="",  
   Namespace="",  
   ProtectionLevel=ProtectionLevel.None,  
   HasProtectionLevel=False)> 
<OperationContractAttribute()> 
Function AddJobs( _ 
   ByVal request As Leadtools.Services.Jobprocessor.Datacontracts.AddJobsRequest _ 
) As Leadtools.Services.Jobprocessor.Datacontracts.AddJobsResponse 
[FaultContractAttribute(DetailType=Leadtools.Services.JobProcessor.FaultContracts.CloudFault,  
   Action="",  
   Name="",  
   Namespace="",  
   ProtectionLevel=ProtectionLevel.None,  
   HasProtectionLevel=false)] 
[OperationContractAttribute()] 
Leadtools.Services.Jobprocessor.Datacontracts.AddJobsResponse^ AddJobs(  
   Leadtools.Services.Jobprocessor.Datacontracts.AddJobsRequest^ request 
)  

Parameters

request
An Leadtools.Services.JobProcessor.DataContracts.AddJobsRequest class for the jobs to add.

Return Value

An Leadtools.Services.JobProcessor.DataContracts.AddJobsResponse class containing information for the added jobs.

Remarks

Use this method to add a batch of jobs to the Job Processor database using a single call to the server WCF service. The Leadtools.Services.JobProcessor.DataContracts.AddJobsResponse class will contain the ID's (GUID's) of the added jobs. To add a single job, use AddJob.

Example

C#
VB
using LeadtoolsJobProcessorExamples.JobService; 
 
 
//This method will be used to store the conversion settings (how the file should be converted). 
//We will serialize it at the, and the worker assembly will deserialize it to obtain the settings. 
public struct JobMetadata 
{ 
   public string SourceFile; 
   public string TargetFile; 
   public string Format; 
 
   public JobMetadata(string _sourceFile, string _targetFile, string _format) 
   { 
      SourceFile = _sourceFile; 
      TargetFile = _targetFile; 
      Format = _format; 
   } 
} 
 
//Serialize the job metadata to an xml string so it can be stored in the JobProcessor database, 
//and deserialized later by the worker assembly when the job is processed. 
public string SerializeToString(JobMetadata jobMetadata) 
{ 
   //Serialize the job metadata to an xml string so it can be stored in the JobProcessor database, 
   //and deserialized later by the worker assembly when the job is processed. 
   using (StringWriter sw = new StringWriter()) 
   { 
      XmlSerializer xmlSerializer = new XmlSerializer(typeof(JobMetadata)); 
      xmlSerializer.Serialize(sw, jobMetadata); 
      return sw.ToString(); 
   } 
} 
 
public void AddJobs(JobMetadata[] jobMetadataList) 
{ 
   AddJobsRequest addJobRequestList = new AddJobsRequest(); 
   foreach (JobMetadata jobMetadata in jobMetadataList) 
   { 
      AddJobRequest addJobRequest = new AddJobRequest(); 
      addJobRequest.UserToken = "User1"; 
      //The job metadata describes how the job should be converted. For this example, we will assume the worker assembly 
      //will convert image files from one format to another. We will create a struct (JobMetadata) to hold the conversion 
      //information, serialize it to a string, and add it as the job metadata. In a typical scenario, the worker assembly 
      //would receive the job metadata, deserialize it, and convert the file based on the properties in the JobMetadata 
      //struct. 
      addJobRequest.JobMetadata = SerializeToString(jobMetadata); 
      addJobRequest.JobType = "ConvertToPDF"; 
 
      //Add to the list 
      addJobRequestList.Add(addJobRequest); 
   } 
 
   if (addJobRequestList.Count == 0) 
      return; 
 
   using (JobServiceClient jobServiceClient = new JobServiceClient()) 
   { 
      AddJobsResponse addJobsResponse = jobServiceClient.AddJobs(addJobRequestList); 
      foreach (string jobID in addJobsResponse.Ids) 
      { 
         if (!String.IsNullOrEmpty(jobID)) 
            Console.WriteLine(String.Format("The ID of the new job is {0}", jobID)); 
      } 
   } 
} 
 
'This method will be used to store the conversion settings (how the file should be converted). 
'We will serialize it at the, and the worker assembly will deserialize it to obtain the settings. 
Public Structure JobMetadata 
   Public SourceFile As String 
   Public TargetFile As String 
   Public Format As String 
 
   Public Sub New(ByVal _sourceFile As String, ByVal _targetFile As String, ByVal _format As String) 
      SourceFile = _sourceFile 
      TargetFile = _targetFile 
      Format = _format 
   End Sub 
End Structure 
 
'Serialize the job metadata to an xml string so it can be stored in the JobProcessor database, 
'and deserialized later by the worker assembly when the job is processed. 
Public Function SerializeToString(ByVal jobMetadata As JobMetadata) As String 
   'Serialize the job metadata to an xml string so it can be stored in the JobProcessor database, 
   'and deserialized later by the worker assembly when the job is processed. 
   Using sw As StringWriter = New StringWriter() 
      Dim xmlSerializer As XmlSerializer = New XmlSerializer(GetType(JobMetadata)) 
      xmlSerializer.Serialize(sw, jobMetadata) 
      Return sw.ToString() 
   End Using 
End Function 
 
Public Sub AddJobs(ByVal jobMetadataList As JobMetadata()) 
   Dim addJobRequestList As AddJobsRequest = New AddJobsRequest() 
   For Each jobMetadata As JobMetadata In jobMetadataList 
      Dim addJobRequest As AddJobRequest = New AddJobRequest() 
      addJobRequest.UserToken = "User1" 
      'The job metadata describes how the job should be converted. For this example, we will assume the worker assembly 
      'will convert image files from one format to another. We will create a struct (JobMetadata) to hold the conversion 
      'information, serialize it to a string, and add it as the job metadata. In a typical scenario, the worker assembly 
      'would receive the job metadata, deserialize it, and convert the file based on the properties in the JobMetadata 
      'struct. 
      addJobRequest.JobMetadata = SerializeToString(jobMetadata) 
      addJobRequest.JobType = "ConvertToPDF" 
 
      'Add to the list 
      addJobRequestList.Add(addJobRequest) 
   Next jobMetadata 
 
   If addJobRequestList.Count = 0 Then 
      Return 
   End If 
 
   Using jobServiceClient As JobServiceClient = New JobServiceClient() 
      Dim addJobsResponse As AddJobsResponse = jobServiceClient.AddJobs(addJobRequestList) 
      For Each jobID As String In addJobsResponse.Ids 
         If (Not String.IsNullOrEmpty(jobID)) Then 
            Console.WriteLine(String.Format("The ID of the new job is {0}", jobID)) 
         End If 
      Next jobID 
   End Using 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.