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

GetDayAsync() public static method

Gets the key for the day covered by the DateTime supplied, creating the data at the key if necessary.
public static GetDayAsync ( 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> GetDayAsync(
            IDatabase database, string category, string action, DateTime dateTime)
        {
            // get the key
            string day = BitwiseAnalytics.DateTimeUtil.OneDay(dateTime);
            RedisKey key = EventKey(category, action, day);

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

            // no data for the day, so we need to create it from the hours
            string[] hoursInDay = BitwiseAnalytics.DateTimeUtil.HoursInDay(dateTime);

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

            // make sure each hour exists
            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (string hour in hoursInDay)
            {
                keyTasks.Add(GetHourAsync(
                    database,
                    category,
                    action,
                    DateTime.ParseExact(hour, "yyyyMMddHH", CultureInfo.InvariantCulture)));
            }

            await Task.WhenAll(keyTasks);

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

            return key;
        }