Exemplo n.º 1
0
 public void UnPlugTerminalEventHandler(object sender, IClientTerminal terminal)
 {
     if (sender is Port port)
     {
         MessageHandler?.Invoke(sender, $"Терминал {terminal.ClientNumberOfTelephone} отключен от порта {port.PortNumber}");
     }
 }
Exemplo n.º 2
0
 public ClientContract(string clientName, TelephoneNumber number, IClientTerminal terminal, IRate rate)
 {
     ClientName = clientName;
     TelephoneNumber = number;
     Terminal = terminal;
     Rate = rate;
 }
        public TerminalToPortConnection(IPort port, IClientTerminal terminal)
        {
            Port = port;
            Terminal = terminal;

            // handle terminal events
            Port.ConnectWithTerminal(Terminal);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            IStation    _Station    = new Station();
            ICompany    Company     = new Billing.Company_.Company("Белтелеком", _Station);
            ITariffPlan TarriffPlan = new TariffPlan();

            IPort           port1     = _Station.GetFreePort();
            IClientTerminal terminal1 = _Station.GetClientTerminal(111111);

            IClient Client1 = new Billing.Client_.Client("Вася", "Пупкин", "10.10.1990");

            Company.ClientHandler.Contracts.Add(new Contract(Company, Client1, DateTime.Now, TarriffPlan));
            Client1.AcceptClientTerminalAndPort(terminal1, port1, TarriffPlan);
            Client1.PlugClientTerminalInPort();

            IPort           port2     = _Station.GetFreePort();
            IClientTerminal terminal2 = _Station.GetClientTerminal(222222);

            IClient Client2 = new Billing.Client_.Client("Федя", "Тапкин", "11.11.1995");

            Company.ClientHandler.Contracts.Add(new Contract(Company, Client2, DateTime.Now, TarriffPlan));
            Client2.AcceptClientTerminalAndPort(terminal2, port2, TarriffPlan);
            Client2.PlugClientTerminalInPort();

            IPort           port3     = _Station.GetFreePort();
            IClientTerminal terminal3 = _Station.GetClientTerminal(333333);

            IClient Client3 = new Billing.Client_.Client("Афоня", "Сковородкин", "11.11.2000");

            Company.ClientHandler.Contracts.Add(new Contract(Company, Client3, DateTime.Now, TarriffPlan));
            Client3.AcceptClientTerminalAndPort(terminal3, port3, TarriffPlan);
            Client3.PlugClientTerminalInPort();



            Client1.ClientTerminal.OutgoingCall(222222);
            Thread.Sleep(5000);
            Client1.ClientTerminal.FinishConversation();

            Client1.ClientTerminal.OutgoingCall(333333);
            Thread.Sleep(7000);
            Client3.ClientTerminal.FinishConversation();


            Client2.ClientTerminal.OutgoingCall(111111);
            Thread.Sleep(10000);
            Client2.ClientTerminal.FinishConversation();


            Company.ClientHandler.GetDetailedСallReportForReportPeriod(Client1);
            Company.ClientHandler.GetDetailedСallReportByCallDate();
            Company.ClientHandler.GetDetailedСallReportByClient(Client1);
            Company.ClientHandler.GetDetailedСallReportByCallCost();

            Console.ReadKey();
        }
Exemplo n.º 5
0
 public void UnPlugTerminal(IClientTerminal terminal)
 {
     if (terminal != null)
     {
         terminal.CallEvent    -= OutgoingCallHandler;
         PortIncomingCallEvent -= terminal.IncomingCall;
         UnPlugTerminalEvent?.Invoke(this, terminal);
         Terminal = null;
     }
     else
     {
         throw new Exception("In Method UnPlugTerminal terminal is null");
     }
 }
Exemplo n.º 6
0
 public void PlugTerminal(IClientTerminal terminal)
 {
     if (terminal != null && Terminal == null)
     {
         Terminal               = terminal;
         terminal.CallEvent    += OutgoingCallHandler;
         PortIncomingCallEvent += terminal.IncomingCall;
         PlugTerminalEvent?.Invoke(this, terminal);
     }
     else
     {
         throw new Exception("In Method PlugTerminal terminal is null");
     }
 }
Exemplo n.º 7
0
        public void ConnectWithTerminal(IClientTerminal terminal)
        {
            ClearHandlers();

            _terminal = terminal;

            terminal.Connected += OnTerminalConnected;
            terminal.Disconnected += OnTerminalDisconnected;

            terminal.Calling += OnTerminalCalling;
            terminal.Droped += OnTerminalDropCall;
            terminal.Accepted += OnTerminalAcceptCall;
            terminal.RequestCome += OnTerminalReceiveRequest;
        }
Exemplo n.º 8
0
        public IClientTerminal GetClientTerminal(int ClientNumberOfTelephone)
        {
            IClientTerminal terminal = ClientTerminals.FirstOrDefault(x => x.ClientNumberOfTelephone == ClientNumberOfTelephone);

            if (terminal != null)
            {
                if (terminal.Rent == false)
                {
                    return(terminal);
                }
                else
                {
                    throw new Exception("Терминал с таким номером уже существует");
                }
            }
            else
            {
                IClientTerminal terminal1 = new ClientTerminal(ClientNumberOfTelephone, CallController);
                ClientTerminals.Add(terminal1);
                return(terminal1);
            }
        }
Exemplo n.º 9
0
        public void AcceptClientTerminalAndPort(IClientTerminal terminal, IPort port, ITariffPlan tariffPlan)
        {
            if (terminal.Rent != true)
            {
                terminal.Rent  = true;
                ClientTerminal = terminal;
                TariffPlan     = tariffPlan;
            }
            else
            {
                throw new Exception("Данный терминал уже выдан другому клиенту");
            }

            if (port.Rent != true)
            {
                port.Rent = true;
                Port      = port;
            }
            else
            {
                throw new Exception("Данный порт уже предоставлен другому клиенту");
            }
        }
Exemplo n.º 10
0
 protected void DisconnectWithTerminal(IClientTerminal terminal)
 {
     terminal.Calling -= OnTerminalCalling;
     terminal.Droped -= OnTerminalDropCall;
     terminal.Accepted -= OnTerminalAcceptCall;
 }
Exemplo n.º 11
0
        protected void ConnectWithTerminal(IClientTerminal terminal)
        {
            DisconnectWithTerminal(terminal);

            terminal.Calling += OnTerminalCalling;
            terminal.Droped += OnTerminalDropCall;
            terminal.Accepted += OnTerminalAcceptCall;
        }
Exemplo n.º 12
0
        protected void ConnectTerminalToPort(IClientTerminal terminal, IPort port)
        {
            var connection = new TerminalToPortConnection(port, terminal);
            _terminalToPertConnections.Add(connection);

            // add event handlers
            ConnectWithTerminal(terminal);
            ConnectWithPort(port);
        }
Exemplo n.º 13
0
        protected void ConnectTerminalToFreePort(IClientTerminal terminal)
        {
            if (_terminalToPertConnections.Any(c => c.Terminal == terminal)) return;

            // get free port
            var freePort = Ports.FirstOrDefault(p => _terminalToPertConnections.All(c => c.Port != p));
            if (freePort == null)
                // add new port, if there is no free one
                freePort = AddNewPort();

            ConnectTerminalToPort(terminal, freePort);
        }