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

GetHour() public static method

Gets the key for the hour covered by the DateTime supplied, creating the data at the key if necessary.
public static GetHour ( IDatabase database, string category, string action, System.DateTime dateTime ) : RedisKey
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 RedisKey
        public static RedisKey GetHour(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 = BitwiseAnalytics.Exists(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);
            BitwiseAnalytics.BitwiseOr(
                database,
                key,
                fifteenMinutesInHour.Select(x => EventKey(category, action, x)).ToArray());

            return key;
        }