private void NoAnsweredCall(object o, EventArgs e) { Port port = (o as Port); port.AnswerEvent -= AnsweredCall; port.RejectEvent -= RejectedCall; port.NoAnswerEvent -= NoAnsweredCall; var connection = ActiveConnections.FirstOrDefault(x => x.Value == port.PhoneNumber); ActiveConnections.Remove(connection.Key); TerminalNoAnswered?.Invoke(this, new CallEventArgs(connection.Value, connection.Key)); if (Calls.ContainsKey(connection)) { Calls[connection].Add(new CallInfo(connection.Key, connection.Value, DateTime.Now, Enums.AnswerType.NotResponding)); } else { Calls.Add(connection, new List <CallInfo>()); Calls[connection].Add(new CallInfo(connection.Key, connection.Value, DateTime.Now, Enums.AnswerType.NotResponding)); } }
private void EndCall(object o, EventArgs e) { Port port = (o as Port); Port secondPort; port.EndCallEventOnPort -= EndCall; var connection = ActiveConnections.FirstOrDefault(x => (x.Value == (o as Port).PhoneNumber) || (x.Key == (o as Port).PhoneNumber)); if (port.PhoneNumber == connection.Key) { secondPort = Ports.First(x => x.PhoneNumber == connection.Value); } else { secondPort = Ports.First(x => x.PhoneNumber == connection.Key); } List <CallInfo> calls = Calls.FirstOrDefault(x => (x.Key.Key == port.PhoneNumber && x.Key.Value == secondPort.PhoneNumber) || (x.Key.Value == port.PhoneNumber && x.Key.Key == secondPort.PhoneNumber)).Value; CallInfo call = calls[calls.Count - 1]; call.FinishCall(DateTime.Now); EndCallEvent?.Invoke(this, call); secondPort.EndCallEventOnPort -= EndCall; ActiveConnections.Remove(connection.Key); }