Automatic Tasks handling

I was wondering if you could offer a few precisions about the AutomatedTasks (the overriden version, with Event Handlers). Ive seen something pretty close to the code that Im posting now, and was wondering: 

1. What is preventing the code from reaching the "string strErrorMessage line (line 9)? Are the automated tasks blocking operations (in an async wait type of way)? Or, before I move on the the strErrorMsg line, should I do a Task.Status check? do a while loop until its reached the "completed" status, and then check for errors. 

2. The "List<Sdl.ProjectAutomation.Core.MessageEventArgs> ConversionErrorMessages" object: is this an object that will capture error messages only? or will it get any type of messages from sub operations? 

Sample code:

1 #region Automated task: convert the files to a translatable format 
2 AutomaticTask atScan = fpbNewProject.RunAutomaticTask(gSourceFileGuid, 
3 AutomaticTaskTemplateIds.ConvertToTranslatableFormat, 
4 (sender, TaskStatus) => { ConversionTaskStatus.Add(TaskStatus); }, 
5 (sender, ScanMessage) => { ConversionErrorMessages.Add(ScanMessage); }); 
6 #endregion 
7 
8 #region Check for errors from the automated task operation 
9 string strErrorMessage = ""; 
10 
11 if (ConversionErrorMessages.Count > 0) 
12 { 
13 strErrorMessage = string.Format("Errors in automated task {0}", "AutomaticTaskTemplateIds.ConvertToTranslatableFormat");
14 
15 foreach (Sdl.ProjectAutomation.Core.MessageEventArgs mArgs in ConversionErrorMessages)
16 {
17 ProjectFile pfFile = fpbNewProject.GetFile(mArgs.Message.ProjectFileId.Value);
18 strErrorMessage += string.Format("\nFile: {0}, \nMessage: {1}, \nSource {2}", pfFile.Name, mArgs.Message.Message, mArgs.Message.Source);
19 }

Parents
  • Hi Raymond,

    It might be that you are are not running Scan which is required to identify the file type information.

    Example:

    try running this before line 2 and let me know how it goes

    fpbNewProject.RunAutomaticTask(gSourceFileGuid, AutomaticTaskTemplateIds.Scan);

    Patrick Andrew Hartnett | RWS Group

  • I think my question is more generic: "what is the proper coding pattern". So, in essence, whenever AutomatedTasks are invoked, shouldnt I be checking for the status of the operation? or, is there something that becomes "blocking" until the automated task completes?, and then, the explicit status check becomes redundant/not needed? or, is the status check always required? Let's say that instead of using the convert template, I was just scanning as you suggest. The coding pattern I would use would be the same as you see above... but in some SDK docs, I see things about checking the Status of the task. Should I be including that check myself, or is taken care of by the AutomatedTasks processing. Check out line 11 here: 

    1 #region Automated task: convert the files to a translatable format
    2 AutomaticTask atScan = fpbNewProject.RunAutomaticTask(gSourceFileGuid,
    3 AutomaticTaskTemplateIds.ConvertToTranslatableFormat,
    4 (sender, TaskStatus) => { ConversionTaskStatus.Add(TaskStatus); },
    5 (sender, ScanMessage) => { ConversionErrorMessages.Add(ScanMessage); });
    6 #endregion
    7
    8 #region Check for errors from the automated task operation
    9 string strErrorMessage = "";
    10
    11 if (TaskStatus == Completed)
    12 {
    13 if (ConversionErrorMessages.Count > 0)
    14 {
    15 strErrorMessage = string.Format("Errors in automated task {0}", "AutomaticTaskTemplateIds.ConvertToTranslatableFormat");
    16
    17 foreach (Sdl.ProjectAutomation.Core.MessageEventArgs mArgs in ConversionErrorMessages)
    18 {
    19 ProjectFile pfFile = fpbNewProject.GetFile(mArgs.Message.ProjectFileId.Value);
    20 strErrorMessage += string.Format("\nFile: {0}, \nMessage: {1}, \nSource {2}", pfFile.Name, mArgs.Message.Message, mArgs.Message.Source);
    21 }
    22 }

    Also, what is in the MessageEventArgs (the last argument in the automatedtask invocation). Only errors? or information of other types of details? 

  • Hi

    You can recover the status of the executing task in the execution order given (from the AutomaticTaskTemplateIds), by subscribing to the statusEventHandler when calling the RunAutomaticTask method, as you are doing.

    It really depends on your requirements and as you are aware, the return object (AutomaticTask) will provide you with details of the all tasks that were executed in all cases, once they are completed or failed...

    Correct, the MessageEventArgs will provide you with a list of the detailed exception messages relative to the templateId; holding information such as the project file id, source, message + the exception

    To help you better understand how to run these automation tasks in a more structure way and recover the status messages etc... I have attached the following example project:

    ProjectAutomationSample.zip

    Note: open the project as Administrator as the output folder will be pointing to your Studio installation directory.

    let me know how it goes,

    P.

    Patrick Andrew Hartnett | RWS Group

Reply
  • Hi

    You can recover the status of the executing task in the execution order given (from the AutomaticTaskTemplateIds), by subscribing to the statusEventHandler when calling the RunAutomaticTask method, as you are doing.

    It really depends on your requirements and as you are aware, the return object (AutomaticTask) will provide you with details of the all tasks that were executed in all cases, once they are completed or failed...

    Correct, the MessageEventArgs will provide you with a list of the detailed exception messages relative to the templateId; holding information such as the project file id, source, message + the exception

    To help you better understand how to run these automation tasks in a more structure way and recover the status messages etc... I have attached the following example project:

    ProjectAutomationSample.zip

    Note: open the project as Administrator as the output folder will be pointing to your Studio installation directory.

    let me know how it goes,

    P.

    Patrick Andrew Hartnett | RWS Group

Children
No Data