Is there any good example on how to use FileBasedProject.RunAutomaticTask Method (Guid[], String, EventHandler<TaskStatusEventArgs>, EventHandler<TaskMessageEventArgs>)

Is there any good example on how to use FileBasedProject.RunAutomaticTask Method (Guid[], String, EventHandler<TaskStatusEventArgs>, EventHandler<TaskMessageEventArgs>)

Looks like a great way to get an operation progress status, but I can't find any example on how to use this function.

Any help would be appreciated!

Rieko Matsunaga

Parents
  • Hi Rieko,

    Here is my Scan task example. Hope that will help:

    ProjectFile[] projectFiles = p.GetSourceLanguageFiles();

               List<TaskStatusEventArgs> ScanTaskStatus = new List<TaskStatusEventArgs>();

               List<MessageEventArgs> ScanMessages = new List<MessageEventArgs>();

               AutomaticTask scan = p.RunAutomaticTask(projectFiles.GetIds(), AutomaticTaskTemplateIds.Scan,

                   (sender, TaskStatus) => { ScanTaskStatus.Add(TaskStatus); }, (sender, ScanMess) => { ScanMessages.Add(ScanMess); });

               if (ScanMessages.Count > 0)

               {

                   string body = "File Scan Error: ";

                   foreach (MessageEventArgs arg in ScanMessages)

                   {

    //messages found, throwns an exception.

                       ProjectFile pf = p.GetFile(arg.Message.ProjectFileId.Value);

                       body += String.Format("File: :{0}, Message: {1}, Source: {2}", pf.Name, arg.Message.Message,

                           arg.Message.Source);

                       ContactPerson cp = ContactPerson.GetContactPersonFromITracUserId(q.UserID.Value);

                       string lang = CodeTables.Choices.Languages.GetDescription(q.LanguageId);

                       string subject = String.Format("Job: {0}, language: {1}: Failed to convert", q.Job.Number,

                           lang);

                       List<string> to = new List<string>();

                       to.Add(cp.Email);

                       Tools.SendMailNoAttachments(subject, body, MailPriority.High, to);

                       throw new Exception(body);

                   }

               }

  • Thank you all for sharing your codes!  

    Have you found a way to cancel RunAutomaticTask during the task?  

    How about getting a percentage value indicating how far the operation has progressed?  

    Thank you for your support!

    Rieko

Reply Children
No Data