public async Task LoadMore()
        {
            if (this.IsRefreshing)
            {
                return;
            }

            this.IsRefreshing = true;

            IEnumerable<Article> articles = null;
            bool showFailMessage = false;
            try
            {
                articles = await this.echoJsClient.GetLatestNews(this.Articles.Count);
            }
            catch (HttpRequestException)
            {
                showFailMessage = true;
            }
            catch (UnsupportedMediaTypeException)
            {
                showFailMessage = true;
            }

            this.IsRefreshing = false;

            if (showFailMessage)
            {
                await Task.Delay(50);

                var showMessageBoxResult = new ShowMessageBoxResult(
                    "There was an error trying to get the top articles.",
                    AppResources.NetworkErrorMessageBoxCaption);

                await showMessageBoxResult.ExecuteAsync();
            }
            else
            {
                foreach (var article in articles)
                {
                    this.Articles.Add(article);
                }
            }
        }
        private async Task GetComments()
        {
            this.IsBusy = true;

            IEnumerable<Comment> comments = null;
            bool showFailMessage = false;
            try
            {
                comments = await this.echoJsClient.GetCommentsForArticle(this.ArticleId);
                comments = this.FlattenComments(comments);
            }
            catch (HttpRequestException)
            {
                showFailMessage = true;
            }
            catch (UnsupportedMediaTypeException)
            {
                showFailMessage = true;
            }

            this.IsBusy = false;

            if (showFailMessage)
            {
                await Task.Delay(50);

                var showMessageBoxResult = new ShowMessageBoxResult(
                    "There was an error trying to get the comments.",
                    AppResources.NetworkErrorMessageBoxCaption);

                await showMessageBoxResult.ExecuteAsync();
            }
            else
            {
                this.Comments.AddRange(comments);
            }

            this.NotifyOfPropertyChange(() => this.ShowNoCommentsMessage);
            this.NotifyOfPropertyChange(() => this.ShowComments);
        }
Exemple #3
0
        public async Task RefreshArticles()
        {
            if (this.IsRefreshing)
            {
                return;
            }

            this.ShowFailureMessage = false;
            this.Articles.Clear();
            this.IsRefreshing = true;

            IEnumerable<Article> articles = null;

            bool showFailMessage = false;
            try
            {
                articles = await this.echoJsClient.GetTopNews();
            }
            catch (HttpRequestException)
            {
                showFailMessage = true;
            }
            catch (UnsupportedMediaTypeException)
            {
                showFailMessage = true;
            }

            this.IsRefreshing = false;

            if (showFailMessage)
            {
                await Task.Delay(50);

                var showMessageBoxResult = new ShowMessageBoxResult(
                    "There was an error trying to get the top articles.",
                    AppResources.NetworkErrorMessageBoxCaption);

                await showMessageBoxResult.ExecuteAsync();
                this.ShowFailureMessage = true;
            }
            else
            {
                this.Articles.AddRange(articles.ToList());
            }
        }