private IPort CancelNotStartedCall(IPort portRejectedCall, RejectedCallEvent e) { IPort portWhichNeedToSendNotification; string senderPhoneNumber; string receiverPhoneNumber; if (CallsWaitingToBeAnswered.ContainsKey(portRejectedCall)) { portWhichNeedToSendNotification = CallsWaitingToBeAnswered[portRejectedCall]; senderPhoneNumber = portRejectedCall.PhoneNumber; receiverPhoneNumber = portWhichNeedToSendNotification.PhoneNumber; CallsWaitingToBeAnswered.Remove(portRejectedCall); } else { portWhichNeedToSendNotification = CallsWaitingToBeAnswered.FirstOrDefault(x => x.Value == portRejectedCall).Key; senderPhoneNumber = portWhichNeedToSendNotification.PhoneNumber; receiverPhoneNumber = portRejectedCall.PhoneNumber; CallsWaitingToBeAnswered.Remove(portWhichNeedToSendNotification); } DisposeTimer(portRejectedCall); OnNotifyBillingSystemAboutCallEnd(new UnansweredCallEvent(senderPhoneNumber, receiverPhoneNumber, e.CallRejectionTime)); Logger.WriteLine( $"{portRejectedCall.PhoneNumber} rejected call from {portWhichNeedToSendNotification.PhoneNumber}"); return(portWhichNeedToSendNotification); }
private void OnNotifyPortAboutRejectionOfCall(RejectedCallEvent e, IPort port) { if (NotifyPortOfRejectionOfCall?.GetInvocationList().FirstOrDefault(x => x.Target == port) != null) { (NotifyPortOfRejectionOfCall?.GetInvocationList().First(x => x.Target == port) as EventHandler <RejectedCallEvent>)?.Invoke(this, e); // changes port and telephone status and send notification } }
public void RejectCall(object sender, RejectedCallEvent e) { PortStatus = PortStatus.Free; OnNotifyStationAboutRejectionOfCall(new RejectedCallEvent(PhoneNumber) { CallRejectionTime = e.CallRejectionTime }); }
public void RejectCall(object sender, RejectedCallEvent e) { if (!(sender is IPort portRejectedCall)) { return; } var suitableCall = CallsInProgress.FirstOrDefault(x => x.ReceiverPhoneNumber == portRejectedCall.PhoneNumber || x.SenderPhoneNumber == portRejectedCall.PhoneNumber); var portWhichNeedToSendNotification = suitableCall is IAnsweredCall answeredCall ? CompleteCallInProgress(portRejectedCall, answeredCall, e) : CancelNotStartedCall(portRejectedCall, e); // check if call was answered and perform next actions depending on that situation OnNotifyPortAboutRejectionOfCall(e, portWhichNeedToSendNotification); }
private IPort CompleteCallInProgress(IPort portRejectedCall, IAnsweredCall call, RejectedCallEvent e) { var portWhichNeedToSendNotification = call.SenderPhoneNumber == portRejectedCall.PhoneNumber ? Ports.FirstOrDefault(x => x.PhoneNumber == call.ReceiverPhoneNumber) : Ports.FirstOrDefault(x => x.PhoneNumber == call.SenderPhoneNumber); if (portWhichNeedToSendNotification != null) { Logger.WriteLine( $"{portRejectedCall.PhoneNumber} ended call with {portWhichNeedToSendNotification.PhoneNumber}"); } CallsInProgress.Remove(call); Logger.WriteLine("Call completed " + $"from {call.SenderPhoneNumber} to {call.ReceiverPhoneNumber}"); OnNotifyBillingSystemAboutCallEnd(new HeldCallEvent(call.SenderPhoneNumber, call.ReceiverPhoneNumber, call.CallStartTime, e.CallRejectionTime)); return(portWhichNeedToSendNotification); }
public void InformTelephoneAboutRejectionOfCall(object sender, RejectedCallEvent e) { PortStatus = PortStatus.Free; OnNotifyTelephoneOfRejectionOfCall(e); }
private void OnNotifyTelephoneOfRejectionOfCall(RejectedCallEvent e) { NotifyTelephoneOfRejectionOfCall?.Invoke(this, e); }
private void OnNotifyStationAboutRejectionOfCall(RejectedCallEvent e) { NotifyStationOfRejectionOfCall?.Invoke(this, e); }
public void NotifyUserAboutRejectedCall(object sender, RejectedCallEvent e) { TelephoneStatus = TelephoneStatus.Inaction; DisplayMethod?.Invoke($"{e.PhoneNumberOfPersonRejectedCall} - canceled the call"); }