Represents an asynchronous result and the associated task that produces the result.
Inheritance: System.ComponentModel.Model
Exemplo n.º 1
0
        public Async<ActionResult> List()
        {
            Async<ActionResult> task = new Async<ActionResult>();
            _newsService.GetNews(/* limitToLastDay */ true, OnNewsItemsAvailable, task);

            return task;
        }
Exemplo n.º 2
0
        public void StartCancelable()
        {
            Async async = new Async<int>(OnCancel, null);
            async.Message = "Test Cancelable Async Activity";

            Activity = async;
        }
Exemplo n.º 3
0
        public void Start()
        {
            Async async = new Async<int>();
            async.Message = "Test Async Activity";

            Activity = async;
        }
Exemplo n.º 4
0
        public Async<ActionResult> Search(string query)
        {
            if (String.IsNullOrEmpty(query)) {
                throw new ArgumentNullException("query");
            }

            Async<ActionResult> task = new Async<ActionResult>();
            _newsService.Search(query, OnNewsItemsAvailable, task);

            return task;
        }
Exemplo n.º 5
0
        public Async<Profile> GetProfile(string userName)
        {
            Async<Profile> asyncProfile = new Async<Profile>();

            _twitterService.GetProfile(userName, delegate(Profile profile) {
                if (profile == null) {
                    asyncProfile.Complete(new Exception("The profile for '" + userName + "' could not be loaded."));
                }
                else {
                    asyncProfile.Complete(profile);
                }
            });

            return asyncProfile;
        }
Exemplo n.º 6
0
        public Async<IEnumerable> GetTweets(string userName)
        {
            Async<IEnumerable> asyncTweets = new Async<IEnumerable>();

            _twitterService.GetTweets(userName, delegate(IEnumerable<Tweet> tweets) {
                if (tweets == null) {
                    asyncTweets.Complete(new Exception("Favorites for '" + userName + "' could not be loaded."));
                }
                else {
                    IEnumerable<TweetGroup> groupedTweets =
                        tweets.AsQueryable().
                        OrderByDescending(t => t.Date).
                        GroupByContiguous<Tweet, int, TweetGroup>(
                            t => TweetGroup.GetDaysGroupValue(t),
                            EqualityComparer<int>.Default,
                            (t, d) => new TweetGroup(t, d));

                    asyncTweets.Complete(groupedTweets);
                }
            });

            return asyncTweets;
        }
Exemplo n.º 7
0
        private void UpdateVisualState(Async asyncActivity)
        {
            if ((asyncActivity != null) && (asyncActivity.IsCompleted == false)) {
                string progressState = "Untracked";
                if (_progressBarVisibility == Visibility.Visible) {
                    progressState = "Tracking";
                }
                VisualStateManager.GoToState(this, progressState, /* useTransitions */ true);

                string statusState = "Empty";
                if ((_statusLabelVisibility == Visibility.Visible) &&
                    (String.IsNullOrEmpty(asyncActivity.Message) == false)) {
                    statusState = "Message";
                }
                VisualStateManager.GoToState(this, statusState, /* useTransitions */ true);

                string cancelState = "NonCancelable";
                if ((_cancelButtonVisibility == Visibility.Visible) &&
                    asyncActivity.CanCancel) {
                    cancelState = "Cancelable";
                }
                VisualStateManager.GoToState(this, cancelState, /* useTransitions */ true);
            }
            else {
                VisualStateManager.GoToState(this, "Untracked", /* useTransitions */ true);
                VisualStateManager.GoToState(this, "Empty", /* useTransitions */ true);
                VisualStateManager.GoToState(this, "NonCancelable", /* useTransitions */ true);
            }
        }
Exemplo n.º 8
0
 private void AsyncPrint()
 {
     Async async = new Async(PrintAndBind);
     async.BeginInvoke(null, null);
 }
Exemplo n.º 9
0
 private void OnCancel(Async<int> async, object taskState)
 {
 }