public void Create(TranslationProviderServer tmServer, string organizationPath, string containerName, string tmName) { #region "CheckExists" foreach (ServerBasedTranslationMemory item in tmServer.GetTranslationMemories(TranslationMemoryProperties.None)) { if (item.Name == tmName) { throw new Exception("TM with that name already exists."); } } #endregion #region "TM" ServerBasedTranslationMemory newTM = new ServerBasedTranslationMemory(tmServer); newTM.Name = tmName; newTM.Description = "Programmatically created sample TM"; newTM.Copyright = "(c) 2010 SDL International"; #endregion string containerPath = organizationPath; if (!containerPath.EndsWith("/")) { containerPath += "/"; } #region "container" containerPath += containerName; TranslationMemoryContainer container = tmServer.GetContainer(containerPath, this.GetContainerProperties()); newTM.Container = container; #endregion #region "LanguageDirection" this.CreateLanguageDirections(newTM.LanguageDirections); #endregion #region "org" newTM.ParentResourceGroupPath = organizationPath; #endregion string templatePath = organizationPath; if (!templatePath.EndsWith("/")) { templatePath += "/"; } #region "templates" string sampleFieldTemplateName = "MyFieldTemplate"; foreach (ServerBasedFieldsTemplate template in tmServer.GetFieldsTemplates(FieldsTemplateProperties.All)) { if (template.Name == sampleFieldTemplateName) { newTM.FieldsTemplate = tmServer.GetFieldsTemplate( templatePath + sampleFieldTemplateName, FieldsTemplateProperties.Fields); break; } } string sampleLanguageResourcesTemplateName = "MyLanguageResourcesTemplate"; foreach (ServerBasedLanguageResourcesTemplate template in tmServer.GetLanguageResourcesTemplates( LanguageResourcesTemplateProperties.LanguageResources)) { if (template.Name == sampleLanguageResourcesTemplateName) { newTM.LanguageResourcesTemplate = tmServer.GetLanguageResourcesTemplate( templatePath + sampleLanguageResourcesTemplateName, LanguageResourcesTemplateProperties.None); break; } } #endregion newTM.Save(); }
private void AddDetailsCallback(string userName, string password, string uri) { try { Properties.Settings.Default.UserName = userName; Properties.Settings.Default.Password = password; Properties.Settings.Default.Uri = uri; Properties.Settings.Default.Save(); var uriServer = new Uri(Properties.Settings.Default.Uri); var translationProvider = new TranslationProviderServer(uriServer, false, Properties.Settings.Default.UserName, Properties.Settings.Default.Password); var translationMemories = translationProvider.GetTranslationMemories(TranslationMemoryProperties.None); var tmDetails = new List <TranslationMemoryDetails>(); foreach (var tm in translationMemories) { tmDetails.Add(new TranslationMemoryDetails { Id = tm.Id, Name = tm.Name, Description = tm.Description, CreatedOn = tm.CreationDate, Location = tm.ParentResourceGroupPath, ShouldRecomputeStatistics = tm.ShouldRecomputeFuzzyIndexStatistics(), LastReIndexDate = tm.FuzzyIndexStatisticsRecomputedAt, LastReIndexSize = tm.GetTranslationUnitCount() }); var result = tm.CurrentReindexOperation; } var sortedBindingList = new SortableBindingList <TranslationMemoryDetails>(tmDetails); gridServerBasedTMs.DataSource = sortedBindingList; for (var i = 0; i < gridServerBasedTMs.Columns.Count; i++) { gridServerBasedTMs.Columns[i].Visible = false; } gridServerBasedTMs.Columns["Name"].Visible = true; gridServerBasedTMs.Columns["Description"].Visible = true; gridServerBasedTMs.Columns["CreatedOn"].Visible = true; gridServerBasedTMs.Columns["Location"].Visible = true; gridServerBasedTMs.Columns["ShouldRecomputeStatistics"].Visible = true; gridServerBasedTMs.Columns["LastReIndexDate"].Visible = true; gridServerBasedTMs.Columns["LastReIndexSize"].Visible = true; if (!gridServerBasedTMs.Columns.Contains("Status")) { gridServerBasedTMs.Columns.Add("Status", "Status"); } gridServerBasedTMs.Columns["Status"].Visible = true; gridServerBasedTMs.ReadOnly = true; gridServerBasedTMs.Visible = true; connectToServerBtn.Text = "Logout"; } catch (Exception ex) { throw new SystemException(Constants.AuthentificationErrorMsg); } }