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);
            }
        }
        // Cannot load photo stream
        private void OnPhotoStreamException(object sender, GetPhotoStreamExceptionEventArgs e)
        {
            Dispatcher.BeginInvoke(() =>
            {
                if (e.UserId != UserSource.ResourceId)
                    return;

                if(SystemTray.ProgressIndicator != null)
                    SystemTray.ProgressIndicator.IsVisible = false;

                StatusLabel.Text = AppResources.GenericPhotoLoadingErrorText;
                StatusLabel.Visibility = Visibility.Visible;
                PhotoStreamListView.Visibility = Visibility.Collapsed;
            });
        }
Exemplo n.º 3
0
        // Photo stream exception
        private void OnPhotoStreamException(object sender, GetPhotoStreamExceptionEventArgs e)
        {
            Dispatcher.BeginInvoke(() => {
                if (e.UserId != Cinderella.CinderellaCore.CurrentUser.ResourceId)
                    return;

                if (Cinderella.CinderellaCore.CurrentUser.Photos.Count == 0)
                {
                    StatusLabel.Text = "Cannot load your photo stream";
                    StatusLabel.Visibility = Visibility.Visible;
                    PhotoStreamListView.Visibility = Visibility.Collapsed;
                }
            });
        }