DocumentConverter has support for document conversion with status update. This feature utilizes LEADTOOLS caching to:
Convert a document in the cache and upload it automatically.
Perform the operation in a separate process (if the cache allows multiple processes to access the same value).
Use the cache to save and obtain the status of the conversion.
The main class for running a conversion with status is StatusJobDataRunner that uses instances of StatusJobData for each conversion. A simple workflow of an application using the status job converter is as follows:
// Create a new status job data runner:
StatusJobDataRunner runner = new StatusJobDataRunner();
// Create a new status job data:
StatusJobData jobData = new StatusJobData();
// Fill it up
jobData.InputDocumentId = "MyDocumentId";
// etc.
// Prepare the runner
runner.Prepare(jobData);
// Run it
runner.Run();
runner.Dispose();
This workflow performs the conversion job but does not allow for obtaining status information on the job. To do that, modify the code as follows:
// Create a new status job data runner:
StatusJobDataRunner runner = new StatusJobDataRunner();
// Create a new status job data:
StatusJobData jobData = new StatusJobData();
// Fill it up
jobData.InputDocumentId = "MyDocumentId";
// etc.
// Prepare the runner
runner.Prepare(jobData);
// Create a thread to query the job status
AutoResetEvent finished = new AutoResetEvent(false);
ThreadPool.QueueUserWorkItem((object state) =>
{
while (!isDone)
{
// Get the status of the job
StatusJobData statusJobData = StatusJobDataRunner.QueryJobStatus(statusCache, jobData.UserToken, jobData.JobToken);
// Do something with the info
Console.WriteLine("Status is " + statusJobData.
ShowJobStatus("Working", statusJobData.JobStatus);
if (statusJobData.IsCompleted)
{
// Notify that the job is completed
finished.Set();
}
Thread.Sleep(100);
}
});
// Run it
runner.Run();
runner.Dispose();
finished.WaitOne();
// The job is finished
StatusJobData can be initialized using only simple string parameters, therefore, the application can run the job from one process and perform the status query described above in the thread in a completely separate process. Refer to StatusJobDataRunner for a complete example.
When the conversion starts, the runner will create a new cache item with Region/Key set to UserToken/JobToken respectively and the value set to a copy of the StatusJobData input object. As the job progresses, the runner will update this item in the cache with the lasts status and timestamps. The application can use QueryJobStatus at any time to get the latest version of StatusJobData from the cache with updated values of the conversion status and any errors that might have occurred. The value of IsCompleted will be true when the runner has completed the conversion.
StatusJobData contains various members that can be organized into the following sections:
Member | Description |
---|---|
UserToken and JobToken | Unique identifiers for user and the job. These are used as the cache region and key to create a unique identifier for the job. |
StatusCacheConfiguration, StatusCachePolicy and StatusCache | Identifies the cache and the policy to use for storing the job status. |
UserData | Any user-defined data associated with the job |
JobStatus | Last status of the job, whether it has started, completed or aborted. |
JobStatusPageNumber, JobStatusMessage | Extra information on the last job status |
IsCompleted | Determine whether the job has been completed |
Abort | Allows the user to abort a running job |
JobStartedTimestamp, JobCompletedTimestamp, JobStatusTimestamp, QueryJobStatusTimestamp | Timestamps of various job operations |
ErrorMessages | Holds any error messages occurred during the conversion |
UserToken and JobToken must be specified by the application and combining them should create a unique string. Internally, the runner will use UserToken and JobToken as the Region and Key of a cache item added to the cache.
The status cache is used to store and update the StatusJobData object passed to the runner. This can be a valid cache instance stored in StatusCache, or a cache configuration string passed to StatusCacheConfiguration. If all these values are null, then the runner will use the next cache in the class (either InputCache or OutputCache), in other words, the application can use the same cache (set it in all three parameters or in only one and leave the rest null) or use different caches for each operation depending on the application configuration.
JobStatus will be set to one of the DocumentConverterJobStatus enumeration members.
JobStatusPageNumber and JobStatusMessage will contain extra information on the last job status.
IsCompleted will be false as long as the runner is performing the conversion. It will be set to true when the job finishes (successfully or not, the status will contain Success or Aborted depending on the result of the conversion). In case of errors, ErrorMessages will contain helpful hints and messages for the one or more error that occurred.
The various timestamps can be queried to check the health of the conversion and whether it is still performing correctly.
Member | Description |
---|---|
DocumentConverter, DocumentConverterOptions | The document converter or its options to use with this job |
DocumentWriterOptions | The options for the document writer to use with this job |
OcrEngineName, OcrEngineStartupParameters, OcrEngineSettings | The OCR engine or its options to use with this job |
The runner uses a DocumentConverter to perform the operation. The options described above can be used to set the instance of the DocumentConverter to use or simple options (in XML form) to use.
Member | Description |
---|---|
InputCache, InputCacheConfiguration | Identifies the cache used to hold the input document. |
InputDocumentId | The ID of the source document to be converted |
InputDocumentFirstPageNumber, InputDocumentLastPageNumber | Optional first and last page number of the document to be converted |
These members must be initialized to the information of input document in the cache to be converted.
Member | Description |
---|---|
OutputCache, OutputCacheConfiguration, OutputCacheItemPolicy | Identifies the cache and policy to use for storing the output document. |
OutputDocumentID | Optional ID to use for the output document |
OutputDocumentUri | Uploaded URI to use for the output document |
OutputDocumentName | Optional name to assign to the output document |
The result output document from the conversion is uploaded it to the cache. These members define how to store the document.
Member | Description |
---|---|
DocumentFormat, RasterImageFormat, RasterImageBitsPerPixel | Format to use for the output document |
JobName | Optional job name |
AnnotationsMode | Annotation output mode |
Finally, this section specifies the output document type and annotation mode to use.
For a full example, refer to StatusJobDataRunner.