Ejemplo n.º 1
0
        public void SendResponse(object sender, IResponse response)
        {
            if (sender == null) throw new ArgumentNullException(nameof(sender));
            if (response == null) throw new ArgumentNullException(nameof(response));
            if (State == PortState.Close)
                throw new StateException($"{this} closed");

            var senderMac = sender as string;
            if (senderMac == null || senderMac != _registeredTerminalMAC) return;

            if (!IsPortBinded)
            {
                var r = new DropedResponse(response.Request, DropedResponse.PortUnbind);
                OnProcessResponseEvent(r);
                return;
            }

            if (!IsBindedPortNotClosed)
            {
                var r = new DropedResponse(response.Request, DropedResponse.TargetPortUnplagged);
                OnProcessResponseEvent(r);
                return;
            }

            OnSendResponseEvent(SendResponsePreparation(response));
        }
Ejemplo n.º 2
0
        public virtual void ProcessResponse(object sender, IResponse response)
        {
            if (sender == null) throw new ArgumentNullException(nameof(sender));
            if (response == null) throw new ArgumentNullException(nameof(response));
            if (State == PortState.Close)
                throw new StateException($"{this} closed");

            if (State == PortState.Open) return;

            var senderMac = sender as string;
            if (senderMac == null || senderMac != _bindedPortMAC) return;

            if (!IsTerminalRegistered)
            {
                var r = new DropedResponse(response.Request, DropedResponse.TerminalNotRegistered);
                OnSendResponseEvent(r);
                return;
            }

            if (!IsRegisteredTerminalPluged)
            {
                var r = new DropedResponse(response.Request, DropedResponse.TerminalUnplagged);
                OnSendResponseEvent(r);
                return;
            }

            OnProcessResponseEvent(ProcessResponsePreparation(response));
        }
Ejemplo n.º 3
0
 private void OnDropedEvent(DropedResponse e)
 {
     DropedEvent?.Invoke(this, e);
 }
Ejemplo n.º 4
0
        private void TerminalOnDropedEvent(object sender, DropedResponse dropedResponse)
        {
            CallInfo call = RemoveActiveConnectionByActor(dropedResponse.Request.Sender);
            if (call != null)
            {
                OnConnectionFailedEvent(call);
                UnbindPortsByCall(call);
                return;
            }

            call = RemoveActiveCallByActor(dropedResponse.Request.Sender);
            if (call != null)
            {
                Random r = new Random();
                call.Duration = TimeSpan.FromSeconds(r.Next(0, 600));
                OnCallEndEvent(call);
                UnbindPortsByCall(call);
            }
        }
Ejemplo n.º 5
0
        public void SendResponse(IResponse response)
        {
            if (response == null) throw new ArgumentNullException(nameof(response));
            if (State == TerminalState.Unplagged)
                throw new StateException($"{this} unplagged");

            if (State == TerminalState.Offline) return;

            if (!IsPortRegistered)
            {
                var r = new DropedResponse(response.Request, DropedResponse.PortNotRegistered);
                ProcessResponse(MACAddress, r);
                return;
            }

            if (!IsRegisteredPortNotClosed)
            {
                var r = new DropedResponse(response.Request, DropedResponse.PortClose);
                ProcessResponse(MACAddress, r);
                return;
            }

            OnSendResponseEvent(response);
        }