Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private Timer SetTimer(IPort senderPort, IPort receiverPort)
        {
            var timer = new Timer(CancellationTime);

            timer.Elapsed += (sender, eventArgs) =>
            {
                Logger.WriteLine($"{receiverPort.PhoneNumber} Did not answered call from {senderPort.PhoneNumber}");

                OnNotifyPortOfFailure(
                    new FailureEvent(receiverPort.PhoneNumber, FailureType.AbonentIsNotResponding),
                    senderPort);

                OnNotifyPortOfFailure(
                    new FailureEvent(receiverPort.PhoneNumber, FailureType.AbonentIsNotResponding),
                    receiverPort);

                CallsWaitingToBeAnswered.Remove(senderPort);
                DisposeTimer(senderPort);

                Logger.WriteLine("Base Station Notifies Billing System about Failed Call " +
                                 $"from {senderPort.PhoneNumber} to {receiverPort.PhoneNumber}");

                OnNotifyBillingSystemAboutCallEnd(new UnansweredCallEvent(senderPort.PhoneNumber,
                                                                          receiverPort.PhoneNumber, DateTime.Now));
            };                       // creating logic wich will track time and perform certain actions if time expires

            timer.AutoReset = false; // switch off timer reset
            timer.Enabled   = true;  // enable set timer

            return(timer);
        }
Esempio n. 3
0
        public void AnswerCall(object sender, AnsweredCallEvent e)
        {
            if (!(sender is IPort receiverPort))
            {
                return;
            }

            var senderPort = CallsWaitingToBeAnswered.FirstOrDefault(x => x.Value == receiverPort).Key;

            if (senderPort == null)
            {
                return;
            }

            DisposeTimer(senderPort);                    // dispose timer because call was answered
            CallsWaitingToBeAnswered.Remove(senderPort); // remove information about call from this specified list

            CallsInProgress.Add(new HeldCallEvent(senderPort.PhoneNumber, receiverPort.PhoneNumber)
            {
                CallStartTime = e.CallStartTime
            });                                   //

            Logger.WriteLine($"{receiverPort.PhoneNumber} answered call from {senderPort.PhoneNumber}");
        }