public static EmailCreate GetInstance()
 {
     if (_emailCreate == null)
     {
         _emailCreate = new EmailCreate();
     }
     return(_emailCreate);
 }
        public void ReceiveEmailEvents(IMessage events)
        {
            try
            {
                if ((Settings.SFDCOptions.SFDCPopupPages != null) && (events != null))
                {
                    this._logger.Info("Agent Email Event : " + events.Name);
                    switch (events.Id)
                    {
                    case EventInvite.MessageId:
                        this._eventInvite           = (EventInvite)events;
                        Settings.EmailProxyClientId = _eventInvite.ProxyClientId;
                        IXNCustomData emailInviteData = new IXNCustomData();
                        emailInviteData.InteractionId        = this._eventInvite.Interaction.InteractionId;
                        emailInviteData.OpenMediaInteraction = this._eventInvite.Interaction;
                        emailInviteData.UserData             = this._eventInvite.Interaction.InteractionUserData;
                        GetEmailData(emailInviteData.InteractionId, emailInviteData);
                        EmailInvite.GetInstance().PopupRecords(emailInviteData, emailInviteData.InteractionType);

                        if ((this._eventInvite.VisibilityMode.ToString() != "Coach") && (this._eventInvite.VisibilityMode.ToString() != "Conference"))
                        {
                        }

                        break;

                    case EventPulledInteractions.MessageId:
                        this._eventPulledInteractions = (EventPulledInteractions)events;
                        if (this._eventPulledInteractions.Interactions.Count == 1)
                        {
                            string             str             = this._eventPulledInteractions.Interactions.AllKeys.GetValue(0).ToString();
                            object[]           kvc             = this._eventPulledInteractions.Interactions.GetValues(str);
                            KeyValueCollection collection      = (KeyValueCollection)kvc[0];
                            IXNCustomData      emailPulledData = new IXNCustomData();
                            emailPulledData.InteractionId = collection["InteractionId"].ToString();
                            GetEmailData(emailPulledData.InteractionId, emailPulledData);
                            if (emailPulledData.IXN_Attributes.TypeId == "Inbound")
                            {
                                emailPulledData.InteractionType = SFDCCallType.InboundEmailPulled;
                            }
                            else if (emailPulledData.IXN_Attributes.TypeId == "Outbound")
                            {
                                emailPulledData.InteractionType = SFDCCallType.OutboundEmailPulled;
                            }
                            EmailPulled.GetInstance().PopupRecords(emailPulledData, emailPulledData.InteractionType);
                        }
                        break;

                    case EventAck.MessageId:
                        this._eventAck = (EventAck)events;
                        if (_eventAck.Extension != null && _eventAck.Extension.ContainsKey("InteractionId") && _eventAck.Extension["InteractionId"] != null)
                        {
                            string type = GetEmailInteractionContent(_eventAck.Extension["InteractionId"].ToString(), "type");
                            if (type.Equals("OutboundNew"))
                            {
                                string ToAddress = GetEmailInteractionContent(_eventAck.Extension["InteractionId"].ToString(), "to");
                                if (!String.IsNullOrEmpty(ToAddress))
                                {
                                    IXNCustomData emailAckData = new IXNCustomData();
                                    emailAckData.InteractionType = SFDCCallType.OutboundEmailSuccess;
                                    emailAckData.InteractionId   = _eventAck.Extension["InteractionId"].ToString();
                                    GetEmailData(emailAckData.InteractionId, emailAckData);
                                    if (IsClick2Email && SFDCHttpServer._emailData.ContainsKey(ToAddress))
                                    {
                                        Settings.ClickToEmailData.Add(_eventAck.Extension["InteractionId"].ToString(), SFDCHttpServer._emailData[ToAddress]);
                                        EmailManager.GetInstance().GetClickToEmailLogs(emailAckData, _eventAck.Extension["InteractionId"].ToString(), SFDCCallType.OutboundEmailSuccess, SFDCHttpServer._emailData[ToAddress], "create");
                                        IsClick2Email = false;
                                    }
                                    else
                                    {
                                        EmailCreate.GetInstance().PopupRecords(emailAckData, SFDCCallType.OutboundEmailSuccess);
                                    }
                                }
                                else
                                {
                                    this._logger.Warn("ReceiveEmailEvents : ToAddress is not found in EventAck");
                                }
                            }
                            else if (type.Equals("OutboundReply"))
                            {
                                string ToAddress = GetEmailInteractionContent(_eventAck.Extension["InteractionId"].ToString(), "to");
                                if (!String.IsNullOrEmpty(ToAddress))
                                {
                                    IXNCustomData outEmailData = new IXNCustomData();
                                    outEmailData.InteractionType = SFDCCallType.OutboundEmailSuccess;
                                    outEmailData.InteractionId   = _eventAck.Extension["InteractionId"].ToString();
                                    GetEmailData(outEmailData.InteractionId, outEmailData);
                                    if (IsClick2Email && SFDCHttpServer._emailData.ContainsKey(ToAddress))
                                    {
                                        Settings.ClickToEmailData.Add(_eventAck.Extension["InteractionId"].ToString(), SFDCHttpServer._emailData[ToAddress]);
                                        EmailManager.GetInstance().GetClickToEmailLogs(outEmailData, _eventAck.Extension["InteractionId"].ToString(), SFDCCallType.OutboundEmailSuccess, SFDCHttpServer._emailData[ToAddress], "create");
                                        IsClick2Email = false;
                                    }
                                    else
                                    {
                                        EmailCreate.GetInstance().PopupRecords(outEmailData, SFDCCallType.OutboundEmailSuccess);
                                    }
                                }
                                else
                                {
                                    this._logger.Warn("ReceiveEmailEvents : ToAddress is not found in EventAck");
                                }
                            }
                        }
                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                this._logger.Error("ReceiveEmailEvents : Error occured while receiving Email events " + exception.ToString());
            }
        }