LEADTOOLS Cloud (Leadtools.Services.Cloud.ServiceContracts assembly)
LEAD Technologies, Inc

AddJobs Method

Example 





A Leadtools.Services.Cloud.DataContracts.AddJobsRequest class for the jobs to add.
Adds a batch of jobs 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)]
AddJobsResponse AddJobs( 
   AddJobsRequest request
)
'Declaration
 
<OperationContractAttribute()>
<FaultContractAttribute(DetailType=Leadtools.Services.Cloud.FaultContracts.CloudFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=False)>
Function AddJobs( _
   ByVal request As AddJobsRequest _
) As AddJobsResponse
'Usage
 
Dim instance As IJobService
Dim request As AddJobsRequest
Dim value As AddJobsResponse
 
value = instance.AddJobs(request)
[OperationContractAttribute()]
[FaultContractAttribute(DetailType=Leadtools.Services.Cloud.FaultContracts.CloudFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=false)]
AddJobsResponse AddJobs( 
   AddJobsRequest request
)
OperationContractAttribute()
FaultContractAttribute(DetailType=Leadtools.Services.Cloud.FaultContracts.CloudFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=)
function Leadtools.Services.Cloud.ServiceContracts.IJobService.AddJobs( 
   request 
)
[OperationContractAttribute()]
[FaultContractAttribute(DetailType=Leadtools.Services.Cloud.FaultContracts.CloudFault, 
   Action="", 
   Name="", 
   Namespace="", 
   ProtectionLevel=ProtectionLevel.None, 
   HasProtectionLevel=false)]
AddJobsResponse^ AddJobs( 
   AddJobsRequest^ request
) 

Parameters

request
A Leadtools.Services.Cloud.DataContracts.AddJobsRequest class for the jobs to add.

Return Value

A Leadtools.Services.Cloud.DataContracts.AddJobsResponse class containing information for the added jobs.
Remarks

Use this method to add a batch of jobd to the cloud database with a single call to the server WCF service. The Leadtools.Services.Cloud.DataContracts.AddJobsResponse class will contain the ID's (Guid's) of the added jobs. To add a single job, use AddJob.

Example
 
'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 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
//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 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));
      }
   }
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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-2012 All Rights Reserved. LEAD Technologies, Inc.