public List <string> Translate(ITranslationService translationService, string sourceLanguageIsoCode, string targetLanguageIsoCode, List <Paragraph> sourceParagraphs, TranslationProcessCancelStatus processCancelStatus)
        {
            IEnumerable <TTranslationBaseUnit> translationBaseUnits = ConstructTranslationBaseUnits(sourceParagraphs);
            var translationChunks = BuildTranslationChunks(translationBaseUnits, translationService);

            Dictionary <int, string> targetParagraphs = new Dictionary <int, string>();

            foreach (TranslationChunk translationChunk in translationChunks)
            {
                List <string> result = translationService.Translate(sourceLanguageIsoCode, targetLanguageIsoCode, translationChunk.TranslationUnits.ConvertAll(x => new Paragraph()
                {
                    Text = x.Text
                }));
                Dictionary <int, string> newTargetParagraphs = GetTargetParagraphs(translationChunk.TranslationUnits, result);
                foreach (KeyValuePair <int, string> newTargetParagraph in newTargetParagraphs)
                {
                    targetParagraphs[newTargetParagraph.Key] = newTargetParagraph.Value;
                }
                if (processCancelStatus != null && processCancelStatus(newTargetParagraphs)) //check if operation was canceled outside
                {
                    return(targetParagraphs.Values.ToList());
                }
            }
            return(targetParagraphs.Values.ToList());
        }
        public List <string> Translate(ITranslationService translationService, string sourceLanguageIsoCode, string targetLanguageIsoCode, List <Paragraph> sourceParagraphs, TranslationProcessCancelStatus processCancelStatus)
        {
            //remove empty paragraphs
            sourceParagraphs = sourceParagraphs.Where(p => !string.IsNullOrWhiteSpace(p.Text)).ToList();

            var translationBaseUnits = ConstructTranslationBaseUnits(sourceParagraphs);
            var translationChunks    = BuildTranslationChunks(translationBaseUnits, translationService);

            var targetParagraphs = new Dictionary <int, string>();

            foreach (var translationChunk in translationChunks)
            {
                var result = translationService.Translate(sourceLanguageIsoCode, targetLanguageIsoCode, translationChunk.TranslationUnits.ConvertAll(x => new Paragraph()
                {
                    Text = x.Text
                }));
                var newTargetParagraphs = GetTargetParagraphs(translationChunk.TranslationUnits, result);
                foreach (var newTargetParagraph in newTargetParagraphs)
                {
                    targetParagraphs[newTargetParagraph.Key] = newTargetParagraph.Value;
                }
                if (processCancelStatus != null && processCancelStatus(newTargetParagraphs)) //check if operation was canceled outside
                {
                    return(targetParagraphs.Values.ToList());
                }
            }
            return(targetParagraphs.Values.ToList());
        }