public void SearchRecipeByName(string name, int page) { string realtext = name; CultureInfo currentCulture = System.Threading.Thread.CurrentThread.CurrentCulture; if (!currentCulture.TwoLetterISOLanguageName.ToLowerInvariant().Equals("es")) { var translator = new TranslationProvider(); string languagePair = string.Format("{0}|es", currentCulture.TwoLetterISOLanguageName); // we made a separate async translation to avoid screen freezing translator.TranslateTextAsync(name, languagePair); translator.TranslationEnded += (s, e) => { if (e.HasFail) { // Happens when interrupted internet connection is occuring FireProcessEnded(s, e); } else { realtext = (string)e.Result; string url = string.Format("http://s.ficfiles.com/utilisima/get_rss.php?seeker=recetas&search={0}&page={1}", realtext, page); var consumer = new WebConsumer(); consumer.GetUrlAsync(url); consumer.ResponseEnded += new EventHandler<ResultEventArgs>(rss_ResponseEnded); } }; } else { string url = string.Format("http://s.ficfiles.com/utilisima/get_rss.php?seeker=recetas&search={0}&page={1}", realtext, page); var consumer = new WebConsumer(); consumer.GetUrlAsync(url); consumer.ResponseEnded += new EventHandler<ResultEventArgs>(rss_ResponseEnded); } }
/// <summary> /// Translates text using Google Translate GET operation asynchronously /// Google URL - http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1} /// </summary> /// <param name="input">Input string</param> /// <param name="languagePair">2 letter Language Pair, delimited by "|". /// E.g. "ar|en" language pair means to translate from Arabic to English</param> /// <returns>Translated to String</returns> public void TranslateTextAsync(string input, string languagePair = "es|en") { var consumer = new WebConsumer(); consumer.ResponseEnded += new EventHandler<ResultEventArgs>(consumer_ResponseEnded); string url = String.Format(baseURL, input, languagePair); consumer.GetUrlAsync(url); }
/// <summary> /// Process a single recipe, and put the response in the result property /// </summary> /// <param name="id">the recepe id</param> public void ObtainRecipeById(string id) { // Assure Obtain Id var decExpr = new Regex("\\d+"); string realId = decExpr.Match(id).Value; string url = foxplayURL + realId; var consumer = new WebConsumer(); consumer.GetUrlAsync(url); consumer.ResponseEnded += new EventHandler<ResultEventArgs>(consumer_ResponseEnded); }
public void ObtainMostRecents() { string url = "http://www.foxplay.com/ar/lifestyle/search/recipes"; Debug.WriteLine("Llamando a {0}", foxplayURL); //var client = new WebClient(); //client.DownloadStringCompleted += recent_ResponseEnded; //client.DownloadStringAsync(new Uri(foxplayURL)); var consumer = new WebConsumer(); //consumer.ContentType = "text/html"; consumer.GetUrlAsync(url); consumer.ResponseEnded += new EventHandler<ResultEventArgs>(recent_ResponseEnded); }
/// <summary> /// Translate text using Google Translate GET operation synchronously /// </summary> /// <param name="input">Input string</param> /// <param name="languagePair">2 letter Language Pair, delimited by "|". /// E.g. "ar|en" language pair means to translate from Arabic to English</param> /// <returns>Translated to String</returns> public string TranslateText(string input, string languagePair = "es|en") { var consumer = new WebConsumer(); consumer.ResponseEnded +=new EventHandler<ResultEventArgs>(Sync_ResponseEnded); string url = String.Format(baseURL, input, languagePair); consumer.GetUrlAsync(url); //translatedText = consumer.GetUrl(url); // Wait until the call is finished autoResetEvent.WaitOne(); return translatedText; }
public TranslationProvider() { consumer = new WebConsumer(); }