public void NotifyIncomingCallPort(object sender, OutgoingCallEvent e) { var senderPort = sender as IPort; Logger.WriteLine($"{e.SenderPhoneNumber} is calling {e.ReceiverPhoneNumber}"); var checkBalanceEvent = new CheckBalanceEvent(e.SenderPhoneNumber); // create an event object for check balance opperations OnCheckBalanceInBillingSystem(checkBalanceEvent); // Method that checks if abonent have enough balance to make a call Logger.WriteLine($"Checking {e.SenderPhoneNumber} balance"); if (checkBalanceEvent.IsAllowedCall) { Logger.WriteLine($"{e.SenderPhoneNumber} has enough money to make call"); ConnectPorts(senderPort, e); } else { Logger.WriteLine($"{e.SenderPhoneNumber} has not enough money to make call"); OnNotifyPortOfFailure(new FailureEvent(e.ReceiverPhoneNumber, FailureType.InsufficientFunds), senderPort); } }
public void CheckPossibilityOfCall(object sender, CheckBalanceEvent e) { var phone = PhoneManagement.GetPhoneByNumber(e.PhoneNumber); e.IsAllowedCall = phone.Balance >= 0; }
private void OnCheckBalanceInBillingSystem(CheckBalanceEvent e) { CheckBalanceInBillingSystem?.Invoke(this, e); // invokation of event that checks balance and return boolean type if call can be made or not }