Esempio n. 1
0
        public void Execute()
        {
            var uri = new Uri(@"Add your url");
            var translationProviderServer = new TranslationProviderServer(uri, false, "user name", "password");

            //Add Translation memory id
            var guid = new Guid("");
            var tm   = translationProviderServer.GetTranslationMemory(guid, TranslationMemoryProperties.None);

            var langDirection    = tm.GetLanguageDirection(new LanguagePair(new CultureInfo("en-us"), new CultureInfo("ro-ro")));
            var iterator         = new RegularIterator(10);
            var translationUnits = langDirection.GetTranslationUnits(ref iterator);
            //Add the id of the translation unit you want to update
            var tu = langDirection.GetTranslationUnit(
                new PersistentObjectToken(1, new Guid("")));

            //segment visitor
            var textVisitor    = new TextVisitor();
            var segmentElement = tu.TargetSegment.Elements[0];

            segmentElement.AcceptSegmentElementVisitor(textVisitor);

            langDirection.UpdateTranslationUnit(tu);
            tm.Save();
        }
        /// <summary>
        /// Anonymizez each unique name from the UniqueUserNames list found in a specific Server Based Translation Memory
        /// </summary>
        /// <param name="tm">Translation Memory File</param>
        /// <param name="uniqueUsers">List of UniqueUserName objects</param>
        /// /// <param name="translationProvideServer">Translation provider</param>
        public static void AnonymizeServerBasedSystemFields(TmFile tm, List <User> uniqueUsers, TranslationProviderServer translationProvideServer)
        {
            var serverBasedTm      = translationProvideServer.GetTranslationMemory(tm.Path, TranslationMemoryProperties.All);
            var languageDirections = serverBasedTm.LanguageDirections;
            var translationUnits   = GetServerBasedTranslationUnits(serverBasedTm.LanguageDirections);

            foreach (var userName in uniqueUsers)
            {
                if (userName.IsSelected && !string.IsNullOrEmpty(userName.Alias))
                {
                    foreach (var tu in translationUnits)
                    {
                        if (userName.UserName == tu.SystemFields.CreationUser || userName.UserName == tu.SystemFields.UseUser)
                        {
                            tu.SystemFields.CreationUser = userName.Alias;
                            tu.SystemFields.UseUser      = userName.Alias;
                            foreach (var languageDirection in languageDirections)
                            {
                                languageDirection.UpdateTranslationUnit(tu);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 private void btnReindex_Click(object sender, EventArgs e)
 {
     if (tabControlTMLifting.SelectedTab == tabControlTMLifting.TabPages["tabPageFileBasedTM"])
     {
         var tms = lstTms.Items.OfType <TranslationMemoryInfo>().ToList();
         if (tms.Capacity > 0)
         {
             groupBoxProgress.Visible   = true;
             labelMessage.Text          = "In progress, please wait... ";
             progressBarFileBased.Style = ProgressBarStyle.Marquee;
             btnReindex.Enabled         = false;
             _bw.RunWorkerAsync(tms);
             cancelBtn.Enabled = true;
         }
     }
     else
     {
         foreach (dynamic row in gridServerBasedTMs.SelectedRows)
         {
             var selectedRow         = gridServerBasedTMs.Rows[row.Index].DataBoundItem as TranslationMemoryDetails;
             var uriServer           = new Uri(Properties.Settings.Default.Uri);
             var translationProvider = new TranslationProviderServer(uriServer, false,
                                                                     Properties.Settings.Default.UserName,
                                                                     Properties.Settings.Default.Password);
             var selectedTm       = translationProvider.GetTranslationMemory(selectedRow.Id, TranslationMemoryProperties.None);
             var reindexOperation = new ScheduledReindexOperation()
             {
                 TranslationMemory = selectedTm
             };
             reindexOperation.Refresh();
             reindexOperation.Queue();
             gridServerBasedTMs.Rows[row.Index].Cells["Status"].Value = reindexOperation.Status;
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Selects the particular server TM as chosen by the user through the dropdown list.
        /// </summary>
        public void SelectServerTm(string tmName, string uri, string userName, string password)
        {
            var tmServer = new TranslationProviderServer(GetUri(uri), false, userName, password);

            ServerTM = tmServer.GetTranslationMemory(tmName,
                                                     TranslationMemoryProperties.None);
            Server = true;
        }
Esempio n. 5
0
        public static AnonymizeTranslationMemory ServerBasedTmGetTranslationUnits(TranslationProviderServer translationProvider, string tmPath,
                                                                                  ObservableCollection <SourceSearchResult> sourceSearchResult, List <Rule> selectedRules)
        {
            var allTusForLanguageDirections = new List <TranslationUnit>();

            System.Windows.Application.Current.Dispatcher.Invoke(delegate
            {
                var translationMemory  = translationProvider.GetTranslationMemory(tmPath, TranslationMemoryProperties.All);
                var languageDirections = translationMemory.LanguageDirections;
                var pi = new PersonalInformation(selectedRules);

                foreach (var languageDirection in languageDirections)
                {
                    var unitsCount       = languageDirection.GetTranslationUnitCount();
                    var tmIterator       = new RegularIterator(unitsCount);
                    var translationUnits = languageDirection.GetTranslationUnits(ref tmIterator);
                    if (translationUnits != null)
                    {
                        allTusForLanguageDirections.AddRange(translationUnits);
                        foreach (var translationUnit in translationUnits)
                        {
                            var sourceText = translationUnit.SourceSegment.ToPlain();
                            if (pi.ContainsPi(sourceText))
                            {
                                var searchResult = new SourceSearchResult
                                {
                                    Id          = translationUnit.ResourceId.Guid.ToString(),
                                    SourceText  = sourceText,
                                    MatchResult = new MatchResult
                                    {
                                        Positions = pi.GetPersonalDataPositions(sourceText)
                                    },
                                    TmFilePath    = tmPath,
                                    IsServer      = true,
                                    SegmentNumber = translationUnit.ResourceId.Id.ToString()
                                };
                                var targetText = translationUnit.TargetSegment.ToPlain();
                                if (pi.ContainsPi(targetText))
                                {
                                    searchResult.TargetText        = targetText;
                                    searchResult.TargetMatchResult = new MatchResult
                                    {
                                        Positions = pi.GetPersonalDataPositions(targetText)
                                    };
                                }
                                sourceSearchResult.Add(searchResult);
                            }
                        }
                    }
                }
            });
            return(new AnonymizeTranslationMemory
            {
                TmPath = tmPath,
                TranslationUnits = allTusForLanguageDirections
            });
        }
        /// <summary>
        /// Gets unique System Fields values from Server Based Translation Memory
        /// </summary>
        /// <param name="tm">Translation Memory File</param>
        /// <param name="translationProvideServer">Translation provider</param>
        /// <returns>An ObservableCollection of UniqueUserName objects</returns>
        /// TODO: SIMPLIFY METHOD
        public static ObservableCollection <User> GetUniqueServerBasedSystemFields(TmFile tm, TranslationProviderServer translationProvideServer)
        {
            var users            = new List <User>();
            var listOfFieldNames = new List <string>();

            var translationMemory     = translationProvideServer.GetTranslationMemory(tm.Path, TranslationMemoryProperties.All);
            var translationUnits      = GetServerBasedTranslationUnits(translationMemory.LanguageDirections);
            var uniqueUsersCollection = GetuniqueUserCollection(users, listOfFieldNames, translationUnits);

            return(uniqueUsersCollection);
        }
Esempio n. 7
0
        public Report AnonymizeServerBasedCustomFields(ProgressDialogContext context, TmFile tmFile, List <CustomField> customFields, TranslationProviderServer translationProvideServer)
        {
            _tmService.BackupServerBasedTms(context, new List <TmFile> {
                tmFile
            });

            var serverBasedTm = translationProvideServer.GetTranslationMemory(tmFile.Path, TranslationMemoryProperties.All);

            var languageDirections = new List <LanguageDirection>();

            foreach (var languageDirection in serverBasedTm.LanguageDirections)
            {
                languageDirections.Add(new LanguageDirection
                {
                    Source = languageDirection.SourceLanguage,
                    Target = languageDirection.TargetLanguage
                });
            }

            var translationUnits = _tmService.LoadTranslationUnits(context, tmFile, translationProvideServer, languageDirections);

            var units = GetUpdatableTranslationUnits(customFields, translationUnits);

            var report = new Report(tmFile)
            {
                ReportFullPath = _settingsService.GetLogReportFullPath(tmFile.Name, Report.ReportScope.CustomFields),
                UpdatedCount   = units.Count,
                Scope          = Report.ReportScope.CustomFields,
            };

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var changesReport = GetCustomFieldChangesReport(units, customFields);

            foreach (var change in changesReport)
            {
                report.Actions.AddRange(change.Value);
            }

            UpdateCustomFieldPickLists(context, customFields, serverBasedTm);

            UpdateCustomFields(context, tmFile, translationUnits, units, serverBasedTm);

            ClearPreviousCustomFieldValues(translationUnits);

            stopWatch.Stop();
            report.ElapsedSeconds = stopWatch.Elapsed.TotalSeconds;

            return(report);
        }
Esempio n. 8
0
        public void DeleteTm(TranslationProviderServer tmServer, string organizationPath, string tmName)
        {
            string tmPath = organizationPath;

            if (!tmPath.EndsWith("/"))
            {
                tmPath += "/";
            }

            ServerBasedTranslationMemory tm = tmServer.GetTranslationMemory(tmPath + tmName, TranslationMemoryProperties.All);

            tm.Delete();
        }
Esempio n. 9
0
 public static void AnonymizeServerBasedTu(TranslationProviderServer translationProvider,
                                           List <AnonymizeTranslationMemory> tusToAnonymize)
 {
     try
     {
         foreach (var tuToAonymize in tusToAnonymize)
         {
             var translationMemory =
                 translationProvider.GetTranslationMemory(tuToAonymize.TmPath, TranslationMemoryProperties.All);
             var languageDirections = translationMemory.LanguageDirections;
             foreach (var languageDirection in languageDirections)
             {
                 foreach (var translationUnit in tuToAonymize.TranslationUnits)
                 {
                     var sourceTranslationElements = translationUnit.SourceSegment.Elements.ToList();
                     var elementsContainsTag       =
                         sourceTranslationElements.Any(s => s.GetType().UnderlyingSystemType.Name.Equals("Tag"));
                     if (elementsContainsTag)
                     {
                         AnonymizeSegmentsWithTags(translationUnit, sourceTranslationElements, true);
                     }
                     else
                     {
                         AnonymizeSegmentsWithoutTags(translationUnit, sourceTranslationElements, true);
                     }
                     languageDirection.UpdateTranslationUnit(translationUnit);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         if (exception.Message.Equals("One or more errors occurred."))
         {
             if (exception.InnerException != null)
             {
                 MessageBox.Show(exception.InnerException.Message,
                                 "", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             MessageBox.Show(exception.Message,
                             "", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Esempio n. 10
0
        private void ImportXliffToExistingTm()
        {
            var uri = new Uri(@"uri");

            var translationProviderServer = new TranslationProviderServer(uri, false, "user name", "password");

            //Import to existing tm
            var guid          = new Guid("Existing TM Guid");
            var tm            = translationProviderServer.GetTranslationMemory(guid, TranslationMemoryProperties.None);
            var langDirection = tm.LanguageDirections;

            var import = new ScheduledServerTranslationMemoryImport(langDirection[0])
            {
                Source = new FileInfo(@"path to xliff")
            };

            import.Queue();
        }
Esempio n. 11
0
        public Report AnonymizeServerBasedSystemFields(ProgressDialogContext context, TmFile tmFile, List <User> uniqueUsers, TranslationProviderServer translationProvideServer)
        {
            _tmService.BackupServerBasedTms(context, new List <TmFile> {
                tmFile
            });

            var serverBasedTm = translationProvideServer.GetTranslationMemory(tmFile.Path, TranslationMemoryProperties.All);

            var languageDirections = new List <LanguageDirection>();

            foreach (var languageDirection in serverBasedTm.LanguageDirections)
            {
                languageDirections.Add(new LanguageDirection
                {
                    Source = languageDirection.SourceLanguage,
                    Target = languageDirection.TargetLanguage
                });
            }

            var translationUnits = _tmService.LoadTranslationUnits(context, tmFile, translationProvideServer, languageDirections);

            var report = new Report(tmFile)
            {
                ReportFullPath = _settingsService.GetLogReportFullPath(tmFile.Name, Report.ReportScope.SystemFields),
                UpdatedCount   = translationUnits.Count,
                Scope          = Report.ReportScope.SystemFields,
            };


            report.Actions.AddRange(GetSystemFieldChangesReport(uniqueUsers));

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            report.UpdatedCount = UpdateSystemFields(context, tmFile, uniqueUsers, translationUnits, serverBasedTm);

            stopWatch.Stop();
            report.ElapsedSeconds = stopWatch.Elapsed.TotalSeconds;

            return(report);
        }
Esempio n. 12
0
        public List <CustomField> GetServerBasedCustomFields(ProgressDialogContext context, TmFile tm, TranslationProviderServer translationProvideServer)
        {
            var translationMemory = translationProvideServer.GetTranslationMemory(tm.Path, TranslationMemoryProperties.All);

            var translationUnits = new List <TmTranslationUnit>();

            foreach (var languageDirection in translationMemory.LanguageDirections)
            {
                var tus = _tmService.LoadTranslationUnits(context, tm, translationProvideServer, new LanguageDirection
                {
                    Source = languageDirection.SourceLanguage,
                    Target = languageDirection.TargetLanguage
                });

                if (tus != null)
                {
                    translationUnits.AddRange(tus);
                }
            }

            var customFieldList = GetCustomFieldList(translationMemory.FieldDefinitions, translationUnits, tm.Path);

            return(customFieldList);
        }
Esempio n. 13
0
        public List <User> GetUniqueServerBasedSystemFields(ProgressDialogContext context, TmFile tm, TranslationProviderServer translationProvideServer)
        {
            var translationMemory = translationProvideServer.GetTranslationMemory(tm.Path, TranslationMemoryProperties.All);

            var translationUnits = new List <TmTranslationUnit>();

            foreach (var languageDirection in translationMemory.LanguageDirections)
            {
                var tus = _tmService.LoadTranslationUnits(context, tm, translationProvideServer, new LanguageDirection
                {
                    Source = languageDirection.SourceLanguage,
                    Target = languageDirection.TargetLanguage
                });

                if (tus != null)
                {
                    translationUnits.AddRange(tus);
                }
            }

            var uniqueUsersCollection = GetUniqueUserCollection(tm.Path, translationUnits.ToArray());

            return(uniqueUsersCollection);
        }
        private void BackupServerBasedTm(TranslationProviderServer translationProvider,
                                         List <AnonymizeTranslationMemory> tusToAnonymize)
        {
            _backupTms.Clear();
            if (!Directory.Exists(Constants.ServerTmBackupPath))
            {
                Directory.CreateDirectory(Constants.ServerTmBackupPath);
            }
            try
            {
                foreach (var tuToAonymize in tusToAnonymize)
                {
                    var translationMemory =
                        translationProvider.GetTranslationMemory(tuToAonymize.TmPath, TranslationMemoryProperties.All);
                    var languageDirections = translationMemory.LanguageDirections;
                    foreach (var languageDirection in languageDirections)
                    {
                        var folderPath = Path.Combine(Constants.ServerTmBackupPath, translationMemory.Name,
                                                      languageDirection.TargetLanguageCode);
                        if (!Directory.Exists(folderPath))
                        {
                            Directory.CreateDirectory(folderPath);
                        }
                        var fileName = translationMemory.Name + languageDirection.TargetLanguageCode + ".tmx.gz";
                        _filePath = Path.Combine(folderPath, fileName);

                        //if tm does not exist download it
                        if (!File.Exists(_filePath))
                        {
                            _tmExporter = new ScheduledServerTranslationMemoryExport(languageDirection)
                            {
                                ContinueOnError = true
                            };
                            _tmExporter.Queue();
                            _tmExporter.Refresh();

                            var continueWaiting = true;
                            while (continueWaiting)
                            {
                                switch (_tmExporter.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:
                                    _tmExporter.Refresh();
                                    break;

                                default:
                                    continueWaiting = false;
                                    break;
                                }
                            }
                            if (_tmExporter.Status == ScheduledOperationStatus.Completed)
                            {
                                var backup = new ServerTmBackUp
                                {
                                    ScheduledExport = _tmExporter,
                                    FilePath        = _filePath
                                };
                                _backupTms.Add(backup);
                            }
                            else if (_tmExporter.Status == ScheduledOperationStatus.Error)
                            {
                                MessageBox.Show(_tmExporter.ErrorMessage,
                                                "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    if (!_backgroundWorker.IsBusy)
                    {
                        _backgroundWorker.RunWorkerAsync();
                    }
                }
            }
            catch (Exception exception)
            {
                if (exception.Message.Equals("One or more errors occurred."))
                {
                    if (exception.InnerException != null)
                    {
                        MessageBox.Show(exception.InnerException.Message,
                                        "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show(exception.Message,
                                    "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public void ExportToTmx(TranslationProviderServer tmServer, string orgName, string tmName, string exportFilePath)
        {
            #region "OpenTm"
            if (!orgName.StartsWith("/"))
            {
                orgName = "/" + orgName;
            }
            if (!orgName.EndsWith("/"))
            {
                orgName += "/";
            }
            ServerBasedTranslationMemory tm = tmServer.GetTranslationMemory(
                orgName + tmName, TranslationMemoryProperties.All);
            #endregion

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

            #region "settings"
            exporter.ChunkSize       = 25;
            exporter.ContinueOnError = true;
            #endregion

            #region "wait"
            exporter.Queue();
            exporter.Refresh();

            bool continueWaiting = true;
            while (continueWaiting)
            {
                switch (exporter.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;
                    exporter.Refresh();
                    break;

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

            #region "completed"
            if (exporter.Status == ScheduledOperationStatus.Completed)
            {
                using (Stream outputStream = new FileStream(exportFilePath, FileMode.Create))
                {
                    var result = exporter.DownloadExport(outputStream);
                    if (result)
                    {
                        MessageBox.Show("Export successfuly finished.");
                    }
                }
            }
            else if (exporter.Status == ScheduledOperationStatus.Error)
            {
                MessageBox.Show(exporter.ErrorMessage);
            }
            else
            {
                MessageBox.Show("Export did not finish.");
            }
            #endregion
        }
        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"
            ScheduledServerTranslationMemoryImport importer = new ScheduledServerTranslationMemoryImport(
                GetLanguageDirection(tm, CultureInfo.GetCultureInfo("en-US"), CultureInfo.GetCultureInfo("de-DE")));
            #endregion

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

            #region "upload"

            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
        }