MultiTerm Interop - Trouble with automated import of MultiTerm XML in Termbase

Hello community,

Every once in a while we get new MultiTerm XML files to replace our Termbases with revised versions. Since this affects 19 termbases, I am eager to automate this process. 
This means, I need to create a new termbase, use the previous version as template, and import the new XML. Rinse and repeat for 19 files.

Unfortunately, I cannot find the portion in the API documentation thatdescribes how to actually tell *which" XML to import.

This is what I have so far:

var multi = new Sdl.MultiTerm.TMO.Interop.Application();
var repo = multi.LocalRepository;
repo.Connect("Administrator", "");
repo.Termbases.Add(pathToPreviousTBVersion,TbName,"ReferenceTB");
var refTermBase = repo.Termbases[0];

var xdt = $"C:\\temp\\temp.xdt";
if(File.Exists(xdt)) File.Delete(xdt);
refTermBase.Definition.Save(xdt);

repo.Termbases.New(newTbName, newTbDescription, xdt, pathToSaveNewTB);

var xmlFile = pathToMultiTermXml;
var newTermBase= repo.Termbases[1];
var impDefs = newTermBase.ImportDefinitions;
var impDef = impDefs["Default import definition"];
impDef.ProcessImport(MtTaskType.mtScript);

From what I understand, MtTaskType.mtScript means "import without GUI", i.e. exactly what I need. Unfortunately, there is no method or property to tell the API the path to the XML that shall be imported. What am I missing?

Cheers,
Andreas

Parents
  • Unless my memory and my old code betray me, you're not missing anything, but the API does: a proper import call Slight smile I used this workaround. Not elegant, but it works

    private void ProcessImport(Termbase termbase, string importDefinition, string importFile)
    {
    string tmpPath = System.Environment.GetEnvironmentVariable("TEMP") + "\\tmpImportDefinition.xml";
    termbase.ImportDefinitions[importDefinition].Save(tmpPath);

    XmlDocument doc = new XmlDocument();
    doc.Load(tmpPath);
    XmlNode node = doc.SelectSingleNode("//XMLFile");
    node.InnerXml = importFile;
    node = doc.SelectSingleNode("//ErrorFile");
    node.InnerXml = importFile + ".import.log";
    doc.Save(tmpPath);

    ImportDefinition modified = _Tb.ImportDefinitions.Add("tmpImport1", "", tmpPath);
    modified.ProcessImport(MtTaskType.mtScript);
    modified.Delete();
    System.IO.File.Delete(tmpPath);
    }

    called like this:

    ProcessImport(newTermbase, "Default import definition", @"C:\temp\temp.xml");

Reply
  • Unless my memory and my old code betray me, you're not missing anything, but the API does: a proper import call Slight smile I used this workaround. Not elegant, but it works

    private void ProcessImport(Termbase termbase, string importDefinition, string importFile)
    {
    string tmpPath = System.Environment.GetEnvironmentVariable("TEMP") + "\\tmpImportDefinition.xml";
    termbase.ImportDefinitions[importDefinition].Save(tmpPath);

    XmlDocument doc = new XmlDocument();
    doc.Load(tmpPath);
    XmlNode node = doc.SelectSingleNode("//XMLFile");
    node.InnerXml = importFile;
    node = doc.SelectSingleNode("//ErrorFile");
    node.InnerXml = importFile + ".import.log";
    doc.Save(tmpPath);

    ImportDefinition modified = _Tb.ImportDefinitions.Add("tmpImport1", "", tmpPath);
    modified.ProcessImport(MtTaskType.mtScript);
    modified.Delete();
    System.IO.File.Delete(tmpPath);
    }

    called like this:

    ProcessImport(newTermbase, "Default import definition", @"C:\temp\temp.xml");

Children