Пример #1
0
        void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null && !e.Cancelled)
            {
                FlurryWP7SDK.Api.LogError("Error in client_DownloadStringCompleted when fetching comments for story", e.Error);
            }
            else if (!e.Cancelled)
            {
                // Parse the comments on a background thread, and then update the UI
                BackgroundWorker updateCommentsWorker = new BackgroundWorker();
                updateCommentsWorker.DoWork += delegate(object s, DoWorkEventArgs args)
                {
                    args.Result = HackerNewsParser.ParseCommentsPage(e.Result);
                };

                updateCommentsWorker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
                {
                    List <Comment> comments = (List <Comment>)args.Result;

                    foreach (Comment c in comments)
                    {
                        CommentListBox.Items.Add(CommentUtils.UIElementFromComment(c));
                    }

                    loadingDialog.Hide();
                };

                updateCommentsWorker.RunWorkerAsync();
            }
        }
Пример #2
0
        void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            LoadingProgressBar.IsVisible = false;

            if (e.Error != null && !e.Cancelled)
            {
                FlurryWP7SDK.Api.LogError("Error in client_DownloadStringCompleted when fetching news on Main Page", e.Error);

                // Display the connection error text in the SystemTray for 2s
                ShowConnectionError(true);
                PerformActionWithDelay(() => ShowConnectionError(false), 2000);
            }
            else if (!e.Cancelled)
            {
                // Parse the news results on a background thread, and then update the UI
                BackgroundWorker updateNewsWorker = new BackgroundWorker();
                updateNewsWorker.DoWork += delegate(object s, DoWorkEventArgs args)
                {
                    args.Result = HackerNewsParser.ParseNewsPage(e.Result);
                };

                updateNewsWorker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
                {
                    NewsPage newsPage = (NewsPage)args.Result;

                    int       pivotIndx        = (int)e.UserState;
                    PivotItem currentPivotItem = (PivotItem)MainPivot.Items[pivotIndx];
                    ListBox   currentListBox   = (ListBox)currentPivotItem.Content;

                    lastRefreshed[pivotIndx]     = DateTime.Now;
                    currentPivotItem.DataContext = newsPage;

                    currentListBox.ItemsSource = null;
                    currentListBox.ItemsSource = newsPage.Items;

                    currentListBox.UpdateLayout();
                    currentListBox.ScrollIntoView(currentListBox.Items[0]);

                    UpdateAppBarLabels();
                };

                updateNewsWorker.RunWorkerAsync();
            }
        }