/// <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);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private static int UpdateSystemFieldsSqlite(ProgressDialogContext context, TmFile tmFile, IEnumerable <TmTranslationUnit> units, List <User> uniqueUsers)
        {
            var updatedCount = 0;

            var service = new SqliteTmService(tmFile.Path, null, new SerializerService(), new SegmentService());

            try
            {
                service.OpenConnection();

                var updateList = units.Where(unit => UpdateSystemFields(uniqueUsers, unit)).ToList();

                if (updateList.Count > 0)
                {
                    updatedCount = service.UpdateSystemFields(context, updateList);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
            finally
            {
                service.CloseConnection();
            }

            return(updatedCount);
        }
Beispiel #3
0
        private static int UpdateCustomFieldsSqlite(ProgressDialogContext context, TmFile tmFile, List <TmTranslationUnit> units)
        {
            if (units.Count == 0)
            {
                return(0);
            }

            int updatedCount;
            var service = new SqliteTmService(tmFile.Path, null, new SerializerService(), new SegmentService());

            try
            {
                service.OpenConnection();

                updatedCount = service.UpdateCustomFields(context, units);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
            finally
            {
                service.CloseConnection();
            }

            return(updatedCount);
        }
Beispiel #4
0
 public Report(TmFile tmFile)
 {
     TmFile         = tmFile;
     Actions        = new List <Model.Log.Action>();
     ElapsedSeconds = 0;
     Created        = DateTime.Now;
     Type           = "Update TM";
 }
        /// <summary>
        /// Retrieves an array of Translation Units for a File Based Translation Memory
        /// </summary>
        /// <param name="tm">Translation Memory File</param>
        /// /// <returns>Array of TranslationUnits</returns>
        private static TranslationUnit[]  GetFileBasedTranslationUnits(TmFile tm)
        {
            var fileBasedTm      = new FileBasedTranslationMemory(tm.Path);
            var unitsCount       = fileBasedTm.LanguageDirection.GetTranslationUnitCount();
            var tmIterator       = new RegularIterator(unitsCount);
            var translationUnits = fileBasedTm.LanguageDirection.GetTranslationUnits(ref tmIterator);

            return(translationUnits);
        }
        /// <summary>
        /// Gets unique System Fields values from File Based Translation Memory
        /// </summary>
        /// <param name="tm">Translation Memory File</param>
        /// <returns>An ObservableCollection of Users</returns>
        public static ObservableCollection <User> GetUniqueFileBasedSystemFields(TmFile tm)
        {
            var users                 = new List <User>();
            var listOfFieldNames      = new List <string>();
            var translationUnits      = GetFileBasedTranslationUnits(tm);
            var uniqueUsersCollection = GetuniqueUserCollection(users, listOfFieldNames, translationUnits);

            return(uniqueUsersCollection);
        }
Beispiel #7
0
        public Report AnonymizeFileBasedCustomFields(ProgressDialogContext context, TmFile tmFile, List <CustomField> customFields)
        {
            _tmService.BackupFileBasedTms(context, new List <TmFile> {
                tmFile
            });

            var tm = new FileBasedTranslationMemory(tmFile.Path);

            var translationUnits = _tmService.LoadTranslationUnits(context, tmFile, null,
                                                                   new LanguageDirection
            {
                Source = tm.LanguageDirection.SourceLanguage,
                Target = tm.LanguageDirection.TargetLanguage
            });

            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, tm);

            var settings = _settingsService.GetSettings();

            if (settings.UseSqliteApiForFileBasedTm)
            {
                UpdateCustomFieldsSqlite(context, tmFile, units);
            }
            else
            {
                UpdateCustomFields(context, tm, units);
            }

            ClearPreviousCustomFieldValues(translationUnits);

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

            return(report);
        }
        /// <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);
        }
        public static List <CustomField> GetFilebasedCustomField(TmFile tm)
        {
            var customFieldList = new List <CustomField>();


            var fileBasedTm = new FileBasedTranslationMemory(tm.Path);
            //var tm =
            //	new FileBasedTranslationMemory(@"C:\Users\aghisa\Desktop\cy-en_(Fields_and_Attributes).sdltm");
            var unitsCount = fileBasedTm.LanguageDirection.GetTranslationUnitCount();
            var tmIterator = new RegularIterator(unitsCount);
            var tus        = fileBasedTm.LanguageDirection.GetTranslationUnits(ref tmIterator);

            foreach (var field in fileBasedTm.FieldDefinitions)
            {
                if (field.IsPicklist)
                {
                    var customField = new CustomField
                    {
                        Id         = field.Id,
                        IsPickList = field.IsPicklist,
                        Name       = field.Name,
                        ValueType  = field.ValueType.ToString(),
                        Details    = new ObservableCollection <Details>(GetPickListCustomFieldValues(field))
                    };
                    customFieldList.Add(customField);
                }
                else
                {
                    var customField = new CustomField
                    {
                        Id         = field.Id,
                        IsPickList = field.IsPicklist,
                        Name       = field.Name,
                        ValueType  = field.ValueType.ToString(),
                        Details    = new ObservableCollection <Details>(GetNonPickListCustomFieldValues(tus, field.Name))
                    };
                    customFieldList.Add(customField);
                }
            }

            return(customFieldList);
        }
        /// <summary>
        /// Anonymizez each unique name from the UniqueUserNames list found in a specific File Based Translation Memory
        /// </summary>
        /// <param name="tm">Translation Memory File</param>
        /// <param name="uniqueUsers">List of UniqueUserName objects</param>
        public static void AnonymizeFileBasedSystemFields(TmFile tm, List <User> uniqueUsers)
        {
            var fileBasedTm      = new FileBasedTranslationMemory(tm.Path);
            var translationUnits = GetFileBasedTranslationUnits(tm);

            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;
                            fileBasedTm.LanguageDirection.UpdateTranslationUnit(tu);
                        }
                    }
                }
            }
        }
