示例#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);
            }
        }
示例#2
0
        /// <summary>
        /// Records the dictionary search, then searches for a given word asynchronously in the Stands4 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> > SearchForWordStands4Async(string word)
        {
            Tools.Logger.Log("SearchForWordStands4Async", "Start search");
            if (string.IsNullOrWhiteSpace(word))
            {
                Tools.Logger.Log("SearchForWordStands4Async", "Null or whitespace. Return an empty list");
                return(new ReadOnlyObservableCollection <IWord>(new ObservableCollection <IWord>()));
            }

            Stands4Dictionary   stands4Endpoint = new Stands4Dictionary(App.OAuth2Account, word);
            IList <Stands4Word> stands4Result   = await Task.Run(async() => await stands4Endpoint.CallEndpointAsStands4Word());

            Tools.Logger.Log("SearchForWordStands4Async", "Data received");

            return(new ReadOnlyObservableCollection <IWord>(new ObservableCollection <IWord>(stands4Result)));
        }
示例#3
0
        private async Task _InitializeStands4Stack()
        {
            try
            {
                this.Stands4Stack.Children.Add(new ActivityIndicator());
                Stands4Dictionary   s4d    = new Stands4Dictionary(App.OAuth2Account, this.searchedWord);
                IList <Stands4Word> result = await s4d.CallEndpointAsStands4Word().ConfigureAwait(false);

                foreach (Stands4Word word in result)
                {
                    this.Stands4Stack.Children.Add(new Stands4SearchListItemView(word));
                }
            }
            catch (UnsuccessfulApiCallException ex)
            {
                Tools.Logger.Log(this.GetType().ToString(), "_InitializeStands4Stack method", ex);
            }
            catch (Exception ex)
            {
                Tools.Logger.Log(this.GetType().ToString(), "_InitializeStands4Stack method", ex);
            }
        }