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); } } }
async void loadAvatar(ActionFacebookGetAvatarArgs arg) { HttpClient client = new HttpClient(); string url = ""; if (arg.IsGuest) { url = FacebookClient.Instance.getUserAvatarUrl(arg.FacebookId); } else { url = FacebookClient.Instance.getUserAvatarUrl(); } #if DEBUG Test.sendLog("C# begin loadAvatar url:" + url); #endif byte[] data = await client.GetByteArrayAsync(url); var dispatcher = ActionHelper.getCurrentUIThread(); dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { try { CreateBitmap(arg, data); } catch (Exception ex) { #if DEBUG Test.sendLog("C# loadAvatar err:" + ex.ToString()); #endif } }); }
async void CreateBitmap(ActionFacebookGetAvatarArgs arg, byte[] data) { MemoryStream ms = new MemoryStream(data); IRandomAccessStream a1 = await ConvertToRandomAccessStream(ms); ////var bitmapImage = new WriteableBitmap(64,64); ////await bitmapImage.SetSourceAsync(a1); ////MemoryStream ms_out = new MemoryStream(); ////IRandomAccessStream a2 = await ConvertToRandomAccessStream(ms_out); ////BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId,a2); ////IBuffer buff = bitmapImage.PixelBuffer; ////DataReader reader = DataReader.FromBuffer(buff); ////byte[] pixels = new byte[buff.Length]; /*reader.ReadBytes(pixels); * encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, 64, 64, 96, 96, pixels); * await a2.ReadAsync(pixels.as(), (uint)myMemoryStream.Size, Windows.Storage.Streams.InputStreamOptions.None); * using (Stream s = await FileManager.GetFileStreamForWrite("tmpAvatar")) * { * byte[] out_data = new byte[a2.Size]; * * }*/ arg.Avatar = a1; Done(arg); }
public override void Do(ActionArgs e) { Begin(e); if (precheckToDo(e)) { try { ActionFacebookGetAvatarArgs arg = e as ActionFacebookGetAvatarArgs; loadAvatar(arg); } catch (Exception ex) { Cancel(e); } } else { Cancel(e); } }
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); }