public void NotifyUserAboutError(object sender, FailureEvent e) { TelephoneStatus = TelephoneStatus.Inaction; switch (e.FailureType) { case FailureType.InsufficientFunds: DisplayMethod?.Invoke("You don't have enough funds to make a call"); break; case FailureType.AbonentIsBusy: DisplayMethod?.Invoke($"{e.PhoneNumber} - Abonent is Busy"); break; case FailureType.AbonentDoesNotExist: DisplayMethod?.Invoke($"{e.PhoneNumber} - Abonent Doesn't Exist"); break; case FailureType.AbonentIsNotResponding: DisplayMethod?.Invoke(sender is IPort port && port.PhoneNumber == e.PhoneNumber ? "You Have Missed Call" : $"{e.PhoneNumber} - Abonent Is Not Responding"); break; default: DisplayMethod?.Invoke("Unknown Error"); break; } }
public void ConnectToPort(IPort port) { if (!IsPossibleToConnect(port)) { DisplayMethod?.Invoke("Unable to Connect to Port"); return; } Mapping.MergeTelephoneAndPortBehaviorWhenConnecting(this, port as IPort); var connectionEvent = new ConnectionEvent(port); // initialize new connection event OnConnectedToPort(connectionEvent); // invoke connection event (switch port status) if (connectionEvent.Port == null) { DisplayMethod?.Invoke("Another Telephone is Already Connected to This Port"); return; } Mapping.ConnectTelephoneToPort(this, connectionEvent.Port as IPort); TelephoneStatus = TelephoneStatus.Inaction; DisplayMethod?.Invoke($"{this.SerialNumber} was connected to {port.IdentificationNumber}"); }
public void Call(string receiverPhoneNumber) { if (TelephoneStatus != TelephoneStatus.Inaction) { return; } TelephoneStatus = TelephoneStatus.OutgoingCall; OnNotifyPortOfOutgoingCall(new OutgoingCallEvent("", receiverPhoneNumber)); // Method to invoke event that write line with information about call, checks balance and connect port if call is allowed }
public void Reject() { if (TelephoneStatus == TelephoneStatus.Inaction || TelephoneStatus == TelephoneStatus.Disabled) { return; } TelephoneStatus = TelephoneStatus.Inaction; DisplayMethod?.Invoke("You Rejected Call"); OnNotifyPortAboutRejectionOfCall(new RejectedCallEvent("") { CallRejectionTime = DateTime.Now }); }
public void Answer() { if (TelephoneStatus != TelephoneStatus.IncomingCall) { return; } TelephoneStatus = TelephoneStatus.Conversation; DisplayMethod?.Invoke("You Answered Call"); OnNotifyPortAboutAnsweredCall(new AnsweredCallEvent("") { CallStartTime = DateTime.Now }); }
public void DisconnectFromPort() { if (TelephoneStatus == TelephoneStatus.Disabled) { DisplayMethod?.Invoke($"{this.SerialNumber} is Already Disconnected"); return; } var connectionEvent = new ConnectionEvent(null); OnDisconnectedFromPort(connectionEvent); Mapping.SeparateTelephoneAndPortBehaviorWhenDisconnecting(this, connectionEvent.Port as IPort); Mapping.DisconnectTelephoneFromPort(this, connectionEvent.Port as IPort); TelephoneStatus = TelephoneStatus.Disabled; DisplayMethod?.Invoke($"{this.SerialNumber} was disconnected"); }
public Telephone(Action <string> displayMethod = null) { DisplayMethod = displayMethod; SerialNumber = Guid.NewGuid(); TelephoneStatus = TelephoneStatus.Disabled; }
public void NotifyUserAboutRejectedCall(object sender, RejectedCallEvent e) { TelephoneStatus = TelephoneStatus.Inaction; DisplayMethod?.Invoke($"{e.PhoneNumberOfPersonRejectedCall} - canceled the call"); }
public void NotifyUserAboutIncomingCall(object sender, IncomingCallEvent e) { TelephoneStatus = TelephoneStatus.IncomingCall; DisplayMethod?.Invoke($"{e.SenderPhoneNumber} - is calling you"); }