public override Call CallingImulation(CallInfo info) { ITerminal targetTerminal = TerminalByPhoneNumber(info.Target); int rand = new Random().Next(2); TimeSpan duration = new TimeSpan(); if (rand == 1) { targetTerminal.AnswerTheCall(info); info.Result = Result.Success; int minutes = new Random().Next(60), seconds = new Random().Next(60); OutputImulation(minutes); duration = new TimeSpan(0, minutes, seconds); } else { targetTerminal.DropTheCall(info); info.Result = Result.Fail; } return new Call { Info = info, Statistic = new CallStatistic { Duration = duration } }; }
public void UpdateBillingSystemHandler(object sender,CallInfo information) { if (information != null) { this.CallHistory.Add(information); } }
private void OutgoingConnectionHandler(object t,PhoneNumber targetPhone) { try { if (t is ITerminal) { ITerminal sender = t as ITerminal; if (this.GetPortByPhoneNumber(sender.Number).State == PortState.Free) { GetPortByPhoneNumber(sender.Number).State = PortState.Busy; ITerminal targetTerminal = this.GetTerminalByPhoneNumber(targetPhone); IPort targetPort = this.GetPortByPhoneNumber(targetPhone); Console.WriteLine("\nCalling from " + sender.UserName + " to " + targetTerminal.UserName); if (targetPort.State == PortState.Free) { targetPort.State = PortState.Busy; Console.WriteLine(); var callInfo = new CallInfo() { source = sender, target = targetTerminal, CurrentTariffPlan = sender.CurrentTariff }; // connectionCollection.Add(callInfo); targetTerminal.IncomingRequestFrom(); // } else { Console.WriteLine("Cannot connect to target port."); } } else { Console.WriteLine("Cant connect to your port.Check port settings."); } } } catch (NullReferenceException ex) { Console.WriteLine("Cannot connect"); } }
protected void OnUpdateBillingSystem(CallInfo information) { if (this.UpdateBillingSystem != null) { this.UpdateBillingSystem(this,information); } }