Ejemplo n.º 1
0
        private void OnOutgoingCall(object sender, IPhoneNumber phone)
        {
            var answerer = _terminalService.FindTerminalByNumber(phone);
            var caller   = sender as Terminal;

            if (answerer != null && caller != null)
            {
                caller.RememberConnection(caller.Number, phone);
                _portService.ChangeState(caller.Port, PortState.Busy);
                CallInfo info = new CallInfo
                {
                    From          = caller.Number,
                    To            = phone,
                    DateTimeStart = DateTime.Now,
                    Duration      = TimeSpan.Zero
                };
                _callService.AddCall(info);

                if (answerer.Port.State != PortState.Busy)
                {
                    answerer.GetCall(caller.Number);
                }
                else
                {
                    Console.WriteLine($"Terminal is busy");
                    caller.RejectCall();
                }
            }
            else
            {
                Console.WriteLine($"Phone not binded to terminal");
                caller.RejectCall();
            }
        }