Exemple #1
0
        /// <summary>CalculateSleepIntervalMSec</summary>
        /// <returns>int</returns>
        public int CalculateSleepIntervalMSec()
        {
            //Thread.Sleep(int millisecondsTimeout) // 引数はミリ秒

            // 基底のミリ秒
            int temp = (int)(Math.Pow(2, this._current_retry_count) * 1000);

            // 1,000 ミリ秒以下の乱数を足し込む。
            // 再試行リクエストの後に毎回再計算
            temp += (int)(RandomValueGenerator.GenerateRandomUint() % 1000);

            this._current_retry_count++;

            if (this._maximum_retry_count <= this._current_retry_count)
            {
                // 最大リトライ回数超過 → ループ終了
                this._current_retry_interval_msec = -1;
            }
            else
            {
                if (this._maximum_backoff_msec <= temp)
                {
                    // 最大リトライ間隔超過 → 最大値を返す。
                    this._current_retry_interval_msec = this._maximum_backoff_msec;
                }
                else
                {
                    // 計算値を返す。
                    this._current_retry_interval_msec = temp;
                }
            }

            return(this._current_retry_interval_msec);
        }
        /// <summary>
        ///  Generates new progress rate for the task based on last progress rate in increasing order.
        /// </summary>
        /// <param name="lastProgressRate">Last progress rate</param>
        /// <returns>New progress rate</returns>
        private uint GenerateProgressRate(uint lastProgressRate)
        {
            // 乱数の30の剰余を足し込む。
            lastProgressRate += (RandomValueGenerator.GenerateRandomUint() % 30);

            if (SUCCESS_STATE <= lastProgressRate)
            {
                // 100%以上の場合、100%
                return(SUCCESS_STATE);
            }
            else
            {
                // 100%未満の場合、その値
                return(lastProgressRate);
            }
        }
 /// <summary>真偽の占い</summary>
 /// <param name="percentage">確率</param>
 /// <returns>真偽</returns>
 private bool Fortune(uint percentage)
 {
     return((RandomValueGenerator.GenerateRandomUint() % 100) < percentage);
 }