Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 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));
 }
Exemplo n.º 5
0
 private void Sync_ResponseEnded(object sender, ResultEventArgs e)
 {
     ResultEventArgs newEv = null;
     if (e.HasFail)
     {
         newEv = e;
     }
     else
     {
         translatedText = ProcessResponse(e);
     }
     autoResetEvent.Set();
 }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        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;
            }
        }
Exemplo n.º 8
0
 private void SearchProcessEndedHandler(object sender, ResultEventArgs e)
 {
     Deployment.Current.Dispatcher.BeginInvoke(() => UpdateSearchUI(e));
     provider.ProcessEnded -= SearchProcessEndedHandler;
 }
Exemplo n.º 9
0
 private void LoadProcessEndedHandler(object sender, ResultEventArgs e)
 {
     Deployment.Current.Dispatcher.BeginInvoke(() => { UpdateUI(e); });
     provider.ProcessEnded -= LoadProcessEndedHandler;
 }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
 private void TriggerTimeoutException(object state)
 {
     var resultEventArgs = new ResultEventArgs { HasFail = true, Result = "Tiempo de Espera excedido. Servicio fuera de linea" };
     TriggerReponseEnded(state, resultEventArgs);
 }
Exemplo n.º 13
0
 private void TriggerReponseEnded(object sender, ResultEventArgs resultEventArgs)
 {
     if (ResponseEnded != null)
     {
         ResponseEnded(sender, resultEventArgs);
     }
 }
Exemplo n.º 14
0
 protected void FireProcessEnded(object sender, ResultEventArgs ev)
 {
     if (ProcessEnded != null)
         ProcessEnded(sender, ev);
 }