Exemplo n.º 1
0
 /// <summary>
 /// Enum to text
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static string ToText(SlotType.Enum type)
 {
     return(type switch
     {
         SlotType.Enum.Day => SlotType.Day,
         SlotType.Enum.Hour => SlotType.Hour,
         SlotType.Enum.Min => SlotType.Min,
         _ => throw new Exception("Invalid slot type"),
     });
Exemplo n.º 2
0
        /// <summary>
        /// DecrementStats
        /// </summary>
        /// <param name="statsType">Model.StatsType.*</param>
        /// <param name="slotType"></param>
        /// <param name="slotId"></param>
        /// <param name="placeId"></param>
        /// <returns></returns>
        public virtual async Task <long?> GetStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, long slotId)
        {
            var time = new DateTimeOffset(slotId, TimeSpan.Zero);
            var t    = slotType switch
            {
                SlotType.Enum.Day => time.RoundDay(),
                SlotType.Enum.Hour => time.RoundHour(),
                SlotType.Enum.Min => time.RoundMinute(),
                _ => throw new Exception("Invalid slot type"),
            };/**/
            var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}";

            return(await redisCacheClient.Db0.HashGetAsync <long?>(
                       $"{configuration["db-prefix"]}{REDIS_KEY_SLOT_STATS}",
                       keyPlace
                       ));
        }
Exemplo n.º 3
0
        /// <summary>
        /// DecrementStats
        /// </summary>
        /// <param name="statsType">Model.StatsType.*</param>
        /// <param name="slotType"></param>
        /// <param name="time"></param>
        /// <param name="placeId"></param>
        /// <returns></returns>
        public virtual async Task <long> DecrementStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, DateTimeOffset time)
        {
            var t = slotType switch
            {
                SlotType.Enum.Day => time.RoundDay(),
                SlotType.Enum.Hour => time.RoundHour(),
                SlotType.Enum.Min => time.RoundMinute(),
                _ => throw new Exception("Invalid slot type"),
            };
            var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}";

            return(await redisCacheClient.Db0.HashIncerementByAsync(
                       $"{configuration["db-prefix"]}{REDIS_KEY_SLOT_STATS}",
                       keyPlace,
                       -1
                       ));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Return stats for specific place and time
        /// </summary>
        /// <param name="statsType"></param>
        /// <param name="slotType"></param>
        /// <param name="placeId"></param>
        /// <param name="slotId"></param>
        /// <returns></returns>
        public async override Task <long?> GetStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, long slotId)
        {
            var time = new DateTimeOffset(slotId, TimeSpan.Zero);
            var t    = slotType switch
            {
                SlotType.Enum.Day => time.RoundDay(),
                SlotType.Enum.Hour => time.RoundHour(),
                SlotType.Enum.Min => time.RoundMinute(),
                _ => throw new Exception("Invalid slot type"),
            };/**/
            var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}";

            if (Stats.ContainsKey(keyPlace))
            {
                return(Stats[keyPlace]);
            }
            return(0);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Decrement stats
        /// </summary>
        /// <param name="statsType"></param>
        /// <param name="slotType"></param>
        /// <param name="placeId"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public async override Task <long> DecrementStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, DateTimeOffset time)
        {
            var t = slotType switch
            {
                SlotType.Enum.Day => time.RoundDay(),
                SlotType.Enum.Hour => time.RoundHour(),
                SlotType.Enum.Min => time.RoundMinute(),
                _ => throw new Exception("Invalid slot type"),
            };
            var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}";

            if (!Stats.ContainsKey(keyPlace))
            {
                Stats[keyPlace] = 0;
            }
            Stats[keyPlace]--;
            return(Stats[keyPlace]);
        }