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 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 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 string GetDisplayName(MethodInfo methodInfo, object[] data) { if (DisplayMethod == null) { if (string.IsNullOrEmpty(DisplayMethodName)) { return(null); } DisplayMethod = MethodClass.GetMethod(DisplayMethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (DisplayMethodName == null) { throw new InvalidOperationException($"could not resolve test data display method:" + $" class=[{MethodClass.FullName}]" + $" method=[{DisplayMethodName}]"); } } if (TestMethod == null) { TestMethod = methodInfo; } object[] methodParams = null; var paramInfos = DisplayMethod.GetParameters(); var paramLen = paramInfos.Length; if (paramLen == 2 && paramInfos[1].ParameterType == typeof(object[])) { methodParams = new object[] { this, data }; } else if (paramLen > 1) { methodParams = new object[data.Length + 1]; methodParams[0] = this; Array.Copy(data, 0, methodParams, 1, data.Length); } else if (paramLen > 0) { methodParams = new object[] { this }; } return((string)DisplayMethod.Invoke(null, methodParams)); }
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 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"); }