コード例 #1
0
ファイル: Twitter.cs プロジェクト: noqisofon/OpenTween
        public bool GetInfoApi(ApiInfo info)
        {
            if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) return true;

            if (MyCommon._endingFlag) return true;

            HttpStatusCode res = HttpStatusCode.BadRequest;
            var content = string.Empty;
            try
            {
                res = twCon.RateLimitStatus(ref content);
            }
            catch(Exception)
            {
                MyCommon.TwitterApiInfo.Initialize();
                return false;
            }

            if (res != HttpStatusCode.OK) return false;

            try
            {
                var limit = MyCommon.CreateDataFromJson<TwitterDataModel.RateLimitStatus>(content);
                var arg = new ApiInformationChangedEventArgs();
                arg.ApiInfo.MaxCount = limit.HourlyLimit;
                arg.ApiInfo.RemainCount = limit.RemainingHits;
                arg.ApiInfo.ResetTime = MyCommon.DateTimeParse(limit.RestTime);
                arg.ApiInfo.ResetTimeInSeconds = limit.RestTimeInSeconds;
                if (info != null)
                {
                    arg.ApiInfo.UsingCount = info.UsingCount;

                    info.MaxCount = arg.ApiInfo.MaxCount;
                    info.RemainCount = arg.ApiInfo.RemainCount;
                    info.ResetTime = arg.ApiInfo.ResetTime;
                    info.ResetTimeInSeconds = arg.ApiInfo.ResetTimeInSeconds;
                }

                if (ApiInformationChanged != null)
                {
                    ApiInformationChanged(this, arg);
                }
                MyCommon.TwitterApiInfo.WriteBackEventArgs(arg);
                return true;
            }
            catch(Exception ex)
            {
                MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content);
                MyCommon.TwitterApiInfo.Initialize();
                return false;
            }
        }
コード例 #2
0
ファイル: Tween.cs プロジェクト: lupeeloveee/OpenTween
        private void ApiInfoMenuItem_Click(object sender, EventArgs e)
        {
            ApiInfo info = new ApiInfo();
            StringBuilder tmp = new StringBuilder();
            GetApiInfoArgs args = new GetApiInfoArgs() {tw = tw, info = info};

            using (FormInfo dlg = new FormInfo(this, Properties.Resources.ApiInfo6, GetApiInfo_Dowork, null, args))
            {
                dlg.ShowDialog();
                if ((bool)dlg.Result)
                {
                    tmp.AppendLine(Properties.Resources.ApiInfo1 + args.info.MaxCount.ToString());
                    tmp.AppendLine(Properties.Resources.ApiInfo2 + args.info.RemainCount.ToString());
                    tmp.AppendLine(Properties.Resources.ApiInfo3 + args.info.ResetTime.ToString());
                    tmp.AppendLine(Properties.Resources.ApiInfo7 + (tw.UserStreamEnabled ? Properties.Resources.Enable : Properties.Resources.Disable).ToString());

                    tmp.AppendLine();
                    tmp.AppendLine(Properties.Resources.ApiInfo8 + args.info.AccessLevel.ToString());
                    SetStatusLabelUrl();

                    tmp.AppendLine();
                    tmp.AppendLine(Properties.Resources.ApiInfo9 + (args.info.MediaMaxCount < 0 ? Properties.Resources.ApiInfo91 : args.info.MediaMaxCount.ToString()));
                    tmp.AppendLine(Properties.Resources.ApiInfo10 + (args.info.MediaRemainCount < 0 ? Properties.Resources.ApiInfo91 : args.info.MediaRemainCount.ToString()));
                    tmp.AppendLine(Properties.Resources.ApiInfo11 + (args.info.MediaResetTime == new DateTime() ? Properties.Resources.ApiInfo91 : args.info.MediaResetTime.ToString()));
                }
                else
                {
                    tmp.Append(Properties.Resources.ApiInfo5);
                }
            }

            MessageBox.Show(tmp.ToString(), Properties.Resources.ApiInfo4, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }