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); }
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); } }
protected void CallWasTerminated(object sender, Response respond) { _ActiveCall = null; _Logger.WriteToLog("-> Call terminate in " + _PhoneNumber.GetValue); }
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); }
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); }
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)); } }
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); } }
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); }
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); } } }