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

GetHourAsync() public static method

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

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

            // no data for the hour, so we need to create it from the 15 minute intervals
            string[] fifteenMinutesInHour = BitwiseAnalytics.DateTimeUtil.FifteenMinutesInHour(dateTime);
            await BitwiseAnalytics.BitwiseOrAsync(
                database,
                key,
                fifteenMinutesInHour.Select(x => EventKey(category, action, x)).ToArray());

            return key;
        }