private void consumer_ResponseEnded(object sender, ResultEventArgs e) { ResultEventArgs newEv = null; if (e.HasFail) { newEv = e; } else { newEv = new ResultEventArgs { Result = ProcessResponse(e) }; } if (TranslationEnded != null) TranslationEnded(sender, newEv); }
private void consumer_ResponseEnded(object sender, ResultEventArgs e) { ResultEventArgs newEv = null; if (e.HasFail) { newEv = e; } else { //var recipe = ProcessHtmlResponse((string)e.Result); var recipe = ConvertIntoRecipe((string)e.Result); DateTime now = DateTime.Now; Debug.WriteLine("----> Translate Started at {0}", now); TranslateRecipeMicrosoft(recipe); TimeSpan span = DateTime.Now.Subtract(now); Debug.WriteLine("----> Translate Time Elapsed {0}", span.ToString()); newEv = new ResultEventArgs { Result = recipe }; } FireProcessEnded(sender, newEv); }
private void rss_ResponseEnded(object sender, ResultEventArgs e) { ResultEventArgs newEv = null; if (e.HasFail) { newEv = e; } else { newEv = new ResultEventArgs { Result = ProcessRssResponse((string)e.Result) }; } FireProcessEnded(sender, newEv); }
private string ProcessResponse(ResultEventArgs e) { translatedText = (string)e.Result; string pattern = "TRANSLATED_TEXT='"; int indexFrom = translatedText.IndexOf(pattern); int indexTo = translatedText.IndexOf("'", indexFrom + pattern.Length); return translatedText.Substring(indexFrom + pattern.Length, indexTo - (indexFrom + pattern.Length)); }
private void Sync_ResponseEnded(object sender, ResultEventArgs e) { ResultEventArgs newEv = null; if (e.HasFail) { newEv = e; } else { translatedText = ProcessResponse(e); } autoResetEvent.Set(); }
private void UpdateUI(ResultEventArgs e) { var list = e.Result as List<Recipe>; if (list != null) { foreach (var item in list) { var vm = new ItemViewModel { Author = item.Author, Title = item.Title, RecipeLink = item.LinkUrl }; vm.SetImageRecipeFrom(item.ImageUrl); RecentRecipes.Add(vm); } UpdateHistoryUI(); } else if(e.Result is string) { string msg = (string)e.Result; MessageBox.Show(msg, "Error", MessageBoxButton.OK); } else if (e.Result is Exception) { var ex = ((Exception)e.Result); BugSenseHandler.Instance.SendException(ex); string msg = ex.Message; MessageBox.Show(msg, "Error", MessageBoxButton.OK); } this.IsDataLoaded = true; ProgressVisibility = Visibility.Collapsed; }
private void UpdateSearchUI(ResultEventArgs e) { var list = e.Result as List<Recipe>; if (list != null) { FoundRecipes.Clear(); foreach (var item in list) { var vm = new ItemViewModel { Author = item.Author, Title = item.Title, RecipeLink = item.LinkUrl }; vm.SetImageRecipeFrom(item.ImageUrl); FoundRecipes.Add(vm); } this.IsDataLoaded = true; ProgressVisibility = Visibility.Collapsed; } }
private void SearchProcessEndedHandler(object sender, ResultEventArgs e) { Deployment.Current.Dispatcher.BeginInvoke(() => UpdateSearchUI(e)); provider.ProcessEnded -= SearchProcessEndedHandler; }
private void LoadProcessEndedHandler(object sender, ResultEventArgs e) { Deployment.Current.Dispatcher.BeginInvoke(() => { UpdateUI(e); }); provider.ProcessEnded -= LoadProcessEndedHandler; }
private void UpdateUI(ResultEventArgs e) { if (e.HasFail) { var ex = (Exception)e.Result; MessageBox.Show(ex.Message); return; } Recipe item = (Recipe)e.Result; var vm = new ItemViewModel { Author = item.Author, Title = item.Title, RecipeLink = item.LinkUrl, Procedure = item.Procedure, Category = item.Category, Portions = item.Portions, MainIngredient = item.MainIngredient }; vm.SetImageRecipeFrom(item.ImageUrl); CurrentRecipe = vm; if (item.Ingridients != null) item.Ingridients.ForEach(ingr => CurrentRecipe.Ingridients.Add(ingr)); ProgressVisibility = Visibility.Collapsed; UpdateAlarmSection(item); }
private void ResponseCallBack(IAsyncResult ar) { ResultEventArgs resultEventArgs = null; string htmldoc = string.Empty; try { var response = webRequest.EndGetResponse(ar); Stream streamResponse = response.GetResponseStream(); StreamReader streamRead = new StreamReader(streamResponse); htmldoc = streamRead.ReadToEnd(); streamResponse.Close(); streamRead.Close(); resultEventArgs = new ResultEventArgs { HasFail = false, Result = htmldoc }; } catch (System.Net.WebException ex) { resultEventArgs = new ResultEventArgs { HasFail = true, Result = ex }; //throw; } TriggerReponseEnded(ar.AsyncState,resultEventArgs); }
private void TriggerTimeoutException(object state) { var resultEventArgs = new ResultEventArgs { HasFail = true, Result = "Tiempo de Espera excedido. Servicio fuera de linea" }; TriggerReponseEnded(state, resultEventArgs); }
private void TriggerReponseEnded(object sender, ResultEventArgs resultEventArgs) { if (ResponseEnded != null) { ResponseEnded(sender, resultEventArgs); } }
protected void FireProcessEnded(object sender, ResultEventArgs ev) { if (ProcessEnded != null) ProcessEnded(sender, ev); }