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); } }
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); } } }
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) { } }); }
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); }