Beispiel #11
0
        public Report AnonymizeFileBasedSystemFields(ProgressDialogContext context, TmFile tmFile, List <User> uniqueUsers)
        {
            _tmService.BackupFileBasedTms(context, new List <TmFile> {
                tmFile
            });

            var tm = new FileBasedTranslationMemory(tmFile.Path);

            var translationUnits = _tmService.LoadTranslationUnits(context, tmFile, null, new LanguageDirection
            {
                Source = tm.LanguageDirection.SourceLanguage,
                Target = tm.LanguageDirection.TargetLanguage
            });

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

            var stopWatch = new Stopwatch();

            stopWatch.Start();

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

            var settings = _settingsService.GetSettings();

            report.UpdatedCount = settings.UseSqliteApiForFileBasedTm
                                ? UpdateSystemFieldsSqlite(context, tmFile, translationUnits, uniqueUsers)
                                : UpdateSystemFields(context, translationUnits, tm, uniqueUsers);

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

            return(report);
        }
Beispiel #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);
        }
Beispiel #13
0
        private int UpdateCustomFields(ProgressDialogContext context, TmFile tmFile, List <TmTranslationUnit> translationUnits,
                                       IReadOnlyCollection <TmTranslationUnit> units, ServerBasedTranslationMemory serverBasedTm)
        {
            var updatedCount = 0;

            decimal iCurrent    = 0;
            decimal iTotalUnits = translationUnits.Count;
            var     groupsOf    = 100;

            var tusGroups = new List <List <TmTranslationUnit> > {
                new List <TmTranslationUnit>(units)
            };

            if (units.Count > groupsOf)
            {
                tusGroups = translationUnits.ChunkBy(groupsOf);
            }

            foreach (var tus in tusGroups)
            {
                iCurrent = iCurrent + tus.Count;
                if (context != null && context.CheckCancellationPending())
                {
                    break;
                }

                var progress = iCurrent / iTotalUnits * 100;
                context?.Report(Convert.ToInt32(progress), "Updating: " + iCurrent + " of " + iTotalUnits + " Translation Units");

                foreach (var languageDirection in serverBasedTm.LanguageDirections)
                {
                    var tusToUpdate = new List <TranslationUnit>();
                    foreach (var tu in tus)
                    {
                        if (languageDirection.SourceLanguage.Name.Equals(tu.SourceSegment.Language) &&
                            languageDirection.TargetLanguage.Name.Equals(tu.TargetSegment.Language))
                        {
                            var unit = _tmService.CreateTranslationUnit(tu, languageDirection);
                            tusToUpdate.Add(unit);
                        }
                    }

                    if (tusToUpdate.Count > 0)
                    {
                        var results = languageDirection.UpdateTranslationUnits(tusToUpdate.ToArray());
                        foreach (var result in results)
                        {
                            if (result.Action != LanguagePlatform.TranslationMemory.Action.Error)
                            {
                                updatedCount++;
                            }
                        }
                    }
                }
            }

            foreach (var languageDirection in tmFile.TmLanguageDirections)
            {
                _tmService.SaveTmCacheStorage(context, tmFile, languageDirection);
            }

            return(updatedCount);
        }
