AddJob Method

Summary

Adds a job to the JobProcessor database by calling the IJobService WCF Service.

Syntax
C#
VB
C++
[OperationContractAttribute()] 
[FaultContractAttribute(System.Type)] 
public AddJobResponse AddJob( 
   AddJobRequest request 
) 
<OperationContractAttribute(), 
   FaultContractAttribute(System.Type)> 
 Public Function AddJob( 
   ByVal request As AddJobRequest 
) As AddJobResponse 
public:  
   [OperationContractAttribute] 
   [FaultContractAttribute(System::Type)] 
   AddJobResponse^ AddJob( 
      AddJobRequest^ request 
   ) 

Parameters

Return Value

An Leadtools.Services.JobProcessor.DataContracts.AddJobResponse class containing information for the added job.

Remarks

Use this method to add a new job to the JobProcessor database. The Leadtools.Services.JobProcessor.DataContracts.AddJobResponse class will contain the ID (GUID) of the added job. To add a batch of jobs at once, use AddJobs.

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 AddJob() 
{ 
   using (JobServiceClient jobServiceClient = new JobServiceClient()) 
   { 
      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. 
      JobMetadata jobMetadata = new JobMetadata(@"c:\input.jpg", @"c:\output.pdf", "PDF"); 
      addJobRequest.JobMetadata = SerializeToString(jobMetadata); 
      addJobRequest.JobType = "ConvertToPDF"; 
      AddJobResponse addJobResponse = jobServiceClient.AddJob(addJobRequest); 
      if (!String.IsNullOrEmpty(addJobResponse.Id)) 
         Console.WriteLine(String.Format("The ID of the new job is {0}", addJobResponse.Id)); 
   } 
} 
 
'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 AddJob() 
   Using jobServiceClient As JobServiceClient = New JobServiceClient() 
      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. 
      Dim jobMetadata As JobMetadata = New JobMetadata("c:\input.jpg", "c:\output.pdf", "PDF") 
      addJobRequest.JobMetadata = SerializeToString(jobMetadata) 
      addJobRequest.JobType = "ConvertToPDF" 
      Dim addJobResponse As AddJobResponse = jobServiceClient.AddJob(addJobRequest) 
      If (Not String.IsNullOrEmpty(addJobResponse.ID)) Then 
         Console.WriteLine(String.Format("The ID of the new job is {0}", addJobResponse.ID)) 
      End If 
   End Using 
End Sub 

Requirements

Target Platforms

Help Version 20.0.2020.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.