BB.Caching.Redis.Analytics.BitwiseAnalytics.GetMinKeysForRangeAsync C# (CSharp) Method

GetMinKeysForRangeAsync() public static method

Gets the fewest number of keys required to cover the date range supplied.
public static GetMinKeysForRangeAsync ( IDatabase database, string category, string action, System.DateTime start, System.DateTime end, TimeInterval timeInterval = TimeInterval.FifteenMinutes ) : Task
database IDatabase /// The database where the query will be performed. This is passed so that we can reuse the same database to /// perform multiple bitwise operations. Doing this with the same connection will guarantee that performance /// is good. ///
category string /// Typically the object that was interacted with (e.g. button) ///
action string /// The type of interaction (e.g. click) ///
start System.DateTime /// The starting DateTime, inclusive. ///
end System.DateTime /// The ending DateTime, exclusive. ///
timeInterval TimeInterval /// The accuracy at which we want the data. For example, setting this to TimeInterval.OneDay means there won't /// be any keys at the fifteen minute or one hour levels, so if the DateTime is for the /// middle of a day, it'll include the entire day. ///
return Task
        public static async Task<RedisKey[]> GetMinKeysForRangeAsync(
            IDatabase database,
            string category,
            string action,
            DateTime start,
            DateTime end,
            TimeInterval timeInterval = TimeInterval.FifteenMinutes)
        {
            Tuple<TimeInterval, string, DateTime>[] requiredKeys = DateTimeUtil.MinKeysForRange(start, end, timeInterval);
            Task<RedisKey>[] keys = new Task<RedisKey>[requiredKeys.Length];
            int keyIndex = 0;

            foreach (var tup in requiredKeys)
            {
                switch (tup.Item1)
                {
                    case TimeInterval.FifteenMinutes:
                    {
                        keys[keyIndex] = GetFifteenMinutesAsync(category, action, tup.Item3);
                        break;
                    }

                    case TimeInterval.OneHour:
                    {
                        keys[keyIndex] = GetHourAsync(database, category, action, tup.Item3);
                        break;
                    }

                    case TimeInterval.OneDay:
                    {
                        keys[keyIndex] = GetDayAsync(database, category, action, tup.Item3);
                        break;
                    }

                    case TimeInterval.Week:
                    {
                        keys[keyIndex] = GetWeekAsync(database, category, action, tup.Item3);
                        break;
                    }

                    case TimeInterval.OneMonth:
                    {
                        keys[keyIndex] = GetMonthAsync(database, category, action, tup.Item3);
                        break;
                    }

                    case TimeInterval.Quarter:
                    {
                        keys[keyIndex] = GetQuarterAsync(database, category, action, tup.Item3);
                        break;
                    }
                }

                keyIndex += 1;
            }

            return await Task.WhenAll(keys);
        }