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

Reply Children