コード例 #1
0
        // Token: 0x06000003 RID: 3 RVA: 0x0000215C File Offset: 0x0000035C
        public bool ObtainTokens <T>(ObtainTokensRequest <T> request, DateTime currentTime)
        {
            int requestedTokenCount = request.RequestedTokenCount;
            int totalTokenCount     = request.TotalTokenCount;

            if (totalTokenCount < 1)
            {
                throw new ArgumentOutOfRangeException("totalTokenCount", totalTokenCount, "totalTokenCount should be greater than 0");
            }
            if (requestedTokenCount < 1 || requestedTokenCount > totalTokenCount)
            {
                string message = string.Format(CultureInfo.InvariantCulture, "requestedCount should be greater than 0 and less or equal to totalCount of {0}", new object[]
                {
                    totalTokenCount
                });
                throw new ArgumentOutOfRangeException("requestedCount", requestedTokenCount, message);
            }
            this.totalCount = totalTokenCount;
            if (this.IsExpired(currentTime))
            {
                ThrottlingServiceLog.LogTokenExpiry(request.MailboxGuid, this);
                this.timestamp   = currentTime;
                this.issuedCount = 0;
            }
            bool result = false;

            if (this.issuedCount + requestedTokenCount <= this.totalCount)
            {
                this.issuedCount += requestedTokenCount;
                result            = true;
            }
            ThrottlingServiceLog.LogObtainTokens <T>(request, this, result);
            return(result);
        }
コード例 #2
0
 // Token: 0x0600003F RID: 63 RVA: 0x00003410 File Offset: 0x00001610
 private static void PopulateRequestParmeters <T>(LogRowFormatter row, ObtainTokensRequest <T> request)
 {
     row[2] = request.ClientHostName;
     row[4] = request.ClientProcessName;
     row[3] = request.ClientType;
     row[5] = request.MailboxGuid;
     row[6] = request.RequestedAction;
     row[8] = request.RequestedTokenCount;
     row[7] = request.TotalTokenCount;
 }
コード例 #3
0
        // Token: 0x0600003D RID: 61 RVA: 0x0000333C File Offset: 0x0000153C
        internal static void LogThrottlingBypassed <T>(ObtainTokensRequest <T> request)
        {
            if (!ThrottlingServiceLog.enabled)
            {
                return;
            }
            LogRowFormatter logRowFormatter = new LogRowFormatter(ThrottlingServiceLog.throttlingServiceLogSchema);

            ThrottlingServiceLog.PopulateRequestParmeters <T>(logRowFormatter, request);
            logRowFormatter[10] = "Throttling is bypassed.";
            logRowFormatter[1]  = ThrottlingServiceLog.ThrottlingEventId.BYPASS;
            ThrottlingServiceLog.log.Append(logRowFormatter, 0);
        }
コード例 #4
0
        // Token: 0x06000029 RID: 41 RVA: 0x00002B18 File Offset: 0x00000D18
        private bool ObtainTokens(Guid mailboxGuid, RequestedAction requestedAction, int requestedTokenCount, int totalTokenCount, string clientHostName, string clientProcessName, string clientType)
        {
            ThrottlingService.Tracer.TraceDebug(0L, "ObtainTokens() request: mailboxGuid=<{0}>; requestedAction={1}; requestedTokenCount={2}; totalTokenCount={3}", new object[]
            {
                mailboxGuid,
                requestedAction,
                requestedTokenCount,
                totalTokenCount
            });
            ObtainTokensRequest <Guid> request = new ObtainTokensRequest <Guid>(mailboxGuid, requestedTokenCount, totalTokenCount, requestedAction, clientHostName, clientProcessName, clientType);
            bool flag;

            if (totalTokenCount < 1 || requestedTokenCount < 1 || requestedTokenCount > totalTokenCount)
            {
                ThrottlingService.Tracer.TraceError(0L, "ObtainSubmissionTokens(): invalid arguments supplied");
                flag = false;
            }
            else if (requestedAction == RequestedAction.UserMailSubmission)
            {
                flag = this.userSubmissionTokens.ObtainTokens(request);
            }
            else if (requestedAction == RequestedAction.MailboxRuleMailSubmission)
            {
                flag = this.mailboxRuleSubmissionTokens.ObtainTokens(request);
            }
            else
            {
                ThrottlingServiceLog.LogThrottlingBypassed <Guid>(request);
                ThrottlingService.Tracer.TraceDebug <RequestedAction>(0L, "Action {1} is not supported, therefor is allowed by default", requestedAction);
                flag = true;
            }
            if (flag)
            {
                ThrottlingService.Tracer.TraceDebug(0L, "ObtainTokens(): request allowed");
            }
            else
            {
                ThrottlingService.EventLogger.LogEvent(ThrottlingServiceEventLogConstants.Tuple_MailboxThrottled, mailboxGuid.ToString(), new object[]
                {
                    mailboxGuid,
                    clientHostName,
                    requestedAction,
                    requestedTokenCount,
                    totalTokenCount,
                    clientType,
                    clientProcessName
                });
                ThrottlingService.Tracer.TraceDebug(0L, "ObtainTokens(): request denied");
            }
            return(flag);
        }
コード例 #5
0
        // Token: 0x0600003A RID: 58 RVA: 0x00003260 File Offset: 0x00001460
        public static void LogObtainTokens <T>(ObtainTokensRequest <T> request, object tokenInfo, bool result)
        {
            if (!ThrottlingServiceLog.enabled)
            {
                return;
            }
            LogRowFormatter logRowFormatter = new LogRowFormatter(ThrottlingServiceLog.throttlingServiceLogSchema);

            ThrottlingServiceLog.PopulateRequestParmeters <T>(logRowFormatter, request);
            logRowFormatter[9]  = result;
            logRowFormatter[10] = tokenInfo;
            if (result)
            {
                logRowFormatter[1] = ThrottlingServiceLog.ThrottlingEventId.APPROVE;
            }
            else
            {
                logRowFormatter[1] = ThrottlingServiceLog.ThrottlingEventId.DENY;
            }
            ThrottlingServiceLog.log.Append(logRowFormatter, 0);
        }
コード例 #6
0
        // Token: 0x06000043 RID: 67 RVA: 0x000034B8 File Offset: 0x000016B8
        public bool ObtainTokens(ObtainTokensRequest <KeyT> request)
        {
            if (this.cleanupTimer == null)
            {
                throw new InvalidOperationException("TokenBucketMap instance is not started.");
            }
            DateTime utcNow = DateTime.UtcNow;
            bool     result;

            lock (this.data)
            {
                DailyTokenBucket dailyTokenBucket;
                if (!this.data.TryGetValue(request.MailboxGuid, out dailyTokenBucket))
                {
                    dailyTokenBucket = new DailyTokenBucket();
                    this.data.Add(request.MailboxGuid, dailyTokenBucket);
                }
                result = dailyTokenBucket.ObtainTokens <KeyT>(request, utcNow);
            }
            return(result);
        }