本文整理汇总了C#中JabbR.Commands.CommandContext类的典型用法代码示例。如果您正苦于以下问题:C# CommandContext类的具体用法?C# CommandContext怎么用?C# CommandContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandContext类属于JabbR.Commands命名空间,在下文中一共展示了CommandContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (args.Length == 0)
{
throw new InvalidOperationException("Who are you trying to kick?");
}
string targetUserName = args[0];
ChatUser targetUser = context.Repository.VerifyUser(targetUserName);
string targetRoomName = args.Length > 1 ? args[1] : callerContext.RoomName;
if (String.IsNullOrEmpty(targetRoomName))
{
throw new InvalidOperationException("Which room?");
}
ChatRoom room = context.Repository.VerifyRoom(targetRoomName);
context.Service.KickUser(callingUser, targetUser, room);
context.NotificationService.KickUser(targetUser, room);
context.Repository.CommitChanges();
}
示例2: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (String.IsNullOrEmpty(callerContext.RoomName))
{
throw new InvalidOperationException("This command cannot be invoked from the Lobby.");
}
string targetRoomName = args.Length > 0 ? args[0] : callerContext.RoomName;
if (String.IsNullOrEmpty(targetRoomName))
{
throw new InvalidOperationException("Which room?");
}
ChatRoom targetRoom = context.Repository.VerifyRoom(targetRoomName, mustBeOpen: false);
// ensure the user could join the room if they wanted to
callingUser.EnsureAllowed(targetRoom);
if (String.IsNullOrEmpty(targetRoom.InviteCode))
{
context.Service.SetInviteCode(callingUser, targetRoom, RandomUtils.NextInviteCode());
}
ChatRoom callingRoom = context.Repository.GetRoomByName(callerContext.RoomName);
context.NotificationService.PostNotification(callingRoom, callingUser, String.Format("Invite Code for {0}: {1}", targetRoomName, targetRoom.InviteCode));
}
示例3: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (String.IsNullOrEmpty(callerContext.RoomName))
{
throw new HubException(LanguageResources.InvokeFromRoomRequired);
}
string targetRoomName = args.Length > 0 ? args[0] : callerContext.RoomName;
if (String.IsNullOrEmpty(targetRoomName))
{
throw new HubException(LanguageResources.InviteCode_RoomRequired);
}
ChatRoom targetRoom = context.Repository.VerifyRoom(targetRoomName, mustBeOpen: false);
// ensure the user could join the room if they wanted to
callingUser.EnsureAllowed(targetRoom);
if (String.IsNullOrEmpty(targetRoom.InviteCode))
{
context.Service.SetInviteCode(callingUser, targetRoom, RandomUtils.NextInviteCode());
}
ChatRoom callingRoom = context.Repository.GetRoomByName(callerContext.RoomName);
context.NotificationService.PostNotification(callingRoom, callingUser, String.Format(LanguageResources.InviteCode_Success, targetRoomName, targetRoom.InviteCode));
}
示例4: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (args.Length == 0)
{
throw new InvalidOperationException("Which user to you want to revoke persmissions from?");
}
string targetUserName = args[0];
ChatUser targetUser = context.Repository.VerifyUser(targetUserName);
if (args.Length == 1)
{
throw new InvalidOperationException("Which room?");
}
string roomName = args[1];
ChatRoom targetRoom = context.Repository.VerifyRoom(roomName);
context.Service.UnallowUser(callingUser, targetUser, targetRoom);
context.NotificationService.UnallowUser(targetUser, targetRoom);
context.Repository.CommitChanges();
}
示例5: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
var mentions = ParseMentions(args);
if (mentions.Length == 0)
{
// List current mentions for user
var currentMentions = context.Repository.GetMentionsByUser(callingUser)
.Select(m => m.String);
context.NotificationService.ChangeMentions(callingUser, currentMentions.ToArray(), false);
}
else if (mentions.Length > 5)
{
throw new InvalidOperationException("You are not allowed more than 5 mention strings.");
}
else
{
// Update mentions for user
UpdateMentions(context, callingUser, mentions);
context.NotificationService.ChangeMentions(callingUser, mentions);
context.Repository.CommitChanges();
}
}
示例6: TryHandleCommand
public bool TryHandleCommand(string commandName, string[] args)
{
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;
if (!TryMatchCommand(commandName, out command))
{
throw new InvalidOperationException(String.Format("'{0}' is not a valid command.", commandName));
}
command.Execute(context, callerContext, args);
return true;
}
示例7: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (args.Length == 0)
{
throw new InvalidOperationException("Which owner do you want to remove?");
}
string targetUserName = HttpUtility.HtmlDecode(args[0]);
ChatUser targetUser = context.Repository.VerifyUser(targetUserName);
if (args.Length == 1)
{
throw new InvalidOperationException("Which room?");
}
string roomName = HttpUtility.HtmlDecode(args[1]);
ChatRoom targetRoom = context.Repository.VerifyRoom(roomName);
context.Service.RemoveOwner(callingUser, targetUser, targetRoom);
context.NotificationService.RemoveOwner(targetUser, targetRoom);
context.Repository.CommitChanges();
}
示例8: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (args.Length == 0)
{
throw new InvalidOperationException("Who do you want to grant access permissions to?");
}
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 InvalidOperationException("Which room do you want to allow access to?");
}
ChatRoom targetRoom = context.Repository.VerifyRoom(roomName, mustBeOpen: false);
context.Service.AllowUser(callingUser, targetUser, targetRoom);
context.NotificationService.AllowUser(targetUser, targetRoom);
context.Repository.CommitChanges();
}
示例9: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (context.Repository.Users.Count() == 1)
{
throw new InvalidOperationException("You're the only person in here...");
}
if (args.Length == 0 || String.IsNullOrWhiteSpace(args[0]))
{
throw new InvalidOperationException("Who do you want to send a private message to?");
}
var toUserName = args[0];
ChatUser toUser = context.Repository.VerifyUser(toUserName);
if (toUser == callingUser)
{
throw new InvalidOperationException("You can't private message yourself!");
}
string messageText = String.Join(" ", args.Skip(1)).Trim();
if (String.IsNullOrEmpty(messageText))
{
throw new InvalidOperationException(String.Format("What do you want to say to '{0}'?", toUser.Name));
}
context.NotificationService.SendPrivateMessage(callingUser, toUser, messageText);
}
示例10: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (args.Length == 0)
{
throw new HubException(LanguageResources.Kick_UserRequired);
}
string targetUserName = args[0];
ChatUser targetUser = context.Repository.VerifyUser(targetUserName);
string targetRoomName = args.Length > 1 ? args[1] : callerContext.RoomName;
if (String.IsNullOrEmpty(targetRoomName))
{
throw new HubException(LanguageResources.Kick_RoomRequired);
}
ChatRoom room = context.Repository.VerifyRoom(targetRoomName);
context.Service.KickUser(callingUser, targetUser, room);
// try to extract the reason
string reason = null;
if (args.Length > 2)
{
reason = String.Join(" ", args.Skip(2)).Trim();
}
context.NotificationService.KickUser(targetUser, room, callingUser, reason);
context.Repository.CommitChanges();
}
示例11: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (context.Repository.Users.Count() == 1)
{
throw new InvalidOperationException("You're the only person in here...");
}
if (args.Length == 0 || String.IsNullOrWhiteSpace(args[0]))
{
throw new InvalidOperationException("Who are you trying send a private message to?");
}
var toUserName = HttpUtility.HtmlDecode(args[0]);
ChatUser toUser = context.Repository.VerifyUser(toUserName);
if (toUser == callingUser)
{
throw new InvalidOperationException("You can't private message yourself!");
}
string messageText = String.Join(" ", args.Skip(1)).Trim();
if (String.IsNullOrEmpty(messageText))
{
throw new InvalidOperationException(String.Format("What did you want to say to '{0}'?", toUser.Name));
}
HashSet<string> urls;
var transform = new TextTransform(context.Repository);
messageText = transform.Parse(messageText);
messageText = TextTransform.TransformAndExtractUrls(messageText, out urls);
context.NotificationService.SendPrivateMessage(callingUser, toUser, messageText);
}
示例12: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (args.Length == 0)
{
throw new InvalidOperationException("Who do you want to invite?");
}
string targetUserName = HttpUtility.HtmlDecode(args[0]);
ChatUser targetUser = context.Repository.VerifyUser(targetUserName);
if (targetUser == callingUser)
{
throw new InvalidOperationException("You can't invite yourself!");
}
if (args.Length == 1)
{
throw new InvalidOperationException("Invite them to which room?");
}
string roomName = HttpUtility.HtmlDecode(args[1]);
ChatRoom targetRoom = context.Repository.VerifyRoom(roomName);
context.NotificationService.Invite(callingUser, targetUser, targetRoom);
}
示例13: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (args.Length == 0)
{
throw new InvalidOperationException("Which owner do you want to remove?");
}
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 InvalidOperationException("Which room do you want to remove the owner from?");
}
ChatRoom targetRoom = context.Repository.VerifyRoom(roomName);
context.Service.RemoveOwner(callingUser, targetUser, targetRoom);
context.NotificationService.RemoveOwner(targetUser, targetRoom);
context.Repository.CommitChanges();
}
示例14: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (args.Length == 0)
{
throw new HubException(LanguageResources.Allow_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.Allow_RoomRequired);
}
ChatRoom targetRoom = context.Repository.VerifyRoom(roomName, mustBeOpen: false);
context.Service.AllowUser(callingUser, targetUser, targetRoom);
context.NotificationService.AllowUser(targetUser, targetRoom);
context.Repository.CommitChanges();
}
示例15: Execute
public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
{
if (args.Length == 0)
{
throw new InvalidOperationException("Which room do you want to open?");
}
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.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, room);
}