Esempio n. 1
0
        public void ImportTmx(TranslationProviderServer tmServer, string orgName, string tmName, string importFilePath)
        {
            if (!orgName.StartsWith("/"))
            {
                orgName = "/" + orgName;
            }
            if (!orgName.EndsWith("/"))
            {
                orgName += "/";
            }
            #region "OpenTm"
            ServerBasedTranslationMemory tm = tmServer.GetTranslationMemory(
                orgName + tmName, TranslationMemoryProperties.All);
            #endregion

            #region "importer"
            ScheduledTranslationMemoryImportOperation importer = new ScheduledTranslationMemoryImportOperation(
                this.GetLanguageDirection(tm, CultureInfo.GetCultureInfo("en-US"), CultureInfo.GetCultureInfo("de-DE")));
            #endregion

            #region "params"
            importer.ChunkSize       = 25;
            importer.ContinueOnError = true;
            importer.Source          = new FileInfo(importFilePath);
            this.GetImportSettings(importer.ImportSettings);
            #endregion

            #region "upload"
            importer.Create();
            importer.Upload(this.importer_Uploaded);
            importer.Queue();
            #endregion

            #region "wait"
            bool continueWaiting = true;
            while (continueWaiting)
            {
                switch (importer.Status)
                {
                case ScheduledOperationStatus.Abort:
                case ScheduledOperationStatus.Aborted:
                case ScheduledOperationStatus.Cancel:
                case ScheduledOperationStatus.Cancelled:
                case ScheduledOperationStatus.Completed:
                case ScheduledOperationStatus.Error:
                    continueWaiting = false;
                    break;

                case ScheduledOperationStatus.Aborting:
                case ScheduledOperationStatus.Allocated:
                case ScheduledOperationStatus.Cancelling:
                case ScheduledOperationStatus.NotSet:
                case ScheduledOperationStatus.Queued:
                case ScheduledOperationStatus.Recovered:
                case ScheduledOperationStatus.Recovering:
                case ScheduledOperationStatus.Recovery:
                    continueWaiting = true;
                    importer.Refresh();
                    break;

                default:
                    continueWaiting = false;
                    break;
                }
            }
            #endregion

            #region "completed"
            if (importer.Status == ScheduledOperationStatus.Completed)
            {
                MessageBox.Show("Import successfuly finished.");
            }
            else if (importer.Status == ScheduledOperationStatus.Error)
            {
                MessageBox.Show(importer.ErrorMessage);
            }
            else
            {
                MessageBox.Show("Import didn't finish.");
            }
            #endregion
        }
        public void ImportTMX(string importFilePath)
        {
            ServerBasedTranslationMemory tm = TMServer.GetTranslationMemory(ParentOrganizationPath + "/APISampleTest", TranslationMemoryProperties.All);
            ScheduledTranslationMemoryImportOperation importer =
                new ScheduledTranslationMemoryImportOperation(
                    GetLanguageDirection(tm, CultureInfo.GetCultureInfo("en-US"), CultureInfo.GetCultureInfo("de-DE")));

            importer.ChunkSize       = 25; //25 is minimum
            importer.ContinueOnError = true;
            importer.Source          = new FileInfo(importFilePath);
            AdaptImportSettigns(importer.ImportSettings);

            //create import placeholder in the TM server
            importer.Create();
            //Uploads the source file
            importer.Upload(importer_Uploaded);
            //add the import into the queue
            importer.Queue();

            //Wait until the import is finished
            bool continueWaiting = true;

            while (continueWaiting)
            {
                switch (importer.Status)
                {
                case ScheduledOperationStatus.Abort:
                case ScheduledOperationStatus.Aborted:
                case ScheduledOperationStatus.Cancel:
                case ScheduledOperationStatus.Cancelled:
                case ScheduledOperationStatus.Completed:
                case ScheduledOperationStatus.Error:
                    continueWaiting = false;
                    break;

                case ScheduledOperationStatus.Aborting:
                case ScheduledOperationStatus.Allocated:
                case ScheduledOperationStatus.Cancelling:
                case ScheduledOperationStatus.NotSet:
                case ScheduledOperationStatus.Queued:
                case ScheduledOperationStatus.Recovered:
                case ScheduledOperationStatus.Recovering:
                case ScheduledOperationStatus.Recovery:
                    continueWaiting = true;
                    importer.Refresh();     //refresh the state of the import
                    break;

                default:
                    continueWaiting = false;
                    break;
                }
            }

            if (importer.Status == ScheduledOperationStatus.Completed)
            {
                WriteResult("Import successfuly finished.\r\n");
            }
            else if (importer.Status == ScheduledOperationStatus.Error)
            {
                WriteResult(importer.ErrorMessage);
            }
            else
            {
                WriteResult("Import didn't finish.\r\n");
            }
        }