public static void SetUserInGroup(this ICache cache, MessangerUser user, MessangerGroup room, bool value) { string key = CacheKeys.GetUserInGroup(user, room); // Cache this forever since people don't leave rooms often cache.Set(key, value, TimeSpan.FromDays(365)); }
public static bool IsUserInGroup(this IMessangerRepository repository, ICache cache, MessangerUser user, MessangerGroup group) { bool? cached = cache.IsUserInGroup(user, group); if (cached == null) { //TODO: resolve issue here cached = repository.IsUserInGroup(user, group); cache.SetUserInGroup(user, group, cached.Value); } return cached.Value; }
public NewGroupMessage(MessangerGroup group) { NewGroup = group; }
private void UpdateActivity(MessangerUser user, MessangerGroup group) { UpdateActivity(user); OnUpdateActivity(user, group); }
private void OnUpdateActivity(MessangerUser user, MessangerGroup group) { var userViewModel = new UserViewModel(user); Clients.Group(group.Name).updateActivity(userViewModel, group.Name); }
void INotificationService.OnUserJoinedGroup(MessangerUser user, MessangerGroup group) { if (user == null) throw new ArgumentNullException("user"); if (group == null) throw new ArgumentNullException("group"); Clients.Group(group.Name).userJoinedGroup(user); }
public static string GetUserInGroup(MessangerUser user, MessangerGroup room) { return "UserInRoom" + user.Key + "_" + room.Key; }
public static void RemoveUserInGroup(this ICache cache, MessangerUser user, MessangerGroup room) { cache.Remove(CacheKeys.GetUserInGroup(user, room)); }
public static bool? IsUserInGroup(this ICache cache, MessangerUser user, MessangerGroup room) { string key = CacheKeys.GetUserInGroup(user, room); return (bool?)cache.Get(key); }
private HttpResponseMessage CreateResponseMessage(MessangerGroup group) { HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.Created); message.Content = new StringContent(group.Key.ToString()); message.Headers.Location = new Uri(Url.Link("DefaultApiActionParam", new { action = "get", groupName = group.Name })); return message; }
private bool IsUserAllowed(MessangerGroup group, MessangerUser user) { return group.AllowedUsers.Contains(user) || user.IsAdmin; }
private void GenericOpenOrCloseGroup(MessangerUser user, MessangerGroup targetGroup, bool close) { EnsureOwnerOrAdmin(user, targetGroup); if (!close && !targetGroup.Closed) throw new InvalidOperationException(string.Format("{0} is already open.", targetGroup.Name)); else if (close && targetGroup.Closed) throw new InvalidOperationException(String.Format("{0} is already closed.", targetGroup.Name)); targetGroup.Closed = close; _repository.CommitChanges(); }
private static void EnsureOwnerOrAdmin(MessangerUser user, MessangerGroup room) { if (!room.Owners.Contains(user) && !user.IsAdmin) { throw new InvalidOperationException("You are not an owner of room '" + room.Name + "'"); } }
private static void EnsureCreatorOrAdmin(MessangerUser user, MessangerGroup group) { if (user != group.Creator && !user.IsAdmin) { throw new InvalidOperationException("You are not the creator of room '" + group.Name + "'"); } }
public Common.Models.MessangerGroup AddGroup(Common.Models.MessangerUser user, string groupName) { if (groupName.Equals("Lobby", StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException("Lobby is not a valid chat room."); } if (!IsValidGroupName(groupName)) { throw new InvalidOperationException(String.Format("'{0}' is not a valid group name.", groupName)); } var room = new MessangerGroup { Name = groupName, Creator = user }; room.Owners.Add(user); _repository.Add(room); user.OwnedGroups.Add(room); return room; }
public ChangeGroupMessage(MessangerGroup changed) { DefaultGroup = changed; }