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

GetMonthAsync() public static method

Gets the key for the month covered by the DateTime supplied, creating the data at the key if necessary.
public static GetMonthAsync ( IDatabase database, string category, string action, System.DateTime dateTime ) : 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) ///
dateTime System.DateTime /// The DateTime. ///
return Task
        public static async Task<RedisKey> GetMonthAsync(
            IDatabase database, string category, string action, DateTime dateTime)
        {
            // get the key
            string month = BitwiseAnalytics.DateTimeUtil.OneMonth(dateTime);
            RedisKey key = EventKey(category, action, month);

            // return it if there's already data for this month
            bool monthExists = await BitwiseAnalytics.ExistsAsync(database, key);
            if (monthExists)
            {
                return month;
            }

            // no data for the month, so we need to create it from the days
            string[] daysInMonth = BitwiseAnalytics.DateTimeUtil.DaysInMonth(dateTime);

            var keyTasks = new List<Task<RedisKey>>();

            // make sure each day exists
            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (string day in daysInMonth)
            {
                keyTasks.Add(GetDayAsync(
                    database, category, action, DateTime.ParseExact(day, "yyyyMMdd", CultureInfo.InvariantCulture)));
            }

            await Task.WhenAll(keyTasks);

            // combine the days to form one month
            await BitwiseAnalytics.BitwiseOrAsync(
                database,
                key,
                daysInMonth.Select(x => EventKey(category, action, x)).ToArray());

            return key;
        }