You are here: Installation and Configuration Guides > Connector for Sitecore > Appendix: Connector Extensions > Using Custom Logic to Configure how the Upload Schedule Creates Jobs when Automatically Sending Out Items from the Translation Queue

Using Custom Logic to Configure how the Upload Schedule Creates Jobs when Automatically Sending Out Items from the Translation Queue

The CustomAutoSendQueuesPipeline setting in CT3Translation.config enables you to use your own logic to determine how to automatically create jobs from the Translation Queue. It works in conjunction with the Auto Send Queue Items Time setting in the /sitecore/system/Tasks/Schedules/Lionbridge/Upload Schedule/Upload Service Options item, which is described in Configuring the Connector to Send All Items in the Queue for Translation.

The following is a sample implementation of the pipeline:

public class TestCustomAutoSendQueuesPipeline

{

public void Process(AutoSendQueueJobsArgs args)

{

string frJobId = null;

string otherJobId = null;

 

foreach (TranslationQueueInfo queueItem in args.TranslationQueueItems)

{

TranslationJobInfo jobInfo;

if (queueItem.ItemTargets.Contains("fr-FR"))

{

if (frJobId == null)

{

jobInfo = args.AddNewJob();

// Create a separate job for queue items with fr-FR as target languages

jobInfo.Name = "Auto-sent French job " + DateTime.Now.ToString("MM/dd/yyyy HH:mm");

jobInfo.Description = "Automatically send fr-FR in a separate job scheduled at " + args.ScheduledSendTime.ToString("MM/dd/yyyy HH:mm");

jobInfo.DueDate = DateTime.Now.AddMonths(1);

 

jobInfo.TeamProfile = queueItem.TeamProfile;

 

// Optional. Specify first analysis code,

jobInfo.AnalysisCodes.Add(new AnalysisCode()

{

Level = 1,

Name = "First_Analysis_Name",

Value = "First_Analysis_Value"

});

 

// Optional. Specify second analysis code.

jobInfo.AnalysisCodes.Add(new AnalysisCode()

{

Level = 2,

Name = "Second_Analysis_Name",

Value = "Second_Analysis_Value"

});

 

// Optional. Specify third analysis code.

jobInfo.AnalysisCodes.Add(new AnalysisCode()

{

Level = 3,

Name = "Third_Analysis_Name",

Value = "Third_Analysis_Value"

});

 

// Optional. Specify PO Reference.

jobInfo.PoReference = "PO_Reference_Value";

 

// You can also specify a certain LSP account to send the job to

// jobInfo.SendAccount = "FR LSP";

frJobId = jobInfo.ID;

}

else

{

jobInfo = args.GetJob(frJobId);

}

}

else

{

if (otherJobId == null)

{

// Create a job for all other queued items

jobInfo = args.AddNewJob();

// Not specify job meta information, the connector will automatically fill in the information based on AutoSendQueueItems* configurations

// in CT3Translation.config

otherJobId = jobInfo.ID;

}

else

{

jobInfo = args.GetJob(otherJobId);

}

}

// If the queue item's ID is not inserted in a TranslationJobInfo object, the queue item will be skipped and left in the queue

jobInfo.QueueIdsInTheJob.Add(queueItem.ID);

}

}

}

The previous code sample checks the queued items and creates a translation job named Auto-sent French job with a timestamp. This job includes all queued items with fr-Fr as one of its target languages. The Connector's default job contains all other queued items.

This enables you to submit different queued items in different jobs, and you can send each job using a different producer key. This also supports sending different queue items at different times, by leaving out some of the queued items in one invocation of the pipeline and picking them up in a later invocation, using the args,ScheduledSendTime to determine which ones to send or leave out.

Any implementation should have a method with the signature like:

public void Process(AutoSendQueueJobsArgs args)

The parameter is of ClayTablet.SC.Pipelines.AutoSendQueueJobsArgs type:

public class AutoSendQueueJobsArgs : PipelineArgs

{

public List<TranslationQueueInfo> TranslationQueueItems;

public DateTime ScheduledSendTime;

public List<TranslationJobInfo> TranslationJobsToCreate;

public TranslationJobInfo AddNewJob();

public TranslationJobInfo GetJob(string id);

}

Implementation can iterate over TranslationQueueItems to check all the queued items waiting to be sent out. The type of ClayTablet.SC.Pipelines.TranslationQueueInfo provides information about the queued item:

public class TranslationQueueInfo

{

public String ID { get; }

public String ItemID { get; }

public String ItemDatabase { get; }

public String ItemSource { get; }

public int ItemSourceVersion { get; }

public String ItemPath { get; }

public List<String> ItemTargets { get; }

public DateTime CreateTime { get; }

public String SitecoreUser { get; }

}

The implementation should either:

  • Insert each queued item into a ClayTablet.SC.Pipelines.TranslationJobInfo object, which will cause it to be sent out as part of the job.
  • Leave a queued item alone, so it will remain in the Translation Queue for this scheduled automatic sending invocation.

public class TranslationJobInfo

{

public string ID { get; }

public string Name { get; set; }

public string Description { get; set; }

public string SendAccount { get; set; }

public DateTime? DueDate { get; set; }

public string SendUser { get; set; }

public string TeamProfile { get; set; }

public string PoReference { get; set; }

public List<String> QueueIdsInTheJob { get; }

public List<AnalysisCode> AnalysisCodes { get; }

}

public class AnalysisCode

{

public int Level { get; set; }

public string Name { get; set; }

public string Value { get; set; }

}

A new TranslationJobInfo is created by AutoSendQueueJobsArgs.AddNewJob(). The implementation can set the job's metadata, including name, description, sending account (producer key), sending user (the Sitecore user in the Creator metadata of the job), and due date. Insert the queue item's ID into TranslationJobInfo.QueueIdsInTheJob. After creating a TranslationJobInfo, the implementation should typically save it or its ID for reuse when iterating over other queued items that should be added into the same job. The AutoSendQueueJobsArgs.GetJob (string) enables the implementation to retrieve a previously created TranslationJobInfo so that it can add more queued items into the same job.