예제 #1
0
 private void OnTopicListException(object sender, GetGroupTopicsExceptionEventArgs e)
 {
     Dispatcher.BeginInvoke(() =>
     {
         if (e.GroupId == GroupSource.ResourceId)
             if (SystemTray.ProgressIndicator != null)
                 SystemTray.ProgressIndicator.IsVisible = false;
     });
 }
        public async void GetGroupTopicsAsync(string groupId, Dictionary<string, string> parameters = null)
        {
            if (groupTopicsFetchingQueue.Contains(groupId))
                return;

            groupTopicsFetchingQueue.Add(groupId);

            string timestamp = DateTimeUtils.GetTimestamp();
            string nonce = Guid.NewGuid().ToString().Replace("-", null);

            Dictionary<string, string> paramDict = new Dictionary<string, string>();
            paramDict["method"] = "flickr.groups.discuss.topics.getList";
            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";
            paramDict["group_id"] = groupId;

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

            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()))
            {
                groupTopicsFetchingQueue.Remove(groupId);

                GetGroupTopicsExceptionEventArgs exceptionEvt = null;

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

                    exceptionEvt = new GetGroupTopicsExceptionEventArgs();
                    exceptionEvt.GroupId = groupId;
                    GroupTopicsException(this, exceptionEvt);
                    return;
                }

                string jsonString = await reader.ReadToEndAsync().ConfigureAwait(false);
                if (!TryHandleResponseException(jsonString, () => { GetGroupTopicsAsync(groupId, parameters); }))
                {
                    exceptionEvt = new GetGroupTopicsExceptionEventArgs();
                    exceptionEvt.GroupId = groupId;
                    GroupTopicsException(this, exceptionEvt);
                    return;
                }

                GetGroupTopicsEventArgs args = new GetGroupTopicsEventArgs();
                args.GroupId = groupId;
                args.Response = jsonString;
                GroupTopicsReturned.DispatchEvent(this, args);
            }
        }
        // Topic list cannot be loaded
        private void OnTopicsException(object sender, GetGroupTopicsExceptionEventArgs e)
        {
            Dispatcher.BeginInvoke(() =>
            {
                if ( e.GroupId != GroupSource.ResourceId)
                    return;

                if (TopicCollection.Count == 0)
                {
                    StatusLabel.Text = "Cannot load topics";
                    StatusLabel.Visibility = Visibility.Visible;
                    TopicListView.Visibility = Visibility.Collapsed;
                }
            });
        }