public TcpPackage(TcpCommand command, TcpFlags flags, Guid correlationId, string login, string password, ArraySegment<byte> data) { if ((flags & TcpFlags.Authenticated) != 0) { Ensure.NotNull(login, "login"); Ensure.NotNull(password, "password"); } else { if (login != null) throw new ArgumentException("Login provided for non-authorized TcpPackage."); if (password != null) throw new ArgumentException("Password provided for non-authorized TcpPackage."); } Command = command; Flags = flags; CorrelationId = correlationId; Login = login; Password = password; Data = data; }
public TcpPackage(TcpCommand command, Guid correlationId, byte[] data) : this(command, TcpFlags.None, correlationId, null, null, data) { }
public TcpPackage(TcpCommand command, TcpFlags flags, Guid correlationId, string authToken, byte[] data) : this(command, flags, correlationId, authToken, new ArraySegment <byte>(data ?? Empty.ByteArray)) { }
public TcpPackage(TcpCommand command, TcpFlags flags, Guid correlationId, string login, string password, byte[] data) : this(command, flags, correlationId, login, password, new ArraySegment<byte>(data ?? Empty.ByteArray)) { }
protected void AddUnwrapper <T>(TcpCommand command, Func <TcpPackage, IEnvelope, TcpConnectionManager, T> unwrapper, ClientVersion version) where T : Message { _unwrappers[(byte)version][(byte)command] = (pkg, env, user, login, pass, conn) => unwrapper(pkg, env, conn); }
public TcpPackage(TcpCommand command, Guid correlationId, byte[] data) { Command = command; CorrelationId = correlationId; Data = new ArraySegment<byte>(data ?? EmptyArray); }
public TcpPackage(TcpCommand command, TcpFlags flags, Guid correlationId, string login, string password, byte[] data) : this(command, flags, correlationId, login, password, new ArraySegment <byte>(data ?? Empty.ByteArray)) { }
/// <summary> /// Parses the TcpCommand received by the client /// </summary> /// <param name="bytes">Data bytes</param> private void ParseCommand(byte[] bytes) { TcpCommand cmd = new TcpCommand(); cmd.Deserialize(bytes); if (cmd.IsRequest) // Means a client request { switch (cmd.Type) { case TcpCommand.Command.Acknowledge: // Client needs acknowledgement TcpCommand response = new TcpCommand(true, TcpCommand.Command.Acknowledge); byte[] ack_id = response.Serialize(); using (MemoryStream rms = new MemoryStream()) { byte[] _t = BitConverter.GetBytes(this._clientId); // Acknowledge and tell the client his Id rms.Write(ack_id, 0, ack_id.Length); rms.Write(_t, 0, _t.Length); // Send Acknowledgement and Id this.BeginWriteToClient(this._clientId, NetPacket.PacketType.Command, rms.ToArray()); } if (this.OnClientAcknowledged != null) this.OnClientAcknowledged(this._tcpClient, new NetEventArgs(new NetPacket(0, this._clientId, null), "ack")); if (cmd.Data != null) this.InvokeServer(this._clientId, new TcpCommand(TcpCommand.Command.Name, cmd.Data)); break; case TcpCommand.Command.Name: // Client requests name change this.InvokeServer(this._clientId, cmd); break; case TcpCommand.Command.Disconnect: // Client requests name table this.InvokeServer(this._clientId, cmd); break; } } }
protected void AddUnwrapper <T>(TcpCommand command, Func <TcpPackage, IEnvelope, TcpConnectionManager, T> unwrapper) where T : Message { _unwrappers[(byte)command] = (Func <TcpPackage, IEnvelope, TcpConnectionManager, Message>)unwrapper; }
protected void AddUnwrapper <T>(TcpCommand command, Func <TcpPackage, IEnvelope, T> unwrapper) where T : Message { _unwrappers[(byte)command] = (pkg, env, conn) => unwrapper(pkg, env); }
/// <summary> /// Event handler whenever client manager requires a server operation /// </summary> /// <param name="id">Client Id</param> /// <param name="cmd">TcpCommand operation</param> protected void cm_InvokeServer(int id, TcpCommand cmd) { switch (cmd.Type) { case TcpCommand.Command.Name: string prev = this._clientNames[id]; this._clientNames[id] = UTF8Encoding.UTF8.GetString(cmd.Data); this.DispatchNameTable(); if (this.OnStatusChanged != null) this.OnStatusChanged(this._tcpListener, new NetEventArgs(String.Format("{0} is now known as {1}", prev, this._clientNames[id]))); if (this.OnClientStatusChanged != null) this.OnClientStatusChanged(id, this._clientNames[id], cmd); break; case TcpCommand.Command.NameTable: BinaryFormatter bf = new BinaryFormatter(); using (MemoryStream ms = new MemoryStream()) { bf.Serialize(ms, this._clientNames); this._clientManager[id - 1].BeginWriteToClient(0, NetPacket.PacketType.Command, new TcpCommand(true, cmd.Type, ms.ToArray()).Serialize()); } if (this.OnClientStatusChanged != null) this.OnClientStatusChanged(id, this._clientNames[id], cmd); break; case TcpCommand.Command.Disconnect: this._clientManager.Remove(id); string n = this._clientNames[id]; this._clientNames.Remove(id); if (this.OnStatusChanged != null) this.OnStatusChanged(this._tcpListener, new NetEventArgs(String.Format("{0} Disconnected. Reason: {1}", n, UTF8Encoding.UTF8.GetString(cmd.Data)))); if (this.OnClientStatusChanged != null) this.OnClientStatusChanged(id, n, cmd); break; } }
protected void AddUnwrapper <T>(TcpCommand command, Func <TcpPackage, IEnvelope, IPrincipal, string, string, T> unwrapper) where T : Message { _unwrappers[(byte)command] = (pkg, env, user, login, pass, conn) => unwrapper(pkg, env, user, login, pass); }
public TcpPackage(TcpCommand command, Guid correlationId, ArraySegment <byte> data) { CorrelationId = correlationId; Command = command; Data = data; }
public TcpPackage(TcpCommand command, Guid correlationId, byte[] data) { Command = command; CorrelationId = correlationId; Data = new ArraySegment <byte>(data ?? EmptyArray); }
void _server_OnClientStatusChanged(int id, string name, TcpCommand cmd) { this._neuroLog.WriteFormat("Client Status Changed", "Type: {0}\nId: {1}\nName: {2}", cmd.Type, id, name); switch (cmd.Type) { case TcpCommand.Command.Disconnect: this.BeginInvoke(new MethodInvoker(delegate { this.tabControl.TabPages.Remove(this._tabClientPageIndices[id]); this._captureRecorders[id].Dispose(); this._neuroLog.Write("Disposing Capture Recorder"); })); break; case TcpCommand.Command.Name: this.BeginInvoke(new MethodInvoker(delegate { this.UpdateTerminal(this.textLog, Color.Yellow, "Changing name to: " + name); this.tabControl.SelectedTab = this._tabClientPageIndices[id]; this.tabControl.SelectedTab.Text = name; })); break; } }
public TcpPackage(TcpCommand command, Guid correlationId, ArraySegment <byte> data) : this(command, TcpFlags.None, correlationId, null, data) { }
public OKCWorker(TcpCommand tcpCommand) : base(tcpCommand) { }
public TcpPackage(TcpCommand command, Guid correlationId, byte[] data) : this(command, TcpFlags.None, correlationId, null, new ArraySegment <byte>(data ?? Empty.ByteArray)) { }
public bool SendCMD(byte[] buf) { if (SonarIsOK && TCPCmdService.LinkerClient!=null) { var cmd = new TcpCommand(TCPCmdService.LinkerClient, buf); return cmd.Send(out _error); } return false; }
public TcpPackage(TcpCommand command, Guid correlationId, ArraySegment<byte> data) { CorrelationId = correlationId; Command = command; Data = data; }
public bool SendCMD(byte[] buf) { if (SonarIsOK) { var cmd = new TcpCommand(_cmdtcpClient, buf); return cmd.Send(out _error); } return false; }
private static TcpPackage CreateWriteRequestPackage(TcpCommand command, ClientMessage.WriteRequestMessage msg, object dto) { // we forwarding with InternalCorrId, not client's CorrelationId!!! return msg.Login != null && msg.Password != null ? new TcpPackage(command, TcpFlags.Authenticated, msg.InternalCorrId, msg.Login, msg.Password, dto.Serialize()) : new TcpPackage(command, TcpFlags.None, msg.InternalCorrId, null, null, dto.Serialize()); }
public Worker(TcpCommand tcpCommand) { TcpCommand = tcpCommand; InternalCommunication.GetInternalCommunication().Method = tcpCommand.Method; }
public TcpPackage(TcpCommand command, Guid correlationId, ArraySegment<byte> data) : this(command, TcpFlags.None, correlationId, null, null, data) { }
protected void AddUnwrapper <T>(TcpCommand command, Func <TcpPackage, IEnvelope, ClaimsPrincipal, T> unwrapper, ClientVersion version) where T : Message { _unwrappers[(byte)version][(byte)command] = (pkg, env, user, tokens, conn) => unwrapper(pkg, env, user); }
private static TcpPackage CreateWriteRequestPackage(TcpCommand command, ClientMessage.WriteRequestMessage msg, object dto) { // we forwarding with InternalCorrId, not client's CorrelationId!!! if (msg.User == UserManagement.SystemAccount.Principal) { return new TcpPackage(command, TcpFlags.TrustedWrite, msg.InternalCorrId, null, null, dto.Serialize()); } return msg.Login != null && msg.Password != null ? new TcpPackage(command, TcpFlags.Authenticated, msg.InternalCorrId, msg.Login, msg.Password, dto.Serialize()) : new TcpPackage(command, TcpFlags.None, msg.InternalCorrId, null, null, dto.Serialize()); }
/// <summary> /// Parses the TcpCommand received from the server /// </summary> /// <param name="bytes">Data bytes</param> private void ParseCommand(byte[] bytes) { TcpCommand cmd = new TcpCommand(); cmd.Deserialize(bytes); if (cmd.IsResponse) // Server responses { switch (cmd.Type) { case TcpCommand.Command.Acknowledge: this._clientAcknowledged = true; this._id = BitConverter.ToInt32(cmd.Data, 0); // Get client's Id if (this.OnConnectionSuccess != null && this._id != -1) // Raise Connected event if server acknowledged this.OnConnectionSuccess(this._tcpClient, new NetEventArgs(this._tcpClient.Client.RemoteEndPoint, "Connection Success")); break; case TcpCommand.Command.Shutdown: this.Disconnect("Server Shutting Down."); break; case TcpCommand.Command.NameTable: BinaryFormatter bf = new BinaryFormatter(); this._clientNames = (Dictionary<int, string>)bf.Deserialize(new MemoryStream(cmd.Data)); break; } } /*using (MemoryStream ms = new MemoryStream(bytes)) { byte[] data = new byte[sizeof(uint)]; ms.Read(data, 0, data.Length); TcpCommand cmd = new TcpCommand(); cmd.Deserialize(data); if (cmd.IsResponse) { switch (cmd.Type) { case TcpCommand.Command.Acknowledge: data = new byte[sizeof(int)]; ms.Read(data, 0, sizeof(int)); this._id = BitConverter.ToInt32(data, 0); if (this.OnConnectionSuccess != null && this._id != -1) // Raise Connected this.OnConnectionSuccess(this._tcpClient, new NetEventArgs(this._tcpClient.Client.RemoteEndPoint, "Connection Success")); break; case TcpCommand.Command.Shutdown: this.Disconnect("Server Shutting Down."); break; } } }*/ }