Пример #1
0
        public static Text TranslateFromGerman(Text text, Location location, ref Server1State server1State)
        {
            bool useServer1 = true;

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

            if (useServer1)
            {
                try
                {
                    var result = TranslateFromGermanViaServer1(text, location);

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

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

            return(TranslateFromGermanViaServer2(text, location));
        }
Пример #2
0
        static void Main(string[] args)
        {
            Server1State server1StateForLocationA = new Server1State(false, DateTime.MinValue);

            FolderProcessingModule.TranslateDocumentsInFolder(
                "c:\\inputFolder1",
                "c:\\outputFolder1",
                document => DocumentTranslationModule.TranslateDocument(
                    document,
                    paragraph => DocumentTranslationModule.TranslateParagraph(
                        paragraph,
                        paragraphText => DocumentTranslationModule.TranslateText(
                            paragraphText,
                            text => GermanTextTranslationModule.TranslateFromGerman(
                                text,
                                Location.A,
                                ref server1StateForLocationA),
                            text => SpanishTextTranslationModule.TranslateFromSpanish(
                                text,
                                Location.A,
                                ref server1StateForLocationA)))));

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

            FolderProcessingModule.TranslateDocumentsInFolder(
                "c:\\inputFolder2",
                "c:\\outputFolder2",
                document => DocumentTranslationModule.TranslateDocument(
                    document,
                    paragraph => DocumentTranslationModule.TranslateParagraph(
                        paragraph,
                        paragraphText => DocumentTranslationModule.TranslateText(
                            paragraphText,
                            text => GermanTextTranslationModule.TranslateFromGerman(
                                text,
                                Location.B,
                                ref server1StateForLocationB),
                            text => SpanishTextTranslationModule.TranslateFromSpanish(
                                text,
                                Location.B,
                                ref server1StateForLocationB)))));
        }