예제 #1
0
 public void CallingTo(object sender, IEventArgsCalling e)
 {
     if (_usersData.ContainsKey(e.TargetTelephoneNumber) && e.TargetTelephoneNumber != e.TelephoneNumber ||
         e is EventArgsEndCall)
     {
         IPort targetPort;
         IPort port;
         if (e is EventArgsEndCall)
         {
             var callListFirst = _callInfo;
             if (callListFirst.CallerNumber == e.TelephoneNumber)
             {
                 targetPort = _usersData[callListFirst.TargetNumber];
                 port       = _usersData[callListFirst.CallerNumber];
             }
             else
             {
                 port       = _usersData[callListFirst.TargetNumber];
                 targetPort = _usersData[callListFirst.CallerNumber];
             }
         }
         else
         {
             targetPort = _usersData[e.TargetTelephoneNumber];
             port       = _usersData[e.TelephoneNumber];
         }
         if (targetPort.PortState == PortState.Connected && port.PortState == PortState.Connected)
         {
             CallInfo inf;
             if (e is EventArgsAnswer)
             {
                 var answerArgs = (EventArgsAnswer)e;
                 targetPort.AnswerCall(answerArgs.TelephoneNumber, answerArgs.TargetTelephoneNumber, answerArgs.StateInCall);
             }
             if (e is EventArgsCall)
             {
                 var callArgs = (EventArgsCall)e;
                 inf = new CallInfo(
                     callArgs.TelephoneNumber,
                     callArgs.TargetTelephoneNumber,
                     DateTime.Now, DateTime.Now, DateTime.Now);
                 _callInfo = inf;
                 targetPort.IncomingCall(callArgs.TelephoneNumber, callArgs.TargetTelephoneNumber);
             }
             if (e is EventArgsEndCall)
             {
                 var args = (EventArgsEndCall)e;
                 inf             = _callInfo;
                 inf.TimeEndCall = DateTime.Now;
                 targetPort.AnswerCall(args.TelephoneNumber, args.TargetTelephoneNumber, CallState.Rejected);
                 SentDataEvent?.Invoke(new Billing.BL.Classes.CallInfo(GetInfoList().CallerNumber, GetInfoList().TargetNumber
                                                                       , GetInfoList().Date, GetInfoList().TimeStartCall, GetInfoList().TimeEndCall));
             }
         }
         else
         {
             _help.GetMessageAboutCallToDisconnectTerminal(e.TargetTelephoneNumber);
         }
     }
     else if (!_usersData.ContainsKey(e.TargetTelephoneNumber))
     {
         _help.GetMessageAboutNonexistentNumber(e.TargetTelephoneNumber);
     }
 }
예제 #2
0
        public void Calling(object sender, IEventArgsCalling e)
        {
            if (usersData.ContainsKey(e.TargetNumber) &&
                e.TargetNumber != e.Number ||
                e is EventArgsEndCall)
            {
                IPort targetPort;
                IPort port;

                if (e is EventArgsEndCall)
                {
                    var callListFirst = callInfo;

                    if (callListFirst.CallerNumber == e.Number)
                    {
                        targetPort = usersData[callListFirst.TargetNumber];
                        port       = usersData[callListFirst.CallerNumber];
                    }
                    else
                    {
                        port       = usersData[callListFirst.TargetNumber];
                        targetPort = usersData[callListFirst.CallerNumber];
                    }
                }
                else
                {
                    targetPort = usersData[e.TargetNumber];
                    port       = usersData[e.Number];
                }

                if (targetPort.PortState == PortState.Connected && port.PortState == PortState.Connected)
                {
                    CallInfo info;

                    if (e is EventArgsAnswer)
                    {
                        info = callInfo;
                        var answerArgs = (EventArgsAnswer)e;

                        targetPort.AnswerCall(answerArgs.Number, answerArgs.TargetNumber, answerArgs.CurrentState);

                        Thread.Sleep(4000);
                        info.TimeEndCall = DateTime.Now;
                        GetCallTime();
                    }

                    if (e is EventArgsCall)
                    {
                        Terminal term     = new Terminal();
                        var      callArgs = (EventArgsCall)e;
                        info     = new CallInfo(callArgs.Number, callArgs.TargetNumber, DateTime.Now, DateTime.Now);
                        callInfo = info;
                        targetPort.IncomingCall(callArgs.Number, callArgs.TargetNumber);
                    }

                    if (e is EventArgsEndCall)
                    {
                        var endArgs = (EventArgsEndCall)e;
                        info = callInfo;

                        RespondState state = endArgs.CurrentState;

                        if (state == RespondState.Ending)
                        {
                            targetPort.AnswerCall(endArgs.Number, endArgs.TargetNumber, RespondState.Ending);
                        }

                        else if (state == RespondState.Decline)
                        {
                            targetPort.AnswerCall(endArgs.Number, endArgs.TargetNumber, RespondState.Decline);
                            GetCallTime();
                        }
                        SentDataEvent?.Invoke(new BillingCallInfo(GetInfoList().CallerNumber, GetInfoList().TargetNumber
                                                                  , GetInfoList().TimeStartCall, GetInfoList().TimeEndCall));
                    }
                }
                else
                {
                    interaction.CallingToDisconnectedTerminalMessage(e.TargetNumber);
                }
            }
            else if (!usersData.ContainsKey(e.TargetNumber))
            {
                interaction.CallingToNonExictentNumberMessage(e.TargetNumber);
            }
        }