BatchTask for NativeSource Files: ReportMessage possible?

Hello,

I am working on a PreProcessor Batch Task, that cleans some Word files before these are converted and translated. So I am working on the native files. I use a ShouldProcessFile override function for that. Is it possible to return status information or report errors to the BatchTask Dialog? I have not found a way to do that.

Thank you
Andre

Parents
  • One more question: Is it possible to abort the BatchTask process if I notice that something is wrong with the source files? How can I do that?
  • Hi Andre,

    I'm not sure I am following.
    Would you be able to show code of how you are processing the native files?
  • Sure. This is a simplified version of the code:

    [AutomaticTask("Faq_Pre_Processor",
    "Faq Pre Processor",
    "Pre process the Faq Word documents and clean them for better translation.",
    GeneratedFileType = AutomaticTaskFileType.NativeSource)]
    [AutomaticTaskSupportedFileType(AutomaticTaskFileType.NativeSource)]
    [RequiresSettings(typeof(MyCustomBatchTaskSettings), typeof(MyCustomBatchTaskSettingsPage))]
    public class MyCustomBatchTask : AbstractFileContentProcessingAutomaticTask
    {
    private bool _isError = false;

    protected override void OnInitializeTask()
    {
    // nothing to do
    }

    protected override void ConfigureConverter(ProjectFile projectFile, IMultiFileConverter multiFileConverter)
    {
    // nothing to do
    }

    public override bool ShouldProcessFile(ProjectFile projectFile)
    {
    if (!File.Exists(projectFile.LocalFilePath))
    {
    _isError = true;
    return false;
    }

    try
    {
    Application applicationWord = null;
    Document doc = null;
    // Init
    applicationWord = new Application();
    //applicationWord.Visible = true;
    doc = applicationWord.Documents.Open(projectFile.LocalFilePath);

    // Accept Revistions
    doc.AcceptAllRevisions();
    doc.TrackRevisions = false;
    // and much more...

    doc.Save();
    doc.Close();
    applicationWord.Quit();
    applicationWord = null;
    }
    catch
    { _isError = true; }

    return true;
    }

    public override void TaskComplete()
    {
    if (_isError)
    {
    ExeptionLog el = new ExeptionLog(_filesDirectory);
    Process.Start(el.ErrorFile);
    var message = MessageBox.Show("One or more errors occured. Check the error.log file. Do you want to continue?", "Error",
    MessageBoxButtons.YesNo, MessageBoxIcon.Error);

    if (message == DialogResult.No)
    // Abort BatchTask Process
    }
    }
    }
  • Well, while looking at the code today, I got an idea how get it working to report the errors and warnings. Right now I do all the stuff in the ShouldProcessfile function. I move that to the ConfigureConverter function and create a new Processor class.
    Yesterday I had the problem, that the ConfigureConverter function was never triggered. Now I know why :D
    If i need further help, I get back to you.

    Sometimes it helps to continue the work the next day :D

  • So... I am getting closer...

    I moved all my logic to the a processor class.

    When I do a simple ReportMessage call, like the example below, it is not shown in the BatchTask dialog. Why? The documentation does not tell much about the ReportMessage function. I expected that I can set the errors and warnings with this function. When I throw an exception the error is shown in the dialog.

    Can you help me with that?

    I still don't know how to abort the BatchTask process. If the word file could not be processed correctly it is not necessary to run all the following batch tasks.

     

    public class WordFileProcessor : AbstractBilingualContentProcessor
    {

    public WordFileProcessor(ProjectFile projectFile)
    {
    ReportMessage(null, projectFile.Name, ErrorLevel.Error, "Word file could not be opened", "");
    }
    }
  • Hi Andre,

    The underlying MessageReporter is initialized by the framework.
    Since you call it in the constructor, it probably has not been initialized yet (it is null).

    Override the FileComplete method or one of the other methods of AbstractBilingualContentProcessor and call it in that.
    When you use ErrorLevel.Error it should stop any further Batch Tasks that come after.

    You are running this Batch Task on the native files? Batch Tasks are usually run on SDLXLIFF files, so I'm not sure how you run this on native files.

Reply Children