Esempio n. 1
0
                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;
                    }
                    }
                }