/// <summary> /// Generates outgoing connection with remote port. /// </summary> /// <param name="sender">The sender.</param> /// <param name="number">The number.</param> protected virtual void OnTerminalOutgoingCall(object sender, string number) { _callInfo = new CallInfo(number, CallType.Outgoing); if (OnOutgoingCallEvent != null) { OnOutgoingCallEvent(this, _number); } else { _terminal.Drop(); } }
/// <summary> /// Removes the terminal. /// </summary> /// <param name="terminal">The terminal.</param> /// <returns></returns> public bool RemoveTerminal(ITerminal terminal) { if (terminal != null) { string number = GetNumberForTerminal(terminal); if (number != null) { terminal.Drop(); _terminalMapping.Remove(number); return(true); } } return(false); }
public void TestATS() { Station station = new Station(10); List <ITerminal> terminals = new List <ITerminal>(); for (int i = 0; i < 30; i++) { ITerminal terminal = new Terminal(i); terminal.Plug(); terminals.Add(terminal); station.AddTerminal(GenerateNumber(i), terminal); } Random r = new Random(); int j = 0; for (int i = 0; i < 5; i++) { ITerminal terminal1 = terminals[j]; ITerminal terminal2 = terminals[j + 1]; ITerminal terminal3 = terminals[j + 2]; terminal1.Call(GenerateNumber(j + 1)); Assert.AreEqual(true, terminal2.IsRinging); Thread.Sleep(r.Next(100, 300)); terminal3.Call(GenerateNumber(j + 1)); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(3, station.GetPortCountInUse()); IPort port1 = station.GetPortByTerminal(terminal1); IPort port2 = station.GetPortByTerminal(terminal2); IPort port3 = station.GetPortByTerminal(terminal3); Assert.AreEqual(PortState.OutgoingCall, port1.PortState); Assert.AreEqual(PortState.IncomingCall, port2.PortState); Assert.AreEqual(PortState.OutgoingCall, port3.PortState); terminal2.Answer(); Assert.AreEqual(false, terminal2.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(PortState.Busy, port1.PortState); Assert.AreEqual(PortState.Busy, port2.PortState); Assert.AreEqual(PortState.OutgoingCall, port3.PortState); terminal2.Drop(); Assert.AreEqual(true, terminal2.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(2, station.GetPortCountInUse()); Assert.AreEqual(PortState.Free, port1.PortState); Assert.AreEqual(PortState.IncomingCall, port2.PortState); Assert.AreEqual(PortState.OutgoingCall, port3.PortState); terminal2.Answer(); Assert.AreEqual(false, terminal2.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(PortState.Free, port1.PortState); Assert.AreEqual(PortState.Busy, port2.PortState); Assert.AreEqual(PortState.Busy, port3.PortState); terminal2.Drop(); Assert.AreEqual(false, terminal2.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(0, station.GetPortCountInUse()); Assert.AreEqual(PortState.Free, port1.PortState); Assert.AreEqual(PortState.Free, port2.PortState); Assert.AreEqual(PortState.Free, port3.PortState); terminal1.Call(GenerateNumber(j + 2)); Assert.AreEqual(true, terminal3.IsRinging); Thread.Sleep(r.Next(100, 300)); port1 = station.GetPortByTerminal(terminal1); port3 = station.GetPortByTerminal(terminal3); Assert.AreEqual(2, station.GetPortCountInUse()); Assert.AreEqual(PortState.OutgoingCall, port1.PortState); Assert.AreEqual(PortState.IncomingCall, port3.PortState); terminal1.Drop(); Assert.AreEqual(false, terminal3.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(0, station.GetPortCountInUse()); Assert.AreEqual(PortState.Free, port1.PortState); Assert.AreEqual(PortState.Free, port2.PortState); terminal1.Call(GenerateNumber(j + 2)); Assert.AreEqual(true, terminal3.IsRinging); Thread.Sleep(r.Next(100, 300)); terminal2.Call(GenerateNumber(j + 2)); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(3, station.GetPortCountInUse()); port1 = station.GetPortByTerminal(terminal1); port2 = station.GetPortByTerminal(terminal2); port3 = station.GetPortByTerminal(terminal3); Assert.AreEqual(PortState.OutgoingCall, port1.PortState); Assert.AreEqual(PortState.OutgoingCall, port2.PortState); Assert.AreEqual(PortState.IncomingCall, port3.PortState); terminal1.Drop(); Assert.AreEqual(true, terminal3.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(2, station.GetPortCountInUse()); Assert.AreEqual(PortState.OutgoingCall, port2.PortState); Assert.AreEqual(PortState.IncomingCall, port3.PortState); terminal2.Drop(); Assert.AreEqual(false, terminal3.IsRinging); Thread.Sleep(r.Next(100, 300)); Assert.AreEqual(0, station.GetPortCountInUse()); j += 2; } }