コード例 #1
0
ファイル: TcpPackage.cs プロジェクト: danieldeb/EventStore
        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;
        }
コード例 #2
0
 public TcpPackage(TcpCommand command, Guid correlationId, byte[] data)
     : this(command, TcpFlags.None, correlationId, null, null, data)
 {
 }
コード例 #3
0
 public TcpPackage(TcpCommand command, TcpFlags flags, Guid correlationId, string authToken,
                   byte[] data)
     : this(command, flags, correlationId, authToken, new ArraySegment <byte>(data ?? Empty.ByteArray))
 {
 }
コード例 #4
0
ファイル: TcpPackage.cs プロジェクト: danieldeb/EventStore
 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))
 {
 }
コード例 #5
0
ファイル: TcpPackage.cs プロジェクト: danieldeb/EventStore
 public TcpPackage(TcpCommand command, Guid correlationId, byte[] data)
     : this(command, TcpFlags.None, correlationId, null, null, data)
 {
 }
コード例 #6
0
 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);
 }
コード例 #7
0
ファイル: TcpPackage.cs プロジェクト: robashton/EventStore
 public TcpPackage(TcpCommand command, Guid correlationId, byte[] data)
 {
     Command = command;
     CorrelationId = correlationId;
     Data = new ArraySegment<byte>(data ?? EmptyArray);
 }
コード例 #8
0
 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))
 {
 }
コード例 #9
0
        /// <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;
                }
            }
        }
コード例 #10
0
 protected void AddUnwrapper <T>(TcpCommand command, Func <TcpPackage, IEnvelope, TcpConnectionManager, T> unwrapper)
     where T : Message
 {
     _unwrappers[(byte)command] = (Func <TcpPackage, IEnvelope, TcpConnectionManager, Message>)unwrapper;
 }
コード例 #11
0
 protected void AddUnwrapper <T>(TcpCommand command, Func <TcpPackage, IEnvelope, T> unwrapper) where T : Message
 {
     _unwrappers[(byte)command] = (pkg, env, conn) => unwrapper(pkg, env);
 }
コード例 #12
0
        /// <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;
            }
        }
コード例 #13
0
ファイル: TcpDispatcher.cs プロジェクト: dhanzhang/EventStore
 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);
 }
コード例 #14
0
 public TcpPackage(TcpCommand command, Guid correlationId, ArraySegment <byte> data)
 {
     CorrelationId = correlationId;
     Command       = command;
     Data          = data;
 }
コード例 #15
0
 public TcpPackage(TcpCommand command, Guid correlationId, byte[] data)
 {
     Command       = command;
     CorrelationId = correlationId;
     Data          = new ArraySegment <byte>(data ?? EmptyArray);
 }
コード例 #16
0
        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;
            }
        }
コード例 #17
0
 public TcpPackage(TcpCommand command, Guid correlationId, ArraySegment <byte> data)
     : this(command, TcpFlags.None, correlationId, null, data)
 {
 }
コード例 #18
0
 public OKCWorker(TcpCommand tcpCommand) : base(tcpCommand)
 {
 }
コード例 #19
0
 public TcpPackage(TcpCommand command, Guid correlationId, byte[] data)
     : this(command, TcpFlags.None, correlationId, null, new ArraySegment <byte>(data ?? Empty.ByteArray))
 {
 }
コード例 #20
0
 public bool SendCMD(byte[] buf)
 {
     if (SonarIsOK && TCPCmdService.LinkerClient!=null)
     {
         var cmd = new TcpCommand(TCPCmdService.LinkerClient, buf);
         return cmd.Send(out _error);
     }
     return false;
 }
コード例 #21
0
ファイル: TcpPackage.cs プロジェクト: robashton/EventStore
 public TcpPackage(TcpCommand command, Guid correlationId, ArraySegment<byte> data)
 {
     CorrelationId = correlationId;
     Command = command;
     Data = data;
 }
コード例 #22
0
 public bool SendCMD(byte[] buf)
 {
     if (SonarIsOK)
     {
         var cmd = new TcpCommand(_cmdtcpClient, buf);
         return cmd.Send(out _error);
     }
     return false;
 }
コード例 #23
0
 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());
 }
コード例 #24
0
 public Worker(TcpCommand tcpCommand)
 {
     TcpCommand = tcpCommand;
     InternalCommunication.GetInternalCommunication().Method = tcpCommand.Method;
 }
コード例 #25
0
ファイル: TcpPackage.cs プロジェクト: danieldeb/EventStore
 public TcpPackage(TcpCommand command, Guid correlationId, ArraySegment<byte> data)
     : this(command, TcpFlags.None, correlationId, null, null, data)
 {
 }
コード例 #26
0
 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);
 }
コード例 #27
0
 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());
 }
コード例 #28
0
        /// <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;
                    }
                }
            }*/
        }