Ejemplo n.º 1
0
        /// <summary>
        /// Event handler for search button
        /// </summary>
        /// <param name="sender">Search bar sender object</param>
        /// <param name="e">EventArgs param</param>
        private async void SearchBar_SearchButtonPressed(object sender, EventArgs e)
        {
            string word = ((SearchBar)sender).Text;

            this.MainStack.Children.Clear();
            try
            {
                this.SwitchActivityIndicator(true);
                Stands4Dictionary   s4d       = new Stands4Dictionary(App.OAuth2Account, word);
                IList <Stands4Word> s4wResult = await s4d.CallEndpointAsStands4Word().ConfigureAwait(false);

                foreach (Stands4Word w in s4wResult)
                {
                    this.MainStack.Children.Add(new Stands4SearchListItemView(w));
                }

                this.SwitchActivityIndicator(false);
            }
            catch (UnsuccessfulApiCallException ex)
            {
                Tools.Logger.Log(this.GetType().ToString(), "Stands4 Exception", ex);
                this.SwitchActivityIndicator(false);
            }
            catch (Exception ex)
            {
                Tools.Logger.Log(this.GetType().ToString(), "Stands4 Exception", ex);
                this.SwitchActivityIndicator(false);
            }

            try
            {
                this.SwitchActivityIndicator(true);
                CollinsEnglishDictionary     dictionaryAPI = new CollinsEnglishDictionary(App.OAuth2Account, word);
                CollinsJsonEnglishDictionary result        = await dictionaryAPI.CallEndpointAsObjectAsync().ConfigureAwait(false);

                // Create a panel, but avoid the remote call
                foreach (CollinsJsonEnglishDictionarySingleResult entry in result.Results)
                {
                    this.MainStack.Children.Add(new CollinsEntriesWrapper(entry));
                }

                this.SwitchActivityIndicator(false);
            }
            catch (UnsuccessfulApiCallException ex)
            {
                Tools.Logger.Log(this.GetType().ToString(), "Collins Exception", ex);
                this.SwitchActivityIndicator(false);
            }
            catch (Exception ex)
            {
                Tools.Logger.Log(this.GetType().ToString(), "Collins Exception", ex);
                this.SwitchActivityIndicator(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Searches for a given word asynchronously in the Collins dictionary.
        /// </summary>
        /// <param name="word">The word to search for.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        private static async Task <ReadOnlyObservableCollection <IWord> > SearchForWordCollinsAsync(string word)
        {
            Tools.Logger.Log("SearchForWordCollinsAsync", "Start search");
            if (string.IsNullOrWhiteSpace(word))
            {
                Tools.Logger.Log("SearchForWordCollinsAsync", "Null or whitespace. Return an empty list");
                return(new ReadOnlyObservableCollection <IWord>(new ObservableCollection <IWord>()));
            }

            CollinsEnglishDictionary collinsEndpoint = new CollinsEnglishDictionary(App.OAuth2Account, word);
            IList <CollinsWord>      collinsResult   = await Task.Run(async() => await collinsEndpoint.CallEndpointAsCollinsWord());

            Tools.Logger.Log("SearchForWordCollinsAsync", "Data received");
            return(new ReadOnlyObservableCollection <IWord>(new ObservableCollection <IWord>(collinsResult)));
        }