public void AddCallInfo(CallInfo callInfo) { _callCollection.Add(callInfo); OnCallInfoAdded(this, callInfo); }
protected void InterruptConnection(CallInfo connection) { var sourceTerminal = GetTerminal(connection.Source); var sourcePort = GetPort(sourceTerminal); var targetTerminal = GetTerminal(connection.Target); var targetPort = GetPort(targetTerminal); var cl = GetLastConnectionInfo(connection.Target); if (connection == cl && targetPort.State != PortState.Off) { connection.Duration = DateTime.Now - connection.Started; SetPortStateWhenConnectionInterrupted(connection.Source, connection.Target); } else SetPortStateWhenConnectionInterrupted(connection.Source, default(PhoneNumber)); this._connectionCollection.Remove(connection); AddCallInfo(connection); }
protected virtual void OnCallInfoAdded(object sender, CallInfo e) { CallInfoAdded?.Invoke(sender, e); }
protected void InterruptActiveCall(CallInfo connection) { connection.Duration = DateTime.Now - connection.Started; InterruptConnection(connection); }
public void RegisterCall(Request request) { if (request.Source != default(PhoneNumber) && request.Target != default(PhoneNumber)) { var sourceTerminal = GetTerminal(request.Source); var sourcePort = GetPort(sourceTerminal); var targetTerminal = GetTerminal(request.Target); var targetPort = GetPort(targetTerminal); var callInfo = new CallInfo() { Source = request.Source, Target = request.Target, Started = DateTime.Now, Duration = TimeSpan.Zero }; var sourceConnection = GetLastConnectionInfo(request.Source); var targetConnection = GetLastConnectionInfo(request.Target); this._connectionCollection.Add(callInfo); if ((sourceConnection == null && targetConnection == null) && (sourcePort.State != PortState.Off && targetPort.State != PortState.Off)) { sourcePort.State = PortState.Busy; targetPort.State = PortState.Busy; var incomingRequest = new Request(request.Source, request.Target, Request.IncomingCall); targetTerminal.IncomingRequest(incomingRequest); } else { InterruptConnection(callInfo); Console.WriteLine("Drop"); sourceTerminal.IncomingRespond(new Respond(Respond.Drop, request)); } } }