Example #1
0
        private int UpdateCustomFields(ProgressDialogContext context, ILocalTranslationMemory tm, List <TmTranslationUnit> units)
        {
            var updatedCount = 0;

            decimal iCurrent    = 0;
            decimal iTotalUnits = units.Count;
            var     groupsOf    = 200;

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

            if (units.Count > groupsOf)
            {
                tusGroups = units.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");

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

                        tusToUpdate.Add(unit);
                    }
                }

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

            return(updatedCount);
        }
Example #2
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);
        }