public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args) { if (args.Length == 0) { throw new HubException(LanguageResources.AddOwner_UserRequired); } string targetUserName = args[0]; ChatUser targetUser = context.Repository.VerifyUser(targetUserName); string roomName = args.Length > 1 ? args[1] : callerContext.RoomName; if (String.IsNullOrEmpty(roomName)) { throw new HubException(LanguageResources.AddOwner_RoomRequired); } ChatRoom targetRoom = context.Repository.VerifyRoom(roomName); context.Service.AddOwner(callingUser, targetUser, targetRoom); context.NotificationService.AddOwner(targetUser, targetRoom); context.Repository.CommitChanges(); }
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args) { if (args.Length == 0) { throw new HubException(LanguageResources.Join_RoomRequired); } // Extract arguments string roomName = args[0]; string inviteCode = null; if (args.Length > 1) { inviteCode = args[1]; } // Locate the room, does NOT have to be open ChatRoom room = context.Repository.VerifyRoom(roomName, mustBeOpen: false); if (!context.Repository.IsUserInRoom(context.Cache, callingUser, room)) { // Join the room context.Service.JoinRoom(callingUser, room, inviteCode); context.Repository.CommitChanges(); } context.NotificationService.JoinRoom(callingUser, room); //Clients.Caller.JoinRoom(callingUser, room); }
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args) { if (args.Length == 0) { throw new HubException(LanguageResources.Open_RoomRequired); } string roomName = args[0]; ChatRoom room = context.Repository.VerifyRoom(roomName, mustBeOpen: false); context.Service.OpenRoom(callingUser, room); // join the room, unless already in the room if (!room.Users.Select(r => r.ChatUserKeyNavigation).Contains(callingUser)) { context.Service.JoinRoom(callingUser, room, inviteCode: null); context.Repository.CommitChanges(); context.NotificationService.JoinRoom(callingUser, room); } var users = room.Users.ToList(); context.NotificationService.UnCloseRoom(users.Select(u => u.ChatUserKeyNavigation).ToList(), room); }
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args) { ChatRoom room = context.Repository.VerifyUserRoom(context.Cache, callingUser, callerContext.RoomName); room.EnsureOpen(); if (args.Length == 0) { throw new HubException(LanguageResources.Me_ActionRequired); } var content = String.Join(" ", args); context.NotificationService.OnSelfMessage(room, callingUser, content); }
public bool TryHandleCommand(string commandName, string[] args) { if (String.IsNullOrEmpty(commandName)) { return(false); } commandName = commandName.Trim(); if (commandName.StartsWith("/")) { return(false); } var context = new CommandContext { Cache = _cache, NotificationService = _notificationService, Repository = _repository, Service = _chatService }; var callerContext = new CallerContext { ClientId = _clientId, UserId = _userId, UserAgent = _userAgent, RoomName = _roomName, }; ICommand command; try { MatchCommand(commandName, out command); } catch (CommandNotFoundException) { throw new HubException(String.Format(LanguageResources.CommandNotFound, commandName)); } catch (CommandAmbiguityException e) { throw new HubException(String.Format(LanguageResources.CommandAmbiguous, commandName, String.Join(", ", e.Ambiguities))); } command.Execute(context, callerContext, args); return(true); }
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args) { string targetRoomName = args.Length > 0 ? args[0] : callerContext.RoomName; if (String.IsNullOrEmpty(targetRoomName)) { throw new HubException(LanguageResources.Leave_RoomRequired); } ChatRoom room = context.Repository.VerifyRoom(targetRoomName, mustBeOpen: false); context.Service.LeaveRoom(callingUser, room); context.NotificationService.LeaveRoom(callingUser, room); context.Repository.CommitChanges(); }
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args) { string roomName = args.Length > 0 ? args[0] : callerContext.RoomName; if (String.IsNullOrEmpty(roomName)) { throw new HubException(LanguageResources.List_RoomRequired); } ChatRoom room = context.Repository.VerifyRoom(roomName); // ensure the user could join the room if they wanted to callingUser.EnsureAllowed(room); var names = context.Repository.GetOnlineUsers(room).Select(s => s.Name); context.NotificationService.ListUsers(room, names); }
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args) { if (args.Length > 1) { throw new HubException(LanguageResources.RoomInvalidNameSpaces); } if (args.Length == 0) { throw new HubException(LanguageResources.RoomRequired); } string roomName = args[0]; if (String.IsNullOrWhiteSpace(roomName)) { throw new HubException(LanguageResources.RoomRequired); } ChatRoom room = context.Repository.GetRoomByName(roomName); if (room != null) { if (!room.Closed) { throw new HubException(String.Format(LanguageResources.RoomExists, roomName)); } else { throw new HubException(String.Format(LanguageResources.RoomExistsButClosed, roomName)); } } // Create the room, then join it room = context.Service.AddRoom(callingUser, roomName); context.Service.JoinRoom(callingUser, room, null); context.Repository.CommitChanges(); context.NotificationService.JoinRoom(callingUser, room); }
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args) { string roomName = args.Length > 0 ? args[0] : callerContext.RoomName; if (String.IsNullOrEmpty(roomName)) { throw new HubException(LanguageResources.Close_RoomRequired); } ChatRoom room = context.Repository.VerifyRoom(roomName); // Before I close the room, I need to grab a copy of -all- the users in that room. // Otherwise, I can't send any notifications to the room users, because they // have already been kicked. var users = room.Users.ToList(); context.Service.CloseRoom(callingUser, room); context.NotificationService.CloseRoom(users.Select(u => u.ChatUserKeyNavigation).ToList(), room); }
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args) { context.NotificationService.LogOut(callingUser, callerContext.ClientId); }
public abstract void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args);
void ICommand.Execute(CommandContext context, CallerContext callerContext, string[] args) { ChatUser user = context.Repository.VerifyUserId(callerContext.UserId); Execute(context, callerContext, user, args); }