// Photo stream retrieved for a user
        private void PhotoStreamReturned(object sender, GetPhotoStreamEventArgs e)
        {
            // Find the user
            if (!UserCache.ContainsKey(e.UserId))
                return;

            User user = UserCache[e.UserId];

            JObject rawJson = JObject.Parse(e.Response);
            JObject rootJson = (JObject)rawJson["photos"];
            user.PhotoCount = int.Parse(rootJson["total"].ToString());
            int page = int.Parse(rootJson["page"].ToString());
            int numPages = int.Parse(rootJson["pages"].ToString());
            int perPage = int.Parse(rootJson["perpage"].ToString());

            List<Photo> newPhotos = new List<Photo>();
            foreach (var entry in rootJson["photo"])
            {
                JObject json = (JObject)entry;
                Photo photo = PhotoFactory.PhotoWithJObject(json);

                if (!user.Photos.Contains(photo))
                {
                    user.Photos.Add(photo);
                    newPhotos.Add(photo);
                }
            }

            // Dispatch event
            PhotoStreamUpdatedEventArgs evt = new PhotoStreamUpdatedEventArgs();
            evt.Page = page;
            evt.PageCount = numPages;
            evt.PerPage = perPage;
            evt.NewPhotos = newPhotos;
            evt.UserId = e.UserId;
            PhotoStreamUpdated.DispatchEvent(this, evt);
        }
        public async void GetPhotoStreamAsync(string userId, Dictionary<string, string> parameters = null)
        {
            string timestamp = DateTimeUtils.GetTimestamp();
            string nonce = Guid.NewGuid().ToString().Replace("-", null);

            Dictionary<string, string> paramDict = new Dictionary<string, string>();
            paramDict["method"] = "flickr.people.getPhotos";
            paramDict["format"] = "json";
            paramDict["nojsoncallback"] = "1";
            paramDict["oauth_consumer_key"] = consumerKey;
            paramDict["oauth_nonce"] = nonce;
            paramDict["oauth_signature_method"] = "HMAC-SHA1";
            paramDict["oauth_timestamp"] = timestamp;
            paramDict["oauth_token"] = AccessToken;
            paramDict["oauth_version"] = "1.0";

            if (parameters != null)
            {
                foreach (var entry in parameters)
                {
                    paramDict[entry.Key] = entry.Value;
                }
            }

            if (userId == Cinderella.Cinderella.CinderellaCore.CurrentUser.ResourceId)
                paramDict["user_id"] = "me";
            else
                paramDict["user_id"] = UrlHelper.Encode(userId);

            paramDict["extras"] = UrlHelper.Encode(commonExtraParameters);

            User user = null;
            if (Cinderella.Cinderella.CinderellaCore.UserCache.ContainsKey(userId))
            {
                user = Cinderella.Cinderella.CinderellaCore.UserCache[userId];
                user.IsLoadingPhotoStream = true;
            }

            string paramString = GenerateParamString(paramDict);
            string signature = GenerateSignature("GET", AccessTokenSecret, "https://api.flickr.com/services/rest", paramString);
            string requestUrl = "https://api.flickr.com/services/rest?" + paramString + "&oauth_signature=" + signature;
            HttpWebResponse response = await DispatchRequest("GET", requestUrl, null).ConfigureAwait(false);
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                GetPhotoStreamExceptionEventArgs exceptionEvt = null;

                if (user != null)
                {
                    user.IsLoadingPhotoStream = false;
                }

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    HandleHTTPException(response);

                    exceptionEvt = new GetPhotoStreamExceptionEventArgs();
                    exceptionEvt.UserId = userId;
                    PhotoStreamException(this, exceptionEvt);

                    return;
                }

                string jsonString = await reader.ReadToEndAsync().ConfigureAwait(false);
                if (!TryHandleResponseException(jsonString, () => { GetPhotoStreamAsync(userId, parameters); }))
                {
                    exceptionEvt = new GetPhotoStreamExceptionEventArgs();
                    exceptionEvt.UserId = userId;
                    PhotoStreamException(this, exceptionEvt);

                    return;
                }

                GetPhotoStreamEventArgs args = new GetPhotoStreamEventArgs();
                args.UserId = userId;
                args.Response = jsonString;
                PhotoStreamReturned.DispatchEvent(this, args);
            }
        }