コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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}");
        }
コード例 #3
0
        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
        }
コード例 #4
0
        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
            });
        }
コード例 #5
0
        public void Answer()
        {
            if (TelephoneStatus != TelephoneStatus.IncomingCall)
            {
                return;
            }

            TelephoneStatus = TelephoneStatus.Conversation;

            DisplayMethod?.Invoke("You Answered Call");

            OnNotifyPortAboutAnsweredCall(new AnsweredCallEvent("")
            {
                CallStartTime = DateTime.Now
            });
        }
コード例 #6
0
        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");
        }
コード例 #7
0
 public Telephone(Action <string> displayMethod = null)
 {
     DisplayMethod   = displayMethod;
     SerialNumber    = Guid.NewGuid();
     TelephoneStatus = TelephoneStatus.Disabled;
 }
コード例 #8
0
        public void NotifyUserAboutRejectedCall(object sender, RejectedCallEvent e)
        {
            TelephoneStatus = TelephoneStatus.Inaction;

            DisplayMethod?.Invoke($"{e.PhoneNumberOfPersonRejectedCall} - canceled the call");
        }
コード例 #9
0
        public void NotifyUserAboutIncomingCall(object sender, IncomingCallEvent e)
        {
            TelephoneStatus = TelephoneStatus.IncomingCall;

            DisplayMethod?.Invoke($"{e.SenderPhoneNumber} - is calling you");
        }