protected virtual void PortOnCallAccepted(object sender, AnswerEventArgs e)
        {
            var port1 = ActivePorts.FirstOrDefault(x => x.Key.Number == e.number1).Key;
            var port2 = EnabledPorts.FirstOrDefault(x => x.Number == e.number2);

            AnswerOnAccept?.Invoke(this, new ConnectionEventArgs(port1, port2, e.message));
        }
        protected virtual void PortOnPortDisabled(object sender, EventArgs e)
        {
            var port = sender as Port;

            if (EnabledPorts.Contains(port))
            {
                EnabledPorts.Remove(port);
                DisabledPorts.Add(port);
            }
            else if (ActivePorts.ContainsKey(port))
            {
                ActivePorts.Remove(port);
                DisabledPorts.Add(port);
            }
        }
        protected virtual void PortOnPortStateSetToActive(object sender, CallEventArgs phoneNumberArgs)
        {
            var port = sender as Port;

            if (DisabledPorts.Contains(port))
            {
                DisabledPorts.Remove(port);
                ActivePorts.Add(port, phoneNumberArgs.number);
            }
            if (EnabledPorts.Contains(port))
            {
                EnabledPorts.Remove(port);
                ActivePorts.Add(port, phoneNumberArgs.number);
            }
            CheckActivePortCalledNumber(port, phoneNumberArgs.number);
        }
        protected virtual void PortOnPortConnectionEstablished(object sender, ConnectionEstablishedEventArgs e)
        {
            var port1 = e.port1;
            var port2 = e.port2;

            if (port1 == null || port2 == null)
            {
                return;
            }
            ActivePorts.Remove(port1);
            EnabledPorts.Remove(port2);
            CallingPorts.Add(port1);
            CallingPorts.Add(port2);

            var call = new Call(port1.Number, port2.Number);

            call.Start();
            CurrentCalls.Add(call);
        }
 private bool IsActiveListContainsCalledNumber(int number)
 {
     return(ActivePorts.Any(pair => pair.Key.Number == number));
 }
        protected virtual void PortOnCallRejected(object sender, AnswerEventArgs e)
        {
            var port1 = ActivePorts.FirstOrDefault(x => x.Key.Number == e.number1).Key;

            AnswerOnReject?.Invoke(port1, e.message);
        }