The WATS Client supports 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 (2022).
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 4.6.2 when using WATS Client 6.x
- Install the WATS.Client NuGet package.
- 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.
- Open WATS Client Configurator and select Add Converter in the Converters tab.
- Enter a name
- Browse to the compiled converter assembly (.dll file)
- Select a folder as input folder. Creating a folder inside C:\ProgramData\Virinco\WATS is recommended, if you choose another location make sure the Network Service user has read and write permission.
- Select Post Processing Actions
- Delete; default
- Move; moved to Done folder
- Zip; zip file created in Done 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:
var convlog = new StreamWriter(api.ConversionSource.ConversionLog);
//Use convlog.WriteLine to output. Will genereate a log file in the Done folder
Then at the end of the program:
convlog.Flush();
convlog.Close();
Comments
3 comments
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
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
Hi Danny, I have created a support ticket for this to follow up.
Please sign in to leave a comment.