Esempio n. 1
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            lock (viewState)
            {
                if (string.IsNullOrEmpty(viewState))
                {                  //emulate first access to site
                    WebRequestHelper helpertop =
                        new WebRequestHelper(result, new Uri("http://www.online-translator.com/Default.aspx/Text"),
                                             networkSetting,
                                             WebRequestContentType.UrlEncodedGet);

                    string responseFromServertop = helpertop.GetResponse();
                    viewState = StringParser.Parse("id=\"__VIEWSTATE\" value=\"", "\"", responseFromServertop);
                    prevPage  = StringParser.Parse("id=\"__PREVIOUSPAGE\" value=\"", "\"", responseFromServertop);
                }
            }

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri("http://www.online-translator.com/Default.aspx/Text"),
                                     networkSetting,
                                     WebRequestContentType.UrlEncoded);

            //query
            lock (viewState)
            {
                //string query = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE={0}&ctl00%24SiteContent%24ucTextTranslator%24tbFromAddr=&ctl00%24SiteContent%24ucTextTranslator%24tbToAddr=&ctl00%24SiteContent%24ucTextTranslator%24tbCCAddr=&ctl00%24SiteContent%24ucTextTranslator%24tbSubject=&ctl00%24SiteContent%24ucTextTranslator%24tbBody=&ctl00%24SiteContent%24ucTextTranslator%24templates={1}&ctl00%24SiteContent%24ucTextTranslator%24checkShowVariants=on&ctl00%24SiteContent%24ucTextTranslator%24dlTemplates=General&ctl00%24SiteContent%24ucTextTranslator%24sourceText={2}&resultText=&ctl00%24SiteContent%24ucTextTranslator%24dlDirections={3}&ctl00%24SiteContent%24ucTextTranslator%24bTranslate=Translate&ctl00%24tbEmail=&ctl00%24tbName=&ctl00%24tbComment=&ctl00%24pollDiv%24tbSiteLang=en";
                string query = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE={0}&ctl00%24SiteContent%24MA_trasnlform%24selected_tab=text&chLangs=true&ctl00%24SiteContent%24MA_trasnlform%24rblTemplates=General&ctl00%24SiteContent%24MA_trasnlform%24otherTemplatesInput={1}&ctl00%24SiteContent%24MA_trasnlform%24sourceText={2}&ctl00%24SiteContent%24MA_trasnlform%24sLang={3}&ctl00%24SiteContent%24MA_trasnlform%24rLang={4}&ctl00%24SiteContent%24MA_trasnlform%24bTranslate=Translate&ctl00%24SiteContent%24MA_trasnlform%24changedFieldToAddr=&ctl00%24SiteContent%24MA_trasnlform%24hiddenDir=&ctl00%24SiteContent%24MA_trasnlform%24hiddenTranid=&ctl00%24changedField=&__PREVIOUSPAGE={5}";
                query = string.Format(query,
                                      HttpUtility.UrlEncode(viewState),
                                      PromtUtils.GetSubject(subject),
                                      HttpUtility.UrlEncode(phrase),
                                      PromtUtils.ConvertLanguage(languagesPair.From),
                                      PromtUtils.ConvertLanguage(languagesPair.To),
                                      prevPage);
                helper.AddPostData(query);
            }



            string responseFromServer = helper.GetResponse();

            string translation = StringParser.Parse("class=\"send_win\">", "</textarea>", responseFromServer);

            result.Translations.Add(translation);
            lock (viewState)
            {
                viewState = StringParser.Parse("id=\"__VIEWSTATE\" value=\"", "\"", responseFromServer);
                prevPage  = StringParser.Parse("id=\"__PREVIOUSPAGE\" value=\"", "\"", responseFromServer);
            }
        }
Esempio n. 2
0
        protected override void DoTranslate(string phrase, LanguagePair languagesPair, string subject, Result result, NetworkSetting networkSetting)
        {
            string query = "http://www.online-translator.com/text/references.aspx?prmtlang=en&direction={0}&word={1}";

            query = string.Format(query, PromtUtils.ConvertLanguagesPair(languagesPair),
                                  HttpUtility.UrlEncode(phrase));

            WebRequestHelper helper =
                new WebRequestHelper(result, new Uri(query),
                                     networkSetting,
                                     WebRequestContentType.UrlEncodedGet);

            string responseFromServer = helper.GetResponse();

            if (responseFromServer.IndexOf("class=\"ref_not_found\"") >= 0)
            {
                result.ResultNotFound = true;
                throw new TranslationException("Nothing found");
            }

            result.ArticleUrl        = query;
            result.ArticleUrlCaption = phrase;


            StringParser parser = new StringParser(responseFromServer);

            string[] translation_list = parser.ReadItemsList("<span class=\"ref_source\"", "</table>");

            string       subphrase;
            string       abbreviation;
            Result       child;
            StringParser subparser;

            foreach (string translation in translation_list)
            {
                subphrase          = StringParser.Parse(">", "</span>", translation);
                abbreviation       = StringParser.Parse("<span class=\"ref_psp\">", "</span>", translation);
                child              = CreateNewResult(subphrase, languagesPair, subject);
                child.Abbreviation = abbreviation;
                result.Childs.Add(child);
                subparser = new StringParser(translation);
                string[] subtranslation_list = subparser.ReadItemsList("<span class=\"ref_result\">", "</span>");
                foreach (string subtranslation in subtranslation_list)
                {
                    child.Translations.Add(HttpUtility.HtmlDecode(subtranslation));
                }
            }
        }
Esempio n. 3
0
 public PromtBaseTranslator()
 {
     PromtUtils.InitServiceItem(this);
 }