public IHandlerConfig Do <TInput, TOutput>( AbstractCommand <TInput, TOutput> command, ISerializer <TOutput> serializer) where TInput : new() where TOutput : CommandResult, new() { return(Do <TInput>(input => new SerializationBasedResponseFiller <TOutput>(serializer, "application/json", (TOutput)command.Execute(input)))); }
public void Send(AbstractCommand c) { LobbyCommands.Add(new CommandEntry() { Client = m_Client, Command = c }); }
private void OnReceivedEvent(AbstractCommand comm) { if (ReceivedEvent != null) { ReceivedEvent(this, new CommandEventHandlerArgs(comm)); } }
public void SendCommand(AbstractCommand command) { m_Server.ServerSendedCommands.Add(new CommandEntry() { Client = this, Command = command }); }
public void AddCommand(AbstractCommand command) { if (!Commands.Exists(c => c.Name == command.Name)) { Commands.Add(command); } }
private void Listen() { while (!listener_stop) { string message = Receiver.GetMessage(); if (message != "") { AbstractCommand command = CommandDecoder.Decode(message); if (command != null) { if (command is StartCommand) { Game.Start(); } else if (command is PauseCommand) { Game.Pause(); } else if (command is StopCommand) { Game.Stop(); } else if (command is PushCommand) { (Game as ServerGameEngine).Push((command as PushCommand).Number); } // Других случаев быть не может, т.к. нераспознанная команда равна null } Console.WriteLine(message); // в целях отладки } } }
protected override void EstablishContext() { base.EstablishContext(); CommandBus = new CommandBus(); Command = A.Fake <AbstractCommand>(); CorrelationId = Guid.NewGuid(); }
public void Enqueue(Command command) { AbstractCommand cmd = command as AbstractCommand; cmd.StateContainer = this; tasks.Enqueue(command); }
public void SubmitCommand(AbstractCommand command) { if (!(command is null)) { m_commandQueue.Enqueue(command); } }
// ------------------------------------------------------------------- public void invokeInputGroupEvent(EInputGroup group, ICommand command) { AbstractCommand absCommand = (AbstractCommand)command; foreach (IUserInputListener listener in inputGroupListeners[group]) { // Pressed key if (absCommand.keyDown) { if (listener == null) { continue; } listener.OnUserInputKeyDown(group, command); } // Holding key if (absCommand.keyHold) { if (listener == null) { continue; } listener.OnUserInputKeyHold(group, command); } // Released key if (!absCommand.keyDown && !absCommand.keyHold) { if (listener == null) { continue; } listener.OnUserInputKeyUp(group, command); } } }
private void OnPlayerSitOutCommandReceived(AbstractCommand command, IBluffinClient client, RemotePlayer p) { var c = (PlayerSitOutCommand)command; client.SendCommand(c.ResponseSuccess()); p.Game.SitOut(p.Player); }
public void SendCommand(AbstractCommand command) { var line = command.Encode(); Logger.LogCommandSent(command, this, line); Send(line); }
public void ExecutarCommand(AbstractCommand command) { if (command.CanExecute(this)) { command.Execute(this); } }
internal void Send(AbstractCommand command) { var jsonString = JsonConvert.SerializeObject(command) + Environment.NewLine; var bytes = Encoding.ASCII.GetBytes(jsonString); _socket.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, OnSent, this); }
private void OnAuthenticateUserCommandReceived(AbstractCommand command, IBluffinClient client) { var c = (AuthenticateUserCommand)command; var u = DataManager.Persistance.Get(c.Username); var ok = false; if (u != null) { client.PlayerName = u.DisplayName; if (DataManager.Persistance.Authenticate(c.Username, c.Password) != null) { if (!Lobby.IsNameUsed(client.PlayerName)) { Lobby.AddName(client.PlayerName); ok = true; client.SendCommand(c.ResponseSuccess()); } else { client.SendCommand(c.ResponseFailure(TaluvaMessageId.NameAlreadyUsed, "The name is already used on the server!")); } } else { client.SendCommand(c.ResponseFailure(TaluvaMessageId.InvalidPassword, "Wrong Password!")); } } else { client.SendCommand(c.ResponseFailure(TaluvaMessageId.UsernameNotFound, "Your username was not in the database!")); } Logger.LogInformation("> Client authenticate to RegisteredMode Server as : {0}. Success={1}", c.Username, ok); }
private void OnCreateUserCommandReceived(AbstractCommand command, IBluffinClient client) { var c = (CreateUserCommand)command; var ok = false; if (!DataManager.Persistance.IsUsernameExist(c.Username)) { if (!DataManager.Persistance.IsDisplayNameExist(c.DisplayName)) { DataManager.Persistance.Register(new UserInfo(c.Username, c.Password, c.Email, c.DisplayName, 7500)); ok = true; client.SendCommand(c.ResponseSuccess()); } else { client.SendCommand(c.ResponseFailure(TaluvaMessageId.NameAlreadyUsed, "The display name is already used on the server!")); } } else { client.SendCommand(c.ResponseFailure(TaluvaMessageId.UsernameAlreadyUsed, "The username is already used on the server!")); } Logger.LogInformation("> Client register to RegisteredMode Server as : {0}. Success={1}", c.Username, ok); }
private TBaseViewType ConstructCommandView(Type viewType, AbstractCommand command) { var view = default(TBaseViewType); if (EnableCaching) { TBaseViewType found; _viewInstanceCache.TryGetValue(viewType, out found); if (found != null) { found.Command = command; return(found); } view = (TBaseViewType)Activator.CreateInstance(viewType); view.Command = command; _viewInstanceCache[viewType] = view; return(view); } view = (TBaseViewType)Activator.CreateInstance(viewType); view.Command = command; return(view); }
void OnDisconnectCommandReceived(AbstractCommand command, IBluffinClient client, RemotePlayer p) { if (p.Game.Table.Params.Lobby.OptionType == LobbyTypeEnum.RegisteredMode) { DataManager.Persistance.Get(p.Client.PlayerName).TotalMoney += p.Player.MoneySafeAmnt; } client.RemovePlayer(p); if (p.Player.State == PlayerStateEnum.Joined || !p.Game.IsPlaying) { var t = p.Game.Table; Logger.LogInformation("> Client '{0}' left table: {2}:{1}", p.Player.Name, t.Params.TableName, p.TableId); p.Game.LeaveGame(p.Player); } else { var blindNeeded = p.Game.Table.Bank.DebtAmount(p.Player); if (!p.Game.Table.Zombies.Contains(p.Player)) { p.Game.Table.Zombies.Add(p.Player); } if (p.Game.State == GameStateEnum.Playing && p.Game.Table.Seats.CurrentPlayer() == p.Player) { p.Game.PlayMoney(p.Player, -1); } else if (blindNeeded > 0) { p.Game.PlayMoney(p.Player, blindNeeded); } } }
private object ToJObject(AbstractCommand cmd) { return(new JObject() { { "name", cmd.Name }, { "cmd-nr", cmd.CmdNr }, { "start-time", cmd.StartTime } }); }
public JobRegistration(AbstractCommand command, IJobDetail jobDetail, ITrigger trigger) : this() { Command = command; JobDetail = jobDetail; Trigger = trigger; }
public void execute(AbstractCommand command) { if (command.undoable()) { lastCommand = command; } command.execute(); }
private void CommandValueChangedHandler(AbstractCommand command) { #if DEBUG Console.WriteLine("CommandValueChanged"); #endif var item = listGestureIntents.SelectedItems[0]; item.SubItems[2].Text = command.Description(); }
void OnListTableCommandReceived(AbstractCommand command, IBluffinClient client) { var c = (ListTableCommand)command; var r = c.ResponseSuccess(); r.Tables = Lobby.ListTables(c.LobbyTypes); client.SendCommand(r); }
public async Task Send(AbstractCommand command) { string serializedCommand = JsonConvert.SerializeObject(command); string data = Protocol.Compress(serializedCommand); await socket.Send(data); }
protected override void EstablishContext() { base.EstablishContext(); this.Command = A.Fake <AbstractCommand>(); this.CorrelationId = Guid.NewGuid(); this.CommandBus = A.Fake <ICommandBus>(); this.Decorator = A.Fake <AbstactCommandBusDecorator>(o => o.WithArgumentsForConstructor(new [] { this.CommandBus })); }
private void OnCheckDisplayExistCommandReceived(AbstractCommand command, IBluffinClient client) { var c = (CheckDisplayExistCommand)command; var r = c.ResponseSuccess(); r.Exist = Lobby.IsNameUsed(c.DisplayName) || DataManager.Persistance.IsDisplayNameExist(c.DisplayName); client.SendCommand(r); }
private void OnCheckUserExistCommandReceived(AbstractCommand command, IBluffinClient client) { var c = (CheckUserExistCommand)command; var r = c.ResponseSuccess(); r.Exist = DataManager.Persistance.IsUsernameExist(c.Username); client.SendCommand(r); }
protected virtual void ExecuteCommandItem(AbstractCommand command) { _currentCommand = command; //放入执行中的命令中 _executingCommands.Add(command); AddDelegateToCommand(command); command.Execute(); }
public virtual void AddCommand(AbstractCommand command) { if (_commands == null) { _commands = new Queue <AbstractCommand>(); } _commands.Enqueue(command); }
public static T GetDecodedCommand <T>(T c) where T : AbstractCommand { string ce = c.Encode(); AbstractCommand dc = AbstractCommand.DeserializeCommand(ce); Assert.AreEqual(c.GetType(), dc.GetType(), "Command and Decoded Command should be the same"); return((T)dc); }
protected virtual void AddDelegateToCommand(AbstractCommand command){ command.OnCommandComplete = OnExecutingCommandItemComplete; command.OnCommandError = OnExecutingCommandItemError; }
protected virtual void OnExecutingCommandItemComplete(AbstractCommand command){ //移除回调函数 RemoveDelegateToCommand (command); switch (_mode) { case CompositeCommandMode.SEQUENCE: //如果执行中的包含的话 就移除这个 if (_executingCommands.Contains(command)) { _executingCommands.Remove(command); } _executedCommands.Add(command); //调用下完成单个命令的回调,让外部可以得知完成了一个,队列中完成的那个命令 if(OnCommandItemComplete != null) { OnCommandItemComplete(command); } //继续执行下一个 ExecuteNextCommand(); break; } }
public void SetCommand(AbstractCommand command) { this.command = command; }
protected virtual void OnExecutingCommandItemError(AbstractCommand command){ }
public virtual void AddCommand(AbstractCommand command){ if (_commands == null) { _commands = new Queue<AbstractCommand>(); } _commands.Enqueue(command); }
protected virtual void ExecuteCommandItem(AbstractCommand command){ _currentCommand = command; //放入执行中的命令中 _executingCommands.Add(command); AddDelegateToCommand(command); command.Execute(); }
protected virtual void RemoveDelegateToCommand(AbstractCommand command){ command.OnCommandComplete = null; command.OnCommandError = null; }