Example #1
0
        public void DeleteContainer(TranslationProviderServer tmServer, string organization, string containerName)
        {
            if (!organization.EndsWith("/"))
            {
                organization += "/";
            }
            TranslationMemoryContainer container = tmServer.GetContainer(organization + containerName, ContainerProperties.None);

            container.Delete(false);
        }
        public void DeleteContainer()
        {
            TranslationMemoryContainer container = TMServer.GetContainer(ParentOrganizationPath + "/APITest", ContainerProperties.None);

            if (container != null)
            {
                container.Delete(true);
                WriteResult("Container deleted\r\n");
            }
        }
Example #3
0
        public void Create(TranslationProviderServer tmServer)
        {
            TranslationMemoryContainer container = new TranslationMemoryContainer(tmServer);

            DatabaseServer dbServ = tmServer.GetDatabaseServer("DB01", GetDbServProperties());

            container.DatabaseServer = dbServ;
            container.DatabaseName   = "DbName";
            container.Name           = "NiceName";
            container.Save();
        }
        private TranslationMemoryContainer CreateContainer(string newContainerName)
        {
            ReadOnlyCollection <DatabaseServer> dbs = TMServer.GetDatabaseServers(DatabaseServerProperties.Containers);

            if (dbs.Count == 0)
            {
                throw new Exception("No DB server registered.");
            }

            //pick first DB server and check if the new container name already exists
            foreach (var cnt in dbs[0].Containers)
            {
                if (cnt.Name == newContainerName)
                {
                    //container exists so let use it
                    return(cnt);
                }
            }
            //set a parent organization variable, all operations will be performed in this organization
            ParentOrganizationPath = dbs[0].ParentResourceGroupPath;

            //now create a new container and add to the server
            TranslationMemoryContainer container = new TranslationMemoryContainer(TMServer);

            container.DatabaseServer          = dbs[0];
            container.DatabaseName            = newContainerName + "DB";
            container.Name                    = newContainerName;
            container.ParentResourceGroupPath = ParentOrganizationPath;
            container.Save();

            //now verify that the container was created sucessfully
            if (TMServer.GetContainer(ParentOrganizationPath + "/" + container.Name, ContainerProperties.None) == null)
            {
                throw new Exception("Container wasn't created.");
            }

            WriteResult("Container " + newContainerName + " was created successfully.\r\n");

            return(container);
        }
        public void CreateNewTM()
        {
            //Create a new testing container first
            TranslationMemoryContainer container = CreateContainer("APITest");

            //Test if TM already exists
            if (TMAlreadyExists("APISampleTest"))
            {
                throw new Exception("TM already exists!");
            }

            ServerBasedTranslationMemory newTM = new ServerBasedTranslationMemory(TMServer);

            newTM.Container   = container;
            newTM.Name        = "APISampleTest";
            newTM.Description = "A sample created as example of using TM API.";
            CreateLanguageDirections(newTM.LanguageDirections);
            newTM.LanguageResourcesTemplate = CreateLanguageResouceTemplate();
            newTM.ParentResourceGroupPath   = ParentOrganizationPath;
            newTM.Save();

            WriteResult("TM APISampleTest was created\r\n");
        }
Example #6
0
        public void CreateAdvanced(TranslationProviderServer tmServer, string organization, string newContainerName)
        {
            #region "count"
            ReadOnlyCollection <DatabaseServer> dbs = tmServer.GetDatabaseServers(DatabaseServerProperties.Containers);
            if (dbs.Count == 0)
            {
                throw new Exception("No DB server registered.");
            }
            #endregion

            #region "CheckExists"
            foreach (TranslationMemoryContainer item in dbs[0].Containers)
            {
                if (item.Name == newContainerName)
                {
                    throw new Exception("Container with that name already exists.");
                }
            }
            #endregion

            #region "CreateContainer"
            TranslationMemoryContainer container = new TranslationMemoryContainer(tmServer);
            container.DatabaseServer          = dbs[0];
            container.DatabaseName            = newContainerName + "DB";
            container.Name                    = newContainerName;
            container.ParentResourceGroupPath = organization;
            container.Save();
            #endregion

            #region "CheckCreated"
            if (!dbs[0].Containers.Contains(container))
            {
                throw new Exception("Container was not created.");
            }
            #endregion
        }
Example #7
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();
        }