/// <summary> /// Check to see if the badge type has been recently processed for this user /// </summary> /// <param name="badgeType"></param> /// <param name="user"></param> /// <returns></returns> private bool RecentlyProcessed(BadgeType badgeType, MembershipUser user) { var cacheKey = string.Concat(CacheKeys.Badge.StartsWith, "RecentlyProcessed-", user.Id, "-", badgeType); return(_cacheService.CachePerRequest(cacheKey, () => { var recentlyProcessed = false; var now = DateTime.UtcNow; BadgeTypeTimeLastChecked timeBadgeLastChecked = null; // Go through all the badge-check time records for this user foreach (var nextBadgeTypeCheckedForUser in user.BadgeTypesTimeLastChecked) { var previouslyCheckedBadgeType = FromString(nextBadgeTypeCheckedForUser.BadgeType); if (previouslyCheckedBadgeType == null || previouslyCheckedBadgeType != badgeType) { continue; } // Block the badge check if not enough time has elapsed since last check if ((now - nextBadgeTypeCheckedForUser.TimeLastChecked).TotalMinutes < BadgeCheckIntervalMinutes) { recentlyProcessed = true; } timeBadgeLastChecked = nextBadgeTypeCheckedForUser; timeBadgeLastChecked.TimeLastChecked = now; break; } // If this badge type never checked for this user, add it if (timeBadgeLastChecked == null) { timeBadgeLastChecked = new BadgeTypeTimeLastChecked { BadgeType = badgeType.ToString(), TimeLastChecked = now, User = user }; user.BadgeTypesTimeLastChecked.Add(timeBadgeLastChecked); } return recentlyProcessed; })); }
/// <summary> /// Check to see if the badge type has been recently processed for this user /// </summary> /// <param name="badgeType"></param> /// <param name="user"></param> /// <returns></returns> private bool RecentlyProcessed(BadgeType badgeType, Member user) { var recentlyProcessed = false; var now = DateTime.UtcNow; BadgeTypeTimeLastChecked timeBadgeLastChecked = null; var usersBadgeTypesTimeLastChecked = BadgeTypeTimeLastCheckedByMember(user.Id); // Go through all the badge-check time records for this user foreach (var nextBadgeTypeCheckedForUser in usersBadgeTypesTimeLastChecked) { var previouslyCheckedBadgeType = FromString(nextBadgeTypeCheckedForUser.BadgeType); if (previouslyCheckedBadgeType == null || previouslyCheckedBadgeType != badgeType) { continue; } // Block the badge check if not enough time has elapsed since last check if ((now - nextBadgeTypeCheckedForUser.TimeLastChecked).TotalMinutes < BadgeCheckIntervalMinutes) { recentlyProcessed = true; } timeBadgeLastChecked = nextBadgeTypeCheckedForUser; timeBadgeLastChecked.TimeLastChecked = now; break; } // If this badge type never checked for this user, add it if (timeBadgeLastChecked == null) { timeBadgeLastChecked = new BadgeTypeTimeLastChecked { BadgeType = badgeType.ToString(), TimeLastChecked = now, Member = user, MemberId = user.Id }; ContextPerRequest.Db.BadgeTypeTimeLastChecked.Add(timeBadgeLastChecked); } return(recentlyProcessed); }
/// <summary> /// Create a database badge from a badge class /// </summary> /// <param name="badgeType"></param> /// <param name="classType"></param> /// <returns></returns> private static Badge CreateDbBadgeFromClass(BadgeType badgeType, Type classType) { var idAtt = GetAttribute <IdAttribute>(classType); var nameAtt = GetAttribute <NameAttribute>(classType); var descAtt = GetAttribute <DescriptionAttribute>(classType); var imageAtt = GetAttribute <ImageAttribute>(classType); var displayNameAtt = GetAttribute <DisplayNameAttribute>(classType); var badge = new Badge { Id = idAtt.Id, Name = nameAtt.Name, Description = descAtt.Description, Image = imageAtt.Image, DisplayName = displayNameAtt.DisplayName, Users = new List <MembershipUser>(), Type = badgeType.ToString().TrimEnd(), }; return(badge); }
/// <summary> /// Create a database badge from a badge class /// </summary> /// <param name="badgeType"></param> /// <param name="classType"></param> /// <returns></returns> private static Badge CreateDbBadgeFromClass(BadgeType badgeType, Type classType) { var badge = new Badge { Users = new List <MembershipUser>(), Type = badgeType.ToString().TrimEnd() }; foreach (var attribute in classType.GetCustomAttributes(false)) { if (attribute is IdAttribute) { badge.Id = (attribute as IdAttribute).Id; } if (attribute is NameAttribute) { badge.Name = (attribute as NameAttribute).Name; } if (attribute is DescriptionAttribute) { badge.Description = (attribute as DescriptionAttribute).Description; } if (attribute is ImageAttribute) { badge.Image = (attribute as ImageAttribute).Image; } if (attribute is DisplayNameAttribute) { badge.DisplayName = (attribute as DisplayNameAttribute).DisplayName; } if (attribute is AwardsPointsAttribute) { badge.AwardsPoints = (attribute as AwardsPointsAttribute).Points; } } return(badge); }
public static async Task SendAccess(string itemName, BadgeType type, string subject, string color) { var content = new StringContent(JsonConvert.SerializeObject(new { Item = itemName, Type = type.ToString(), Subject = subject, Color = color }), Encoding.UTF8, "application/json"); if (apiKey != null) { await client.PostAsync($"https://logs-01.loggly.com/inputs/{apiKey}/tag/access/", content); } }