public ConnectResponse(ConnectRequest request, int code)
        {
            if (request == null) throw new ArgumentNullException(nameof(request));

            ConnectRequest = request;
            Code = code;
        }
        private void TerminalOnConnectingEvent(object sender, ConnectRequest connectRequest)
        {
            if (connectRequest == null) throw new ArgumentNullException(nameof(connectRequest));

            IPort sourcePort = GetPortByPhoneNumber(connectRequest.Sender);
            IPort targetPort = GetPortByPhoneNumber(connectRequest.Target);

            if (sourcePort != null && sourcePort.State == PortState.Open &&
                targetPort != null && targetPort.State == PortState.Open &&
                sourcePort.MACAddress != targetPort.MACAddress)
            {
                sourcePort.BindPort(targetPort);
                targetPort.BindPort(sourcePort);
            }

            CallInfo call = new CallInfo
            {
                Source = connectRequest.Sender,
                Target = connectRequest.Target,
                Started = DateTime.Now
            };
            _activeConnections.Add(new SourseTargetPair(connectRequest.Sender, connectRequest.Target), call);
        }
 private void OnConnectingEvent(ConnectRequest request)
 {
     ConnectingEvent?.Invoke(MACAddress, request);
 }
        public void Connect(PhoneNumber phoneNumber)
        {
            if (State == TerminalState.Unplagged)
                throw new StateException($"{this} unplagged");
            if (State == TerminalState.Online)
                throw new StateException($"{this} already online");

            State = TerminalState.Online;
            var r = new ConnectRequest(ConnectRequest.UnprotectedConnection, PhoneNumber, phoneNumber);
            OnConnectingEvent(r);
            SendRequest(r);
        }