Create custom WATS Client converter

The WATS Client support custom converters to automatically read and import different report files into WATS. This example shows how to create a simple converter.

  • Download and install the WATS client.
  • Download and unzip the attached file MyNewConverter.zip (at the end of this article). Open the project in Visual Studio (2012).

After opening the project in Visual Studio, follow the instructions in the ReadMe file. You should now be able to set up the client and run the "MyNewConverter" plug-in.


Below is an additional description

  • Open Visual Studio and create a new Class Library:
  • NB: Use .NET Framework 3.5 when using WATS Client 4.2.10.
  • 1.png
  • Add and reference the Virinco.WATS.Interface.TDM.dll:
    2.png
  • Create a Class that implements IReportConverter, here is a simple example:
 
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using Virinco.WATS.Interface;

 
namespace MyNewConverter
{
    class MyConverter : IReportConverter
    {
        public void CleanUp()
        {
            //If needed, will be called if the WATS client service is stopped
        }
 
        ///
        /// This is the main interface call and the only thing you have to implement
        ///
        ///An open WATS TDM api (see own documentation)
        ///A file stream to a file placed in the drop folder defined by convertes.xml
        /// An UUT or UUR report (can also be null if desired, the conversion code must then handle submit
        public Report ImportReport(TDM api, System.IO.Stream file)
        {
            int lineCount = 0;
            try
            {
                using (StreamReader reader = new StreamReader(file))
                {
        /// Read file and send reports
                }
            }
            catch (Exception ex)
            {
                StreamWriter errorlog = new StreamWriter(api.ConversionSource.ErrorLog); //Will place the file in an error catalog
                errorlog.WriteLine("Error in file {0}, line {1}: {2}", api.ConversionSource.SourceFile.Name, lineCount, ex.Message);
                errorlog.Flush();
throw; } return null; } } }
  • Now you need to install the converter.
    First, you need to edit the file called converters.xml found in the C:\ProgramData\Virinco\WATS folder (Windows 7). For the converter in the example, add this:

    <converter name="MyNewConverter" assembly="MyNewConverter" class="MyNewConverter.MyConverter">
    <Source type="folder">
      <Parameter name="Path">C:\ProgramData\Virinco\WATS\MyNewConverterFiles</Parameter>
      <Parameter name="Filter">*.txt</Parameter>
<Parameter name="PostProcessAction">Delete</Parameter> (Default)
<--Parameter name="PostProcessAction">Move</Parameter--> (Moved to Done folder)
<--Parameter name="PostProcessAction">Zip</Parameter--> (.Zip file created in Done folder)
    </Source>
    <Destination type="api">
      <Parameter name="online">False</Parameter>
      <Parameter name="OperationTypeCode">10</Parameter>
      <Parameter name="SomeArgument">This is an argument</Parameter>
    </Destination>
  </converter>
  • Then you copy the compiled converter assembly (.dll) to C:\Program Files\Virinco\WATS.
    Create the drop folder and Restart the WATS Client service. You can now start dropping files. (C:\ProgramData\Virinco\WATS\MyNewConverterFiles). If you place the drop folder another place, make sure that the local “Network Service” has write permission to the folder.

  • Note: Please do not use System.Diagnostics.Debug.WriteLine to output debug info, it seems that this leads to memory consumption. Use the ConversionLog instead:            
    convlog = new StreamWriter(api.ConversionSource.ConversionLog);
    //Use convlog.WriteLine to output. Will genereate a log file in the Done folder
    Then place a
    convlog.Flush(); convlog.Close(); //at the end of your program
Have more questions? Submit a request

3 Comments

  • 0
    Avatar
    Danny Thomson

    Hi,

    So I am trying for the first time to use Visual Studio and write an attach to UUT report converter.

    My idea is to have a text file with info in it, that is specific to an instance of a UUT report and attach it to the UUT report.

    I assume the key to the UUT report is the UTC Time part number and serial number. I was going to provide that info either as the first line of my text file or in the actual filename. 

    Having go that info I then need to do something like

    UUTReport uutReport = api.FindUUTInstance 

    and then some sort of 

    UUTReport uutReport = api.Attach(UUT Instance, file)

    I have been going through the object browser and I cannot find a method to look up a reference to the UUT report instance or a method to attach to file after I have done so. 

    Sorry if my VS terminology is wrong, but could somebody please give me some help finding the WATS.Interface object and methods if should be looking at.

    cheers 

    Danny

  • 0
    Avatar
    Danny Thomson

    It would be lovely if an attachment could simply be adding in via the WSTF, some key and then the filepath of the file to import 

  • 0
    Avatar
    Tom Andres Lomsdalen

    Hi Danny, I have created a support ticket for this to follow up.

Please sign in to leave a comment.