public void OnFlowFinish() { List <Command> commands = this.commandCollector.Commands; if (commands.Count > 0) { List <Command> commandCollection = ClientNetworkInstancesCache.GetCommandCollection(); int count = commands.Count; int num2 = 0; while (true) { if (num2 >= count) { if (commandCollection.Count > 0) { CommandPacket commandPacketInstance = ClientNetworkInstancesCache.GetCommandPacketInstance(commandCollection); this.networkService.SendCommandPacket(commandPacketInstance); } this.commandCollector.Clear(); break; } Command command = commands[num2]; this.logger.InfoFormat("Out {0}", command); commandCollection.Add(command); num2++; } } }
public void WriteCommands() { if (this.IsConnected && this.socket.CanWrite) { while (true) { MemoryStreamData data; while (true) { if (this.packetQueue.Count != 0) { CommandPacket packet = this.packetQueue.Dequeue(); try { data = this.protocolAdapter.Encode(packet); break; } catch (Exception exception) { this.log.DebugFormat("OnSocketProblem {0}", exception.Message); this.OnSocketProblem(ProblemStatus.EncodeError, exception); } finally { ClientNetworkInstancesCache.ReleaseCommandPacketWithCommandsCollection(packet); } return; } else { return; } break; } try { if (this.infoEnabled) { this.log.DebugFormat("WriteCommands {0}", data.Length); } this.socket.Write(data.GetBuffer(), 0, (int)data.Length); } catch (IOException exception2) { this.OnSocketProblem(ProblemStatus.SendError, exception2); } finally { ClientProtocolInstancesCache.ReleaseMemoryStreamData(data); } } } }
private bool ExecuteCommands(CommandPacket packet, long timeToStop, out CommandPacket newPacket) { int num = 0; int count = packet.Commands.Count; while (num < count) { if (CurrentTimeMillis() >= timeToStop) { if (this.infoEnabled) { this.log.InfoFormat("Delay execute {0} commands", count - num); } List <Command> commandCollection = ClientNetworkInstancesCache.GetCommandCollection(); newPacket = ClientNetworkInstancesCache.GetCommandPacketInstance(commandCollection); for (int i = num; i < count; i++) { commandCollection.Add(packet.Commands[i]); } return(false); } Command command = packet.Commands[num]; try { if (this.infoEnabled) { this.log.InfoFormat("Execute {0}", command); } command.Execute(EngineService.Engine); } catch (Exception exception) { if (this.OnCommandExecuteException != null) { this.OnCommandExecuteException(command, exception); } if (!this.SkipThrowOnCommandExecuteException) { this.OnSocketProblem(ProblemStatus.ExecuteCommandError, exception); } } num++; } newPacket = null; return(true); }
private CommandPacket DecodePacket(ProtocolBuffer packetData) { List <Command> commandCollection = ClientNetworkInstancesCache.GetCommandCollection(); while (packetData.Data.Position < packetData.Data.Length) { Command command = (Command)this.commandsCodec.Decode(packetData); if (ReferenceEquals(command.GetType(), typeof(InitTimeCommand)) || ReferenceEquals(command.GetType(), typeof(CloseCommand))) { command.Execute(null); continue; } if (!this.TrySplitCommands(command, commandCollection)) { commandCollection.Add(command); } } return(ClientNetworkInstancesCache.GetCommandPacketInstance(commandCollection)); }
public void FinalizeDecodedCommandPacket(CommandPacket commandPacket) { ClientNetworkInstancesCache.ReleaseCommandPacketWithCommandsCollection(commandPacket); }