示例#1
0
 public override void Do(ActionArgs e)
 {
     Begin(e);
     if (precheckToDo(e))
     {
         try {
             ActionFacebookGetAvatarArgs arg = e as ActionFacebookGetAvatarArgs;
             WebClient client = new WebClient();
             client.OpenReadCompleted += WebClientOpenReadCompleted;
             if (arg.IsGuest)
             {
                 client.OpenReadAsync(new Uri(FacebookClient.Instance.getUserAvatarUrl(arg.FacebookId), UriKind.Absolute));
             }
             else
             {
                 client.OpenReadAsync(new Uri(FacebookClient.Instance.getUserAvatarUrl(), UriKind.Absolute));
             }
             _waiting.Add(client, arg);
         } catch (Exception ex) {
             Cancel(e);
         }
     }
     else
     {
         Cancel(e);
     }
 }
示例#2
0
        static public void loadAvatar(Actions.DelegateBegin onBegin, Actions.DelegateDone onDone, Actions.DelegateCancel onCancel)
        {
            Actions.ActionFacebookGetAvatarArgs arg = new Actions.ActionFacebookGetAvatarArgs();

            Actions.ActionFacebookGetAvatar action_fbavar = new Actions.ActionFacebookGetAvatar();
            try {
                if (onBegin != null)
                {
                    action_fbavar.OnBegin += onBegin;
                }
                if (onDone != null)
                {
                    action_fbavar.OnDone += onDone;
                }
                if (onCancel != null)
                {
                    action_fbavar.OnCancel += onCancel;
                }
                action_fbavar.Do(arg);
            } catch (Exception ex) {
                if (onCancel != null)
                {
                    onCancel(null, arg);
                }
            }
        }
示例#3
0
 private void WebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
 {
     Deployment.Current.Dispatcher.BeginInvoke(() => {
         try {
             ActionFacebookGetAvatarArgs arg = _waiting[(WebClient)sender];
             var streamResourceInfo          = new StreamResourceInfo(e.Result, null);
             var bitmapImage = new BitmapImage();
             bitmapImage.SetSource(streamResourceInfo.Stream);
             arg.Avatar = bitmapImage;
             Done(arg);
         } catch (Exception ex) {
         }
     });
 }
示例#4
0
        public override bool precheckToDo(ActionArgs e)
        {
            ActionFacebookGetAvatarArgs arg = e as ActionFacebookGetAvatarArgs;

            if (arg != null)
            {
                if (arg.IsGuest)
                {
                    return(arg.FacebookId > 0);
                }
                else
                {
                    return(FacebookClient.Instance.IsUserLogedin());
                }
            }
            return(false);
        }