Beispiel #1
0
 public void StartPing()
 {
     if (m_presenceInformer == null)
     {
         m_presenceInformer = new PresenceInformer(this);
         m_presenceInformer.StartPing();
     }
     else if (!m_presenceInformer.IsRunning())
         m_presenceInformer.StartPing();
 }
Beispiel #2
0
        public int Logout()
        {
            try
            {
                if (m_account != null)
                {
                    LogHelper.Debug("Try Log out");
                    //note these two threads below may call this logout, so after they are done, check m_account != null
                    if(m_connectXMPPThread != null)
                        m_connectXMPPThread.Join();
                    if (m_validateThread != null)
                        m_validateThread.Join();
                    if (m_presenceInformer != null)
                    {
                        m_presenceInformer.RequestStopPing();
                        m_presenceInformer.Vanish();
                        m_presenceInformer = null;
                    }
                    if (m_syncRequestHandler != null)
                    {
                        m_syncRequestHandler.StopSending();
                        m_syncRequestHandler.Vanish();
                        m_syncRequestHandler = null;
                    }
                    //should be disconnected after m_presenceInformer and m_syncRequestHandler stopped
                    if (m_xmppCH != null && m_xmppCH.IsOnline)
                    {
                        m_xmppCH.Disconnect();
                        m_xmppCH = null;
                    }
                    //set member variable that might be needed by other variables at last
                    if (m_account != null)
                    {
                        string token = m_account.Token;

                        m_account = null;
                        m_user = null;
                        m_isAuthorized = false;

                        //once m_isAuthorized is false, the account is offline
                        MessageBox.Show("Now offline!");

                        string[] paraName = new string[] { "user_id", "token", "client_version" };
                        string[] paraValue = new string[] { m_account.Id, token, ClientInfo.VERSION };
                        string xmlResponse = RestComm.SendRestRequest(RestComm.URL_ACCOUNT_LOGOUT, paraName, paraValue);

                        if (xmlResponse != null)
                        {
                            LogHelper.Debug("Log out successfully");
                            return (int)Status.SUCCESS;
                        }
                        else
                        {
                            MessageBox.Show("No account found or server's dead!");
                            LogHelper.Debug("Log out failure: No account found");
                            //m_account.Status = "Offline";
                            //m_user.Status = "Offline";
                            return (int)Status.FAILURE;
                        }
                    }
                }
                MessageBox.Show("Already offline!");
                LogHelper.Debug("Log out failure: Already offline");
                return (int)Status.FAILURE;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return (int)Status.EXCEPTION;
            }
        }