public static Text TranslateFromSpanish(Text text, ref Server1State server1State)
        {
            bool useServer1 = true;

            if (server1State.Server1IsDown)
            {
                if (DateTime.Now - server1State.Server1DownSince < TimeSpan.FromMinutes(10))
                {
                    useServer1 = false;
                }
            }

            if (useServer1)
            {
                try
                {
                    var result = TranslateFromSpanishViaServer1(text);

                    server1State = new Server1State(false, DateTime.MinValue);

                    return(result);
                }
                catch
                {
                    server1State = new Server1State(true, DateTime.Now);
                }
            }

            return(TranslateFromSpanishViaServer2(text));
        }
        public static Text TranslateText(Text paragraphText, ref Server1State server1State)
        {
            var language = DetectLanguage(paragraphText);

            return(language == Language.German
                ? GermanTextTranslationModule.TranslateFromGerman(paragraphText, ref server1State)
                : SpanishTextTranslationModule.TranslateFromSpanish(paragraphText, ref server1State));
        }
        public static Document TranslateDocument(Document document, ref Server1State server1State)
        {
            var paragraphs = document.Paragraphs;

            List <Paragraph> translatedParagraphs = new List <Paragraph>();

            foreach (var paragraph in paragraphs)
            {
                translatedParagraphs.Add(TranslateParagraph(paragraph, ref server1State));
            }

            return(new Document(document.Title, translatedParagraphs.ToImmutableArray()));
        }
Пример #4
0
        static void Main(string[] args)
        {
            Server1State server1State = new Server1State(false, DateTime.MinValue);

            FolderProcessingModule.TranslateDocumentsInFolder("c:\\inputFolder", "c:\\outputFolder", ref server1State);
        }
        public static void TranslateDocumentsInFolder(string folderPath, string destinationFolderPath, ref Server1State server1State)
        {
            IEnumerable <Document> documentsEnumerable = GetDocumentsFromFolder(folderPath);

            foreach (var document in documentsEnumerable)
            {
                var translatedDocument = DocumentTranslationModule.TranslateDocument(document, ref server1State);

                WriteDocumentToDestinationFolder(translatedDocument, destinationFolderPath);
            }
        }
 public static Paragraph TranslateParagraph(Paragraph paragraph, ref Server1State server1State)
 {
     return(new Paragraph(TranslateText(paragraph.Text, ref server1State), paragraph.Color));
 }