/// <summary>
        /// Return true if the number of calls to the API has not exceeded the maximum number of calls per minute in the last minute
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool VerifyAzureTableStorageThrottledCallCanProceed(string apiKey, string apiName)
        {
            // Now check if we have capacity in our allocation to make a call now
            bool canProceed = true;

            // Check per minute limit
            var dateFromLastMinute = DateTime.UtcNow.AddMinutes(-1);
            var dateToLastMinute   = DateTime.UtcNow.AddMinutes(1);
            var messages           = AzureTableStorageHelper.RetrieveLogMessagesFromTableStorage(apiKey, dateFromLastMinute, dateToLastMinute);

            if ((messages != null) && (messages.Count() >= this.maxNumberOfCallsPerMinute))
            {
                canProceed = false;
            }

            // Check Daily limit
            var dateFromLastDay = DateTime.UtcNow.AddDays(-1);
            var dateTimeNow     = DateTime.UtcNow.AddMinutes(1);
            var daySpanMessages = AzureTableStorageHelper.RetrieveLogMessagesFromTableStorage(apiKey, dateFromLastDay, dateTimeNow);

            if ((daySpanMessages != null) && (daySpanMessages.Count() >= this.maxNumberOfCallsPerDay))
            {
                canProceed = false;
            }

            return(canProceed);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return true if the number of calls to the API has not exceeded the maximum number of calls per minute in the last minute
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool VerifyAzureTableStorageThrottledCallCanProceed(string apiKey, string apiName)
        {
            // Now check if we have capacity in our allocation to make a call now
            var dateFromLastMinute = DateTime.UtcNow.AddMinutes(-1);
            var dateToLastMinute   = DateTime.UtcNow.AddMinutes(1);
            var messages           = AzureTableStorageHelper.RetrieveLogMessagesFromTableStorage(apiKey, dateFromLastMinute, dateToLastMinute);

            if (messages == null)
            {
                return(true);
            }
            if (messages.Count() >= this.maxNumberOfCallsPerMinute)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }