public void GetFieldTemplates(TranslationProviderServer tmServer)
        {
            #region "LoopTemplates"
            StringBuilder templateList = new StringBuilder();

            foreach (ServerBasedFieldsTemplate template in tmServer.GetFieldsTemplates(FieldsTemplateProperties.All))
            #endregion
            {
                #region "GeneralTemplateInfo"
                templateList.AppendFormat("Template name: {0}\n", template.Name);
                templateList.AppendFormat("Template description: {0}\n", template.Description);
                #endregion

                #region "fields"
                templateList.AppendLine("Fields: ");
                foreach (FieldDefinition def in template.FieldDefinitions)
                {
                    templateList.AppendFormat("{0}({1})", def.Name, def.ValueType.ToString());
                }

                templateList.AppendLine(string.Empty);
                #endregion
            }

            MessageBox.Show(templateList.ToString(), "Template List");
        }
Beispiel #2
0
        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, GetContainerProperties());
            newTM.Container = container;
            #endregion

            #region "LanguageDirection"
            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();
        }