예제 #1
0
        public void CallWasCompleted(Response response)
        {
            _State = PortState.Free;

            _Logger.WriteToLog("-> Target port change state in " + _State);

            OnRequestWasCompleted(this, response);
        }
 public static string ToLogString(Response response)
 {
     return String.Format("Respond state is {2} on call from {0} to {1}",
         response.IncomingRequest.SourceNumber.GetValue, response.IncomingRequest.TargetNumber.GetValue, response.State);
 }
예제 #3
0
        protected void SendResponse(Request request, ResponseState state)
        {
            if (OnResponse != null)
            {
                var respond = new Response(state, request);

                _Logger.WriteToLog("-> Response on incoming call");
                _Logger.WriteToLog(ObjectToLogString.ToLogString(respond));

                OnResponse(this, respond);
            }
        }
예제 #4
0
        protected void CallWasTerminated(object sender, Response respond)
        {
            _ActiveCall = null;

            _Logger.WriteToLog("-> Call terminate in " + _PhoneNumber.GetValue);
        }
예제 #5
0
 public void OutgoingResponse(object sender, Response response)
 {
     _State = response.State == ResponseState.Answer ? PortState.Busy : PortState.Free;
     _Logger.WriteToLog("-> Port on number " + (sender as ITerminal).Number.GetValue + " change state in " + _State);
     OnOutgoingResponse(this, response);
 }
예제 #6
0
        public void TerminateCall(object sender, Response response)
        {
            _State = PortState.Free;

            _Logger.WriteToLog("-> Port on number " + (sender as ITerminal).Number.GetValue + " change state in " + _State);

            OnTerminateRequest(this, response);
        }
예제 #7
0
        protected void ProcessEndOfCall(object sender, Response response)
        {
            var senderPort = _RoutingPorts[response.IncomingRequest.SourceNumber];
            var targetPort = _RoutingPorts[response.IncomingRequest.TargetNumber];

            var callInfo = _ActiveCalls.FirstOrDefault(x => x.Source == response.IncomingRequest.SourceNumber
               && x.Target == response.IncomingRequest.TargetNumber);

            if (callInfo != null)
            {
                callInfo.Duration = LocalTimeSpan.Duration(callInfo.StartedAt, LocalDateTime.Now);

                _Logger.WriteToLog("-> ATS process end on");
                _Logger.WriteToLog(ObjectToLogString.ToLogString(response.IncomingRequest));

                TerminateCall(_ActiveCalls, response, (sender as IPort));
            }
        }
예제 #8
0
        protected void TerminateCall(ICollection<CallInfo> calls, Response response, IPort sender)
        {
            var terminateCall =
                calls.SingleOrDefault(x => x.Source == response.IncomingRequest.SourceNumber &&
                    x.Target == response.IncomingRequest.TargetNumber);

            if (terminateCall != null)
            {
                calls.Remove(terminateCall);

                var senderPort = _RoutingPorts[response.IncomingRequest.SourceNumber];
                var targetPort = _RoutingPorts[response.IncomingRequest.TargetNumber];

                if (senderPort == sender)
                {
                    targetPort.CallWasCompleted(response);
                }
                else
                {
                    senderPort.CallWasCompleted(response);
                }

                if (terminateCall.Duration == new TimeSpan(0, 0, 0))
                {
                    terminateCall.StartedAt = LocalDateTime.Now;
                }

                OnTerminateCall(this, terminateCall);
            }
        }
예제 #9
0
        protected void RejectRequest(Request request, ResponseState responseState, IPort port)
        {
            var response = new Response(responseState, request);
            _Logger.WriteToLog("-> ATS reject");
            _Logger.WriteToLog(ObjectToLogString.ToLogString(response));

            CallInfo call = new CallInfo(request.SourceNumber, request.TargetNumber);
            call.StartedAt = LocalDateTime.Now;

            port.CallWasCompleted(response);
            OnTerminateCall(this, call);
        }
예제 #10
0
        protected void ProcessResponse(object sender, Response response)
        {
            var senderPort = _RoutingPorts[response.IncomingRequest.SourceNumber];
            var targetPort = _RoutingPorts[response.IncomingRequest.TargetNumber];

            var callInfo = _ConnectingCalls
                .FirstOrDefault(x => x.Source == response.IncomingRequest.SourceNumber
                && x.Target == response.IncomingRequest.TargetNumber);

            _Logger.WriteToLog("-> ATS process");
            _Logger.WriteToLog(ObjectToLogString.ToLogString(response));

            if (callInfo != null)
            {
                _ConnectingCalls.Remove(callInfo);

                if (response.State == ResponseState.Answer)
                {
                    callInfo.StartedAt = LocalDateTime.Now;
                    _ActiveCalls.Add(callInfo);
                }
                else
                {
                    TerminateCall(_ConnectingCalls, response, targetPort);
                }
            }
        }