LEADTOOLS Cloud (Leadtools.Services.Cloud.ServiceContracts assembly)

AddJob Method

Show in webframe
Example 





A Leadtools.Services.Cloud.DataContracts.AddJobRequest class for the job to add.
Adds a job to the cloud database by calling the IJobService WCF Service.
Syntax
[OperationContractAttribute()]
[FaultContractAttribute(DetailType=Leadtools.Services.Cloud.FaultContracts.CloudFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=false)]
AddJobResponse AddJob( 
   AddJobRequest request
)
'Declaration
 
<OperationContractAttribute()>
<FaultContractAttribute(DetailType=Leadtools.Services.Cloud.FaultContracts.CloudFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=False)>
Function AddJob( _
   ByVal request As AddJobRequest _
) As AddJobResponse
'Usage
 
Dim instance As IJobService
Dim request As AddJobRequest
Dim value As AddJobResponse
 
value = instance.AddJob(request)

            

            
[OperationContractAttribute()]
[FaultContractAttribute(DetailType=Leadtools.Services.Cloud.FaultContracts.CloudFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=false)]
AddJobResponse^ AddJob( 
   AddJobRequest^ request
) 

Parameters

request
A Leadtools.Services.Cloud.DataContracts.AddJobRequest class for the job to add.

Return Value

A Leadtools.Services.Cloud.DataContracts.AddJobResponse class containing information for the added job.
Remarks

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

Example
Copy Code  
'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 cloud 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 cloud 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
using LeadtoolsCloudExamples.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 cloud 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 cloud 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));
   }
}
Requirements

Target Platforms

See Also

Reference

IJobService Interface
IJobService Members
Programming with Leadtools Cloud SDK
Understanding The LEADTOOLS Cloud Database
Creating Cloud Worker Assemblies
OnJobReceived Method

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.