/// <summary> /// Gets twitter User ID and caches it to avoid exceeding limits /// </summary> /// <param name="twittAppInfo">Application to use to interact with Twitter</param> /// <param name="twittAccountInfo">Channel to be used to interact with Twitter</param> /// <returns>null on failure, correct Twitter UserId otherwise</returns> private static string GetTwitterUserId(TwitterApplicationInfo twittAppInfo, TwitterAccountInfo twittAccountInfo) { string key = String.Join(":", twittAppInfo.TwitterApplicationConsumerKey, twittAppInfo.TwitterApplicationConsumerSecret, twittAccountInfo.TwitterAccountAccessToken, twittAccountInfo.TwitterAccountAccessTokenSecret); string userId = null; if (!mTwitterIDs.TryGetValue(key, out userId)) { userId = TwitterHelper.GetTwitterUserId(twittAppInfo.TwitterApplicationConsumerKey, twittAppInfo.TwitterApplicationConsumerSecret, twittAccountInfo.TwitterAccountAccessToken, twittAccountInfo.TwitterAccountAccessTokenSecret); mTwitterIDs.Add(key, userId); } return(userId); }
private void Control_OnBeforeSave(object sender, EventArgs e) { TwitterAccountInfo account = Control.EditedObject as TwitterAccountInfo; if (account != null) { TwitterApplicationInfo application = TwitterApplicationInfoProvider.GetTwitterApplicationInfo(account.TwitterAccountTwitterApplicationID); try { account.TwitterAccountUserID = TwitterHelper.GetTwitterUserId(application.TwitterApplicationConsumerKey, application.TwitterApplicationConsumerSecret, account.TwitterAccountAccessToken, account.TwitterAccountAccessTokenSecret); string errorMessage = null; Validate <TwitterAccountInfo>("TwitterAccountUserID", account.TwitterAccountUserID, "sm.twitter.account.msg.useridexists", ref errorMessage); if (!String.IsNullOrEmpty(errorMessage)) { CancelPendingSave(errorMessage); } } catch { string errorMessage = ResHelper.GetString("sm.twitter.account.msg.getuseridfail"); CancelPendingSave(errorMessage); } } }