using System; using System.Windows.Forms; using Sdl.MultiTerm.TMO.Interop; namespace testmultitermitf { public partial class fName : Form { public fName() { InitializeComponent(); } private void AppendLog(string msg) { eLog.AppendText(msg + "\r\n"); } private void tryOpen(TermbaseRepository localRepo, string name) { try { Termbase tbExists = localRepo.Termbases[name]; if (tbExists == null) { AppendLog("Error exporting to SDLTB (Termbase does not exist)"); return; } AppendLog("Name:" + tbExists.Name + " " + tbExists.Definition); } catch (Exception e) { AppendLog("Failed to open termbase " + name + " " + e.Message); } } private void exportSDLTB() { try { AppendLog("Creating object"); Sdl.MultiTerm.TMO.Interop.Application mtApp = new ApplicationClass(); if (mtApp == null) { AppendLog("Multiterm 2009 does not appear to be installed on this PC - Cannot export to SDLTB"); return; } TermbaseRepository localRepo = mtApp.LocalRepository; if (localRepo == null) { AppendLog("Error exporting to SDLTB: Cannot create local multiterm repository - Is Multiterm 2009 desktop installed on this PC"); return; } /******************************************************************************** * * Connect to a local repository takes "","" as parameters * ********************************************************************************/ localRepo.Connect("", ""); AppendLog("Connection status to local repository:" + localRepo.IsConnected); Termbases termbases = localRepo.Termbases; if (termbases == null) { AppendLog("Error exporting to SDLTB (Termbases)- Is Multiterm 2009 desktop installed on this PC"); return; } /******************************************************************************** * * repository is always empty after creation, it does not store files that were * used in the past. It's up to the application to have an MRU and add termbases. * Consequently, these calls will all fail. * ********************************************************************************/ tryOpen(localRepo, "test_JA"); tryOpen(localRepo, "test_NL"); tryOpen(localRepo, "t1"); tryOpen(localRepo, "test.xdt"); tryOpen(localRepo, "fvTermbase.sdltb"); AppendLog("There are " + termbases.Count + " termbases in the local repo."); foreach (Termbase tb in termbases) { AppendLog("Name:" + tb.Name + " " + tb.Definition); } try { /******************************************************************************** * * make sure the termbase file exists. Otherwise you get COM error -2147220878 (0x80040272) * ********************************************************************************/ termbases.Add(@"D:\Share\Testdata\Termbases\Sample.sdltb", "t3", "t3"); /******************************************************************************** * * Index can be a number or the full path as used in Add() * do NOT use termbases["t3"], since that is not guaranteed to be unique * ********************************************************************************/ Termbase tbNew = termbases[0]; if (tbNew == null) { MessageBox.Show("Error exporting to SDLTB (New Termbase)- Is Multiterm 2009 desktop installed on this PC"); return; } } catch (System.Runtime.InteropServices.COMException comex) { AppendLog("Failed to Add new termbase " + comex.Message + " code:" + comex.ErrorCode); } catch (Exception ex) { AppendLog("Failed to Add new termbase " + ex.Message); } AppendLog("There are " + termbases.Count + " termbases in the local repo."); try { /******************************************************************************** * * make sure the termbase definition file exists. * make sure the folder for the termbase file exists. * make sure the termbase does not already exist. * ********************************************************************************/ Termbase tbNew = termbases.New( "test_JA", // display name "test_JA", // description @"D:\Share\Testdata\Termbases\exported\Definition for Sample.xdt", // full path to termbase definition file @"D:\Share\Testdata\Termbases\newtermbase.sdltb"); // full path to termbase file that will be created if (tbNew == null) { MessageBox.Show("Error exporting to SDLTB (New Termbase)- Is Multiterm 2009 desktop installed on this PC"); return; } } catch (Exception ex) { AppendLog("Failed to create new termbase " + ex.Message); } AppendLog("There are " + termbases.Count + " termbases in the local repo."); } catch (Exception ex) { AppendLog("Failed to connect to Multiterm " + ex.Message); } } private void btConnect_Click(object sender, EventArgs e) { exportSDLTB(); } } }