Beispiel #14
0
        private int UpdateSystemFields(ProgressDialogContext context, TmFile tmFile, List <User> uniqueUsers,
                                       List <TmTranslationUnit> translationUnits, ServerBasedTranslationMemory serverBasedTm)
        {
            var     updatedCount = 0;
            decimal iCurrent     = 0;
            decimal iTotalUnits  = translationUnits.Count;
            var     groupsOf     = 100;

            var tusGroups = new List <List <TmTranslationUnit> > {
                new List <TmTranslationUnit>(translationUnits)
            };

            if (translationUnits.Count > groupsOf)
            {
                tusGroups = translationUnits.ChunkBy(groupsOf);
            }

            foreach (var tus in tusGroups)
            {
                iCurrent = iCurrent + tus.Count;
                if (context != null && context.CheckCancellationPending())
                {
                    break;
                }

                var progress = iCurrent / iTotalUnits * 100;
                context?.Report(Convert.ToInt32(progress), string.Format(StringResources.Updating_0_of_1_Translation_Units, iCurrent, iTotalUnits));

                var filteredTusToUpdate = new List <TmTranslationUnit>();
                foreach (var tu in tus)
                {
                    if (UpdateSystemFields(uniqueUsers, tu))
                    {
                        filteredTusToUpdate.Add(tu);
                    }
                }

                if (filteredTusToUpdate.Count > 0)
                {
                    foreach (var languageDirection in serverBasedTm.LanguageDirections)
                    {
                        var tusToUpdate = new List <TranslationUnit>();
                        foreach (var tu in filteredTusToUpdate)
                        {
                            if (languageDirection.SourceLanguage.Name.Equals(tu.SourceSegment.Language) &&
                                languageDirection.TargetLanguage.Name.Equals(tu.TargetSegment.Language))
                            {
                                var unit = _tmService.CreateTranslationUnit(tu, languageDirection);
                                tusToUpdate.Add(unit);
                            }
                        }

                        if (tusToUpdate.Count > 0)
                        {
                            var results = languageDirection.UpdateTranslationUnits(tusToUpdate.ToArray());
                            updatedCount += results.Count(result => result.Action != LanguagePlatform.TranslationMemory.Action.Error);
                        }
                    }
                }
            }

            serverBasedTm.Save();

            foreach (var languageDirection in tmFile.TmLanguageDirections)
            {
                _tmService.SaveTmCacheStorage(context, tmFile, languageDirection);
            }

            return(updatedCount);
        }
Beispiel #15
0
        public List <User> GetUniqueFileBasedSystemFields(ProgressDialogContext context, TmFile tm)
        {
            var translationMemory = new FileBasedTranslationMemory(tm.Path);

            var tus = _tmService.LoadTranslationUnits(context, tm, null, new LanguageDirection
            {
                Source = translationMemory.LanguageDirection.SourceLanguage,
                Target = translationMemory.LanguageDirection.TargetLanguage
            });

            if (tus != null)
            {
                var uniqueUsersCollection = GetUniqueUserCollection(tm.Path, tus);

                return(uniqueUsersCollection);
            }

            return(null);
        }
Beispiel #16
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);
        }
Beispiel #17
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);
        }
Beispiel #18
0
        public List <CustomField> GetFilebasedCustomField(ProgressDialogContext context, TmFile tm)
        {
            var translationMemory = new FileBasedTranslationMemory(tm.Path);

            var tus = _tmService.LoadTranslationUnits(context, tm, null, new LanguageDirection
            {
                Source = translationMemory.LanguageDirection.SourceLanguage,
                Target = translationMemory.LanguageDirection.TargetLanguage
            });

            if (tus != null)
            {
                var customFieldList = GetCustomFieldList(translationMemory.FieldDefinitions, tus, tm.Path);
                return(customFieldList);
            }

            return(null);
        }
Beispiel #19
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);
        }