protected void RegisterOutgoingRequest(Requests.OutgoingRequest request) { if ((request.Source != default(PhoneNumber) && request.Target != default(PhoneNumber)) && (GetCallInfo(request.Source) == null && GetConnectionInfo(request.Source) == null)) { var callInfo = new CallInfo() { Tariff = GetTariffByPhoneNumber(request.Source), Caller = request.Source, Target = request.Target, TimeOfCalling = DateTime.Now }; ITerminal targetTerminal = GetTerminalByPhoneNumber(request.Target); IPort targetPort = GetPortByPhoneNumber(request.Target); IPort sourcePort = GetPortByPhoneNumber(request.Source); if (targetPort.State == PortState.connected) { _connectionCollection.Add(callInfo); targetPort.State = PortState.calling; targetTerminal.IncomingRequestFrom(request.Source); } else { sourcePort.State = PortState.connected; OnCallInfoPrepared(this, callInfo); } } }
protected virtual void OnCallInfoPrepared(object sender, CallInfo callInfo) { if (CallInfoPrepared != null) { CallInfoPrepared(sender, callInfo); } }
protected void InterruptConnection(CallInfo callInfo) { this._callCollection.Remove(callInfo); SetPortStateWhenConnectionInterrupted(callInfo.Caller, callInfo.Target); OnCallInfoPrepared(this, callInfo); }
protected void MakeCallActive(CallInfo callInfo) { this._connectionCollection.Remove(callInfo); callInfo.TimeOfCalling = DateTime.Now; this._callCollection.Add(callInfo); }
protected void InterruptActiveCall(CallInfo callInfo) { Thread.Sleep(1000); callInfo.Duration = DateTime.Now - callInfo.TimeOfCalling; this._callCollection.Remove(callInfo); SetPortStateWhenConnectionInterrupted(callInfo.Caller, callInfo.Target); OnCallInfoPrepared(this, callInfo); }