Exemplo n.º 1
0
 public Responce(CallingRequest request, ResponceState state)
 {
     CallingRequest = request;
     State = state;
 }
        private void OnTerminalCalling(object sender, CallingRequest e)
        {
            var sourceTerminal = sender as ClientTerminal;
            if (sourceTerminal == null) return;

            var sourceClient = BillingSystem.Contracts.First(c => c.Terminal == sourceTerminal);
            var sourceTelephoneNumber = sourceClient.TelephoneNumber;
            var incommingRequest = new InCommingRequest(sourceTelephoneNumber);

            var clients = BillingSystem.Contracts.Where(c => c.TelephoneNumber == e.Target);
            // Target number doesn't exist
            if (!clients.Any())
            {
                sourceTerminal.ReceiveResponce(ResponceState.DoesNotExist);
                return;
            }

            var targetClient = clients.First();
            var session = new Session(sourceClient, targetClient, sourceClient.Rate);
            var systemTime = DateTime.Now;
            var currentTime = new DateTime(BillingSystem.CurrentTime.Year, BillingSystem.CurrentTime.Month, systemTime.Day, systemTime.Hour, systemTime.Minute, systemTime.Second);
            var connEvent = new ConnectionEvent(targetClient, ConnectionEventType.Accepted, currentTime);
            session.Events.Add(connEvent);

            var targetPort = _terminalToPertConnections.First(c => c.Terminal == targetClient.Terminal).Port;
            switch (targetPort.State)
            {
                case ConnectionState.Free:
                    {
                        sourceTerminal.ReceiveResponce(ResponceState.Calling);
                        CurrentSessions.Add(session);

                        targetClient.Terminal.IncomingRequestFrom(incommingRequest);
                        break;
                    }
                case ConnectionState.Busy:
                    {
                        sourceTerminal.ReceiveResponce(ResponceState.IsBusy);
                        BillingSystem.SessionHistory.Add(session);
                        break;
                    }
                case ConnectionState.UnConnected:
                    {
                        sourceTerminal.ReceiveResponce(ResponceState.UnConnected);
                        BillingSystem.SessionHistory.Add(session);
                        break;
                    }
            }
        }
Exemplo n.º 3
0
 private void OnCalling(CallingRequest request)
 {
     if (_calling != null)
     {
         _calling(this, request);
     }
 }
Exemplo n.º 4
0
 public void Call(TelephoneNumber number)
 {
     var request = new CallingRequest(number);
     OnCalling(request);
 }
Exemplo n.º 5
0
 private void OnTerminalCalling(object sender, CallingRequest e)
 {
     State = ConnectionState.Busy;
 }