public bool CheckAndTrackThrottleConcurrentMessageSizeLimit(long smtpSessionId, int numOfRecipients)
        {
            ThrottleSession throttleSession = DeliveryThrottling.sessionMap.TryGetSession(smtpSessionId);
            bool            flag            = false;

            if (throttleSession != null && throttleSession.MessageSize >= 0L)
            {
                ulong num = Convert.ToUInt64(throttleSession.MessageSize);
                lock (DeliveryThrottling.syncMessageSize)
                {
                    if (DeliveryThrottling.totalConcurrentMessageSize < DeliveryThrottling.maxConcurrentMessageSizeLimit)
                    {
                        DeliveryThrottling.totalConcurrentMessageSize += num;
                        flag = true;
                    }
                    else
                    {
                        throttleSession.MessageSize = 0L;
                    }
                }
            }
            if (!flag)
            {
                DeliveryThrottling.Diag.TraceDebug <long, ulong>(0L, "Delivery for smtp session \"{0}\" is skipped as it exceeds max concurrent message size limit of {1}", smtpSessionId, DeliveryThrottling.maxConcurrentMessageSizeLimit);
                this.DeliveryThrottlingLogWorker.TrackConcurrentMessageSizeThrottle(true, DeliveryThrottling.maxConcurrentMessageSizeLimit, numOfRecipients);
            }
            else
            {
                this.DeliveryThrottlingLogWorker.TrackConcurrentMessageSizeThrottle(false, DeliveryThrottling.maxConcurrentMessageSizeLimit, numOfRecipients);
            }
            return(flag);
        }
        public void ResetSession(long smtpSessionId)
        {
            ThrottleSession throttleSession = DeliveryThrottling.sessionMap.TryGetSession(smtpSessionId);

            if (throttleSession != null)
            {
                if (throttleSession.Recipients != null)
                {
                    IList <RoutingAddress> list = throttleSession.Recipients.Keys.ToList <RoutingAddress>();
                    foreach (RoutingAddress routingAddress in list)
                    {
                        int num = throttleSession.Recipients[routingAddress];
                        for (int i = 0; i < num; i++)
                        {
                            this.DecrementRecipient(smtpSessionId, routingAddress);
                        }
                    }
                }
                lock (DeliveryThrottling.syncMessageSize)
                {
                    DeliveryThrottling.DecrementSessionMessageSize(throttleSession);
                }
                if (throttleSession.Mdb != null)
                {
                    DeliveryThrottling.deliveryDatabaseThreadMap.Decrement(throttleSession.Mdb.ToString());
                    throttleSession.Mdb = null;
                }
            }
        }
        public void ClearSession(long smtpSessionId)
        {
            ThrottleSession throttleSession = DeliveryThrottling.sessionMap.TryGetSession(smtpSessionId);

            if (throttleSession != null)
            {
                this.ResetSession(smtpSessionId);
                DeliveryThrottling.sessionMap.RemoveSession(smtpSessionId);
                DeliveryThrottling.deliveryServerThreadMap.Decrement("localhost");
            }
        }
        public void DecrementCurrentMessageSize(long smtpSessionId)
        {
            ThrottleSession throttleSession = DeliveryThrottling.sessionMap.TryGetSession(smtpSessionId);

            if (throttleSession != null)
            {
                lock (DeliveryThrottling.syncMessageSize)
                {
                    DeliveryThrottling.DecrementSessionMessageSize(throttleSession);
                }
            }
        }
        private static void DecrementSessionMessageSize(ThrottleSession session)
        {
            ulong num = Convert.ToUInt64(session.MessageSize);

            if (DeliveryThrottling.totalConcurrentMessageSize >= num)
            {
                DeliveryThrottling.totalConcurrentMessageSize -= num;
            }
            else
            {
                DeliveryThrottling.totalConcurrentMessageSize = 0UL;
            }
            session.MessageSize = 0L;
        }
        public void SetSessionMessageSize(long messageSize, long smtpSessionId)
        {
            ThrottleSession throttleSession = DeliveryThrottling.sessionMap.TryGetSession(smtpSessionId);

            if (throttleSession != null)
            {
                DeliveryThrottling.DecrementSessionMessageSize(throttleSession);
                if (messageSize < 0L)
                {
                    messageSize = 0L;
                }
                throttleSession.MessageSize = messageSize;
            }
        }