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

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

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

            Activity = async;
        }
Example #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;
        }
Example #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;
        }
Example #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;
        }
Example #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);
            }
        }
Example #8
0
 private void AsyncPrint()
 {
     Async async = new Async(PrintAndBind);
     async.BeginInvoke(null, null);
 }
 private void OnCancel(Async<int> async, object taskState)
 {
 }