public static CallConnected GetInstance()
 {
     if (_connectedObject == null)
     {
         _connectedObject = new CallConnected();
     }
     return(_connectedObject);
 }
예제 #2
0
        public void ReceiveCalls(IMessage events, TimeSpan?callDuration = null)
        {
            try
            {
                if (Settings.SFDCOptions.SFDCPopupPages != null)
                {
                    if (events != null)
                    {
                        try
                        {
                            this._logger.Info("ReceiveCalls: Voice Event Received : " + events.ToString());
                        }
                        catch
                        {
                            this._logger.Error("Error occurred while printing Voice Event in Log");
                        }
                        switch (events.Id)
                        {
                            #region EventRinging

                        case EventRinging.MessageId:
                            _eventRinging    = (EventRinging)events;
                            IsCallTransfered = false;
                            ConsultText      = string.Empty;
                            if (_eventRinging.UserData != null && _eventRinging.UserData.ContainsKey(Settings.SFDCOptions.ConsultAttachDataKey))
                            {
                                IsCallTransfered = true;
                                ConsultText      = _eventRinging.UserData.GetAsString(Settings.SFDCOptions.ConsultAttachDataKey);
                                this._logger.Info("EventRinging : Consult Attach data key found for the ConnId :" + _eventRinging.ConnID.ToString() + " value : " + ConsultText);
                            }

                            if (_eventRinging.CallType == CallType.Inbound)
                            {
                                if (!IsCallTransfered)
                                {
                                    _isConsultCallReceived = false;
                                    CallRinging.GetInstance().PopupRecords(_eventRinging, SFDCCallType.InboundVoice);
                                }
                                else
                                {
                                    _isConsultCallReceived = true;
                                    this._consultConnId    = _eventRinging.ConnID.ToString();
                                    CallRinging.GetInstance().PopupRecords(_eventRinging, SFDCCallType.ConsultVoiceReceived);
                                }
                            }
                            else if (_eventRinging.CallType == CallType.Consult)
                            {
                                _isConsultCallReceived = true;
                                CallRinging.GetInstance().PopupRecords(_eventRinging, SFDCCallType.ConsultVoiceReceived);
                            }
                            else if (_eventRinging.CallType == CallType.Outbound)
                            {
                                if (IsCallTransfered)
                                {
                                    _isConsultCallReceived = true;
                                    this._consultConnId    = _eventRinging.ConnID.ToString();
                                    CallRinging.GetInstance().PopupRecords(_eventRinging, SFDCCallType.ConsultVoiceReceived);
                                }
                            }
                            break;

                            #endregion EventRinging

                            #region EventPartyChanged

                        case EventPartyChanged.MessageId:
                            EventPartyChanged partyChanged = (EventPartyChanged)events;
                            _isConsultCallReceived = true;
                            if (_callDurationData.ContainsKey(partyChanged.PreviousConnID.ToString()) && !_callDurationData.ContainsKey(partyChanged.ConnID.ToString()))
                            {
                                _callDurationData.Add(partyChanged.ConnID.ToString(), _callDurationData[partyChanged.PreviousConnID.ToString()]);
                            }
                            if (Settings.UpdateSFDCLog.ContainsKey(partyChanged.PreviousConnID.ToString()))
                            {
                                if (!Settings.UpdateSFDCLog.ContainsKey(partyChanged.ConnID.ToString()))
                                {
                                    Settings.UpdateSFDCLog.Add(partyChanged.ConnID.ToString(), Settings.UpdateSFDCLog[partyChanged.PreviousConnID.ToString()]);
                                }
                                else
                                {
                                    Settings.UpdateSFDCLog[partyChanged.ConnID.ToString()] = Settings.UpdateSFDCLog[partyChanged.PreviousConnID.ToString()];
                                }
                            }
                            this._consultConnId = partyChanged.ConnID.ToString();

                            if (partyChanged.UserData != null && partyChanged.UserData.ContainsKey(Settings.SFDCOptions.ConsultAttachDataKey))
                            {
                                IsCallTransfered = true;
                                ConsultText      = partyChanged.UserData.GetAsString(Settings.SFDCOptions.ConsultAttachDataKey);
                                this._logger.Info("PartyChanged : Consult Attach data key found for the ConnId :" + partyChanged.ConnID.ToString() + " value : " + ConsultText);
                            }

                            string duration = "0 Hr 0 Mins 0 Secs";
                            if (_callDurationData.ContainsKey(partyChanged.ConnID.ToString()))
                            {
                                TimeSpan ts = System.DateTime.Now.Subtract(_callDurationData[partyChanged.ConnID.ToString()]);
                                duration = ts.Hours + " Hr " + ts.Minutes + " Mins " + ts.Seconds + " Secs";
                            }
                            CallPartyChanged.GetInstance().PopupRecords(partyChanged, SFDCCallType.ConsultVoiceReceived, duration);
                            break;

                            #endregion EventPartyChanged

                            #region EventDialing

                        case EventDialing.MessageId:
                            _eventDialing = (EventDialing)events;
                            if (Settings.SFDCListener.Click2EmailData.ContainsKey("ClickToDial"))
                            {
                                //Settings.ClickToDialData.Add(_eventDialing.ConnID.ToString(), _eventDialing.Reasons.GetAsString("ClickToDial"));
                                Settings.ClickToDialData.Add(_eventDialing.ConnID.ToString(), Settings.SFDCListener.Click2EmailData["ClickToDial"]);
                                Settings.SFDCListener.Click2EmailData.Clear();
                            }
                            if (_eventDialing.CallType == CallType.Unknown || _eventDialing.CallType == CallType.Outbound)
                            {
                                CallDialing.GetInstance().PopupRecords(_eventDialing, SFDCCallType.OutboundVoiceSuccess);
                            }

                            break;

                            #endregion EventDialing

                            #region EventEstablished

                        case EventEstablished.MessageId:

                            eventEstablished = (EventEstablished)events;
                            if (!_callDurationData.ContainsKey(eventEstablished.ConnID.ToString()))
                            {
                                _callDurationData.Add(eventEstablished.ConnID.ToString(), System.DateTime.Now);
                            }
                            if (eventEstablished.CallType == CallType.Inbound)
                            {
                                if (_isConsultCallReceived)
                                {
                                    CallConnected.GetInstance().PopupRecords(eventEstablished, SFDCCallType.ConsultVoiceReceived);
                                }
                                else
                                {
                                    CallConnected.GetInstance().PopupRecords(eventEstablished, SFDCCallType.InboundVoice);
                                }
                            }
                            else if (eventEstablished.CallType == CallType.Unknown || eventEstablished.CallType == CallType.Outbound)
                            {
                                if (_isConsultCallReceived)
                                {
                                    CallConnected.GetInstance().PopupRecords(eventEstablished, SFDCCallType.ConsultVoiceReceived);
                                }
                                else
                                {
                                    CallConnected.GetInstance().PopupRecords(eventEstablished, SFDCCallType.OutboundVoiceSuccess);
                                }
                            }
                            else if (eventEstablished.CallType == CallType.Consult)
                            {
                                if (_isConsultCallReceived)
                                {
                                    CallConnected.GetInstance().PopupRecords(eventEstablished, SFDCCallType.ConsultVoiceReceived);
                                }
                            }
                            break;

                            #endregion EventEstablished

                            #region EventReleased

                        case EventReleased.MessageId:

                            _eventReleased = (EventReleased)events;
                            this._logger.Info("Event Release Call State: " + _eventReleased.CallState.ToString());
                            if (_eventReleased.CallState != 22)
                            {
                                if (Settings.SFDCOptions.CanUseGenesysCallDuration && callDuration != null)
                                {
                                    _callDuration = callDuration.Value.Hours + " Hr " + callDuration.Value.Minutes + " Mins " + callDuration.Value.Seconds + " Secs";;
                                    this._logger.Info("ConnectionId : " + _eventReleased.ConnID.ToString() + " Call duration is " + _callDuration);
                                }
                                else if (_callDurationData.ContainsKey(_eventReleased.ConnID.ToString()))
                                {
                                    TimeSpan ts = System.DateTime.Now.Subtract(_callDurationData[_eventReleased.ConnID.ToString()]);
                                    _callDuration = ts.Hours + " Hr " + ts.Minutes + " Mins " + ts.Seconds + " Secs";
                                    this._logger.Info("ConnectionId : " + _eventReleased.ConnID.ToString() + " Call duration is " + _callDuration);

                                    if (!FinishedCallDuration.ContainsKey(_eventReleased.ConnID.ToString()))
                                    {
                                        FinishedCallDuration.Add(_eventReleased.ConnID.ToString(), _callDuration);
                                    }
                                    else
                                    {
                                        FinishedCallDuration[_eventReleased.ConnID.ToString()] = _callDuration;
                                    }
                                }
                                else
                                {
                                    _callDuration = "0 Hr 0 Mins 0 Secs";
                                    this._logger.Info("Call duration not found for the connection Id : " + _eventReleased.ConnID.ToString());
                                }
                                HandleReleaseEvent(_eventReleased, _callDuration);
                            }
                            else
                            {
                                this._logger.Info("The call has been rejected for the connectionId : " + _eventReleased.ConnID.ToString());
                                HandleCallRejected(_eventReleased, "0 Hr 0 Mins 0 Secs");
                            }

                            break;

                            #endregion EventReleased

                            #region EventError

                        case EventError.MessageId:
                            EventError eventError = (EventError)events;
                            this._logger.Info("EventError occurred for the connectionId : " + eventError.ConnID.ToString());
                            if (eventError.CallType == CallType.Outbound)
                            {
                                CallEventError.GetInstance().PopupRecords(eventError, SFDCCallType.OutboundVoiceFailure);
                            }

                            break;

                            #endregion EventError

                            #region EventAbandoned

                        case EventAbandoned.MessageId:
                            EventAbandoned eventAbandoned = (EventAbandoned)events;
                            this._logger.Info("EventAbandoned occurred for the connectionId : " + eventAbandoned.ConnID.ToString());
                            if (eventAbandoned.CallType == CallType.Outbound)
                            {
                                CallEventAbandoned.GetInstance().PopupRecords(eventAbandoned, SFDCCallType.OutboundVoiceFailure);
                            }

                            break;

                            #endregion EventAbandoned

                            #region EventDestinationBusy

                        case EventDestinationBusy.MessageId:
                            EventDestinationBusy destinationBusyEvent = (EventDestinationBusy)events;
                            this._logger.Info("EventDestinationBusy occurred for the connectionId : " + destinationBusyEvent.ConnID.ToString());
                            if (destinationBusyEvent.CallType == CallType.Outbound)
                            {
                                CallEventDestinationBusy.GetInstance().PopupRecords(destinationBusyEvent, SFDCCallType.OutboundVoiceFailure);
                            }

                            break;

                            #endregion EventDestinationBusy

                        default:
                            _logger.Info("ReceiveCalls: Unhandled Event " + events.Name);
                            break;
                        }
                    }
                }
            }
            catch (Exception generalException)
            {
                _logger.Error("ReceiveCalls: Error occurred while receiving voice events " + generalException.ToString());
            }
        }
        public void ReceiveCalls(IMessage events)
        {
            try
            {
                if (Settings.SFDCOptions.SFDCPopupPages != null)
                {
                    if (events != null)
                    {
                        logger.Info("ReceiveCalls : Agent Voice Event " + events.ToString());
                        switch (events.Id)
                        {
                            #region EventRinging
                        case EventRinging.MessageId:
                            eventRinging = (EventRinging)events;

                            if (eventRinging.CallType == CallType.Inbound)
                            {
                                IsConsultCallReceived = false;
                                CallRinging.GetInstance().PopupRecords(eventRinging, SFDCCallType.Inbound);
                                if (!Settings.UserEventData.ContainsKey(eventRinging.ConnID.ToString()))
                                {
                                    Settings.UserEventData.Add(eventRinging.ConnID.ToString(), SFDCCallType.Inbound);
                                }
                            }
                            else if (eventRinging.CallType == CallType.Consult)
                            {
                                IsConsultCallReceived = true;
                                CallRinging.GetInstance().PopupRecords(eventRinging, SFDCCallType.ConsultReceived);
                                if (!Settings.UserEventData.ContainsKey(eventRinging.ConnID.ToString()))
                                {
                                    Settings.UserEventData.Add(eventRinging.ConnID.ToString(), SFDCCallType.ConsultReceived);
                                }
                            }
                            break;
                            #endregion

                            #region EventPartyChanged
                        case EventPartyChanged.MessageId:
                            EventPartyChanged partyChanged = (EventPartyChanged)events;
                            IsConsultCallReceived = true;
                            if (CallDurationData.ContainsKey(partyChanged.PreviousConnID.ToString()) && !CallDurationData.ContainsKey(partyChanged.ConnID.ToString()))
                            {
                                CallDurationData.Add(partyChanged.ConnID.ToString(), CallDurationData[partyChanged.PreviousConnID.ToString()]);
                            }
                            if (Settings.UpdateSFDCLog.ContainsKey(partyChanged.PreviousConnID.ToString()))
                            {
                                Settings.UpdateSFDCLog.Add(partyChanged.ConnID.ToString(), Settings.UpdateSFDCLog[partyChanged.PreviousConnID.ToString()]);
                            }
                            this.consultConnId = partyChanged.PreviousConnID.ToString();
                            break;
                            #endregion

                            #region EventDialing
                        case EventDialing.MessageId:
                            eventDialing = (EventDialing)events;

                            if (eventDialing.Reasons != null && eventDialing.Reasons.ContainsKey("ClickToDial"))
                            {
                                Settings.ClickToDialData.Add(eventDialing.ConnID.ToString(), eventDialing.Reasons.GetAsString("ClickToDial"));
                            }
                            if (eventDialing.CallType == CallType.Unknown || eventDialing.CallType == CallType.Outbound)
                            {
                                CallDialing.GetInstance().PopupRecords(eventDialing, SFDCCallType.OutboundSuccess);

                                if (!Settings.UserEventData.ContainsKey(eventDialing.ConnID.ToString()))
                                {
                                    Settings.UserEventData.Add(eventDialing.ConnID.ToString(), SFDCCallType.OutboundSuccess);
                                }
                            }
                            else if (eventDialing.CallType == CallType.Consult)
                            {
                                CallDialing.GetInstance().PopupRecords(eventDialing, SFDCCallType.ConsultSuccess);

                                if (!Settings.UserEventData.ContainsKey(eventDialing.ConnID.ToString()))
                                {
                                    Settings.UserEventData.Add(eventDialing.ConnID.ToString(), SFDCCallType.ConsultSuccess);
                                }
                            }
                            break;
                            #endregion

                            #region EventEstablished
                        case EventEstablished.MessageId:

                            eventEstablished = (EventEstablished)events;

                            if (!CallDurationData.ContainsKey(eventEstablished.ConnID.ToString()))
                            {
                                CallDurationData.Add(eventEstablished.ConnID.ToString(), System.DateTime.Now);
                            }
                            if (eventEstablished.CallType == CallType.Inbound)
                            {
                                if (IsConsultCallReceived)
                                {
                                    CallConnected.GetInstance().PopupRecords(eventEstablished, SFDCCallType.ConsultReceived);
                                }
                                else
                                {
                                    CallConnected.GetInstance().PopupRecords(eventEstablished, SFDCCallType.Inbound);
                                }
                            }
                            else if (eventEstablished.CallType == CallType.Unknown || eventEstablished.CallType == CallType.Outbound)
                            {
                                if (IsConsultCallReceived)
                                {
                                    CallConnected.GetInstance().PopupRecords(eventEstablished, SFDCCallType.ConsultReceived);
                                }
                                else
                                {
                                    CallConnected.GetInstance().PopupRecords(eventEstablished, SFDCCallType.OutboundSuccess);
                                }
                            }
                            else if (eventEstablished.CallType == CallType.Consult)
                            {
                                if (IsConsultCallReceived)
                                {
                                    CallConnected.GetInstance().PopupRecords(eventEstablished, SFDCCallType.ConsultReceived);
                                }
                                else
                                {
                                    CallConnected.GetInstance().PopupRecords(eventEstablished, SFDCCallType.ConsultSuccess);
                                }
                            }


                            break;
                            #endregion

                            #region EventReleased
                        case EventReleased.MessageId:

                            eventReleased = (EventReleased)events;

                            if (eventReleased.CallState != 22)
                            {
                                string callDuration = string.Empty;
                                if (CallDurationData.ContainsKey(eventReleased.ConnID.ToString()))
                                {
                                    TimeSpan ts = System.DateTime.Now.Subtract(CallDurationData[eventReleased.ConnID.ToString()]);
                                    callDuration = ts.Hours + "Hr " + ts.Minutes + " mins " + ts.Seconds + "secs";
                                    if (!FinishedCallDuration.ContainsKey(eventReleased.ConnID.ToString()))
                                    {
                                        FinishedCallDuration.Add(eventReleased.ConnID.ToString(), callDuration);
                                    }
                                    else
                                    {
                                        FinishedCallDuration[eventReleased.ConnID.ToString()] = callDuration;
                                    }
                                }
                                if (eventReleased.CallType == CallType.Inbound)
                                {
                                    if (!IsConsultCallReceived)
                                    {
                                        CallReleased.GetInstance().PopupRecords(eventReleased, SFDCCallType.Inbound, callDuration);
                                    }
                                    else
                                    {
                                        IsConsultCallReceived = false;
                                        CallReleased.GetInstance().PopupRecords(eventReleased, SFDCCallType.ConsultReceived, callDuration);
                                    }
                                }
                                else if (eventReleased.CallType == CallType.Unknown || eventReleased.CallType == CallType.Outbound)
                                {
                                    if (IsConsultCallReceived)
                                    {
                                        CallReleased.GetInstance().PopupRecords(eventReleased, SFDCCallType.ConsultReceived, callDuration);
                                        IsConsultCallReceived = false;
                                    }
                                    else
                                    {
                                        CallReleased.GetInstance().PopupRecords(eventReleased, SFDCCallType.OutboundSuccess, callDuration);
                                    }
                                }
                                else if (eventReleased.CallType == CallType.Consult)
                                {
                                    if (IsConsultCallReceived)
                                    {
                                        CallReleased.GetInstance().PopupRecords(eventReleased, SFDCCallType.ConsultReceived, callDuration);
                                        IsConsultCallReceived = false;
                                    }
                                    else
                                    {
                                        CallReleased.GetInstance().PopupRecords(eventReleased, SFDCCallType.ConsultSuccess, callDuration);
                                    }
                                }
                            }

                            break;
                            #endregion

                            #region EventUserEvent
                        case EventUserEvent.MessageId:
                            EventUserEvent userEvent = (EventUserEvent)events;

                            if (userEvent.ConnID != null)
                            {
                                if (Settings.UserEventData.ContainsKey(userEvent.ConnID.ToString()))
                                {
                                    if (FinishedCallDuration.ContainsKey(userEvent.ConnID.ToString()))
                                    {
                                        CallUserEvent.GetInstance().UpdateRecords(userEvent, Settings.UserEventData[userEvent.ConnID.ToString()], FinishedCallDuration[userEvent.ConnID.ToString()]);
                                    }
                                    else
                                    {
                                        CallUserEvent.GetInstance().UpdateRecords(userEvent, Settings.UserEventData[userEvent.ConnID.ToString()], "");
                                    }
                                }
                            }

                            break;
                            #endregion

                            #region EventError
                        case EventError.MessageId:
                            EventError eventError = (EventError)events;
                            if (eventError.CallType == CallType.Outbound)
                            {
                                CallEventError.GetInstance().PopupRecords(eventError, SFDCCallType.OutboundFailure);
                            }
                            else if (eventError.CallType == CallType.Consult)
                            {
                                CallEventError.GetInstance().PopupRecords(eventError, SFDCCallType.ConsultFailure);
                            }
                            break;
                            #endregion

                            #region EventAbandoned
                        case EventAbandoned.MessageId:
                            EventAbandoned eventAbandoned = (EventAbandoned)events;
                            if (eventAbandoned.CallType == CallType.Outbound)
                            {
                                CallEventAbandoned.GetInstance().PopupRecords(eventAbandoned, SFDCCallType.OutboundFailure);
                            }
                            else if (eventAbandoned.CallType == CallType.Consult)
                            {
                                CallEventAbandoned.GetInstance().PopupRecords(eventAbandoned, SFDCCallType.ConsultFailure);
                            }
                            break;
                            #endregion

                            #region EventDestinationBusy
                        case EventDestinationBusy.MessageId:

                            EventDestinationBusy destinationBusyEvent = (EventDestinationBusy)events;
                            if (destinationBusyEvent.CallType == CallType.Outbound)
                            {
                                CallEventDestinationBusy.GetInstance().PopupRecords(destinationBusyEvent, SFDCCallType.OutboundFailure);
                            }
                            else if (destinationBusyEvent.CallType == CallType.Consult)
                            {
                                CallEventDestinationBusy.GetInstance().PopupRecords(destinationBusyEvent, SFDCCallType.ConsultFailure);
                            }
                            break;
                            #endregion

                        default:
                            logger.Info("ReceiveCalls : Unhandled Event " + events.Name);
                            break;
                        }
                    }
                }
            }
            catch (Exception generalException)
            {
                logger.Error("ReceiveCalls : Error occured while receiving voice events " + generalException.ToString());
            }
        }