public static void GetGroupSummary(int groupId, OnGroupSummaryResult onResultHandler) { System.IO.MemoryStream familyPhoto = null; // first, get the group info RockApi.Get_CustomEndPoint <GroupInfo>(RockApi.BaseUrl + EndPoint_GroupInfo + groupId, delegate(HttpStatusCode statusCode, string statusDescription, GroupInfo model) { if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true) { // get an image size appropriate for the device. uint imageRes = (uint)Rock.Mobile.Graphics.Util.UnitToPx(512); RockApi.Get_GetImage(model.FamilyPhotoGuid, imageRes, null, delegate(HttpStatusCode imageCode, string imageDescription, System.IO.MemoryStream imageStream) { // if the image didn't return successfully, just null it out. if (Rock.Mobile.Network.Util.StatusInSuccessRange(imageCode) == false) { imageStream = null; } else { // otherwise, copy it. We must copy it because the imageStream // will be going out of scope when we make the next Get_GetImage async call. familyPhoto = new System.IO.MemoryStream( ); imageStream.CopyTo(familyPhoto); familyPhoto.Position = 0; } // now try for the group photo RockApi.Get_GetImage(model.GroupPhotoGuid, imageRes, null, delegate(HttpStatusCode groupImageCode, string groupImageDesc, System.IO.MemoryStream groupImageStream) { // if the image didn't return successfully, just null it out. if (Rock.Mobile.Network.Util.StatusInSuccessRange(groupImageCode) == false) { groupImageStream = null; } // JHM Note: Enable this to debug the image size issue that's on certain devices. //groupImageStream.CopyTo( leaderPhoto ); //groupImageStream.Position = 0; //leaderPhoto.Position = 0; // return ok whether they have a images or not (since they're not required) onResultHandler(model, familyPhoto, groupImageStream); }); }); } // GROUP INFO fail else { // return ok whether they have an image or not (since it's not required) onResultHandler(null, null, null); } }); }
public void TryDownloadProfilePicture(uint dimensionSize, HttpRequest.RequestResult profilePictureResult) { switch (AccountType) { case BoundAccountType.Facebook: { // grab the actual image string facebookID = UserID.Substring(UserID.IndexOf("_") + 1); //chop off the "facebook_" prefix we add. string profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", facebookID, "large", AccessToken); RestRequest request = new RestRequest(Method.GET); // get the raw response HttpRequest webRequest = new HttpRequest(); webRequest.ExecuteAsync(profilePictureUrl, request, delegate(System.Net.HttpStatusCode statusCode, string statusDescription, byte[] model) { // it worked out ok! if (Util.StatusInSuccessRange(statusCode) == true) { MemoryStream imageStream = new MemoryStream(model); SaveProfilePicture(imageStream); imageStream.Dispose( ); } // notify the caller if (profilePictureResult != null) { profilePictureResult(statusCode, statusDescription); } }); break; } case BoundAccountType.Rock: { if (Person.PhotoId != null) { RockApi.Get_GetImage(Person.PhotoId.Value, dimensionSize, dimensionSize, delegate(System.Net.HttpStatusCode statusCode, string statusDescription, MemoryStream imageStream) { if (Util.StatusInSuccessRange(statusCode) == true) { // if successful, update the file on disk. SaveProfilePicture(imageStream); } // notify the caller if (profilePictureResult != null) { profilePictureResult(statusCode, statusDescription); } }); } // they might not have a photo ID, and that's ok. In that case, just callback with finished. else { // notify the caller if (profilePictureResult != null) { profilePictureResult(System.Net.HttpStatusCode.NotFound, string.Empty); } } break; } } }