Ejemplo n.º 1
0
	    public void Destroy()
	    {
		    m_NetRequest.cancel();
		
	        stop(WAIT_BEFOREKILL_SECONDS);
	        m_pInstance = null;
	    }
Ejemplo n.º 2
0
        public void Destroy()
        {
            m_NetRequest.cancel();

            stop(WAIT_BEFOREKILL_SECONDS);
            m_pInstance = null;
        }
Ejemplo n.º 3
0
	    public static ClientRegister Create(String device_pin)
	    {
	        if ( m_pInstance != null) 
	            return m_pInstance;
	
	        m_pInstance = new ClientRegister(device_pin);
	        return m_pInstance;
	    }
Ejemplo n.º 4
0
        public static ClientRegister Create(String device_pin)
        {
            if (m_pInstance != null)
            {
                return(m_pInstance);
            }

            m_pInstance = new ClientRegister(device_pin);
            return(m_pInstance);
        }
Ejemplo n.º 5
0
        public void Destroy()
        {
            m_oSyncEngine.exitSync();
            stop(SYNC_WAIT_BEFOREKILL_SECONDS);

            if (ClientRegister.getInstance() != null)
            {
                ClientRegister.getInstance().Destroy();
            }

            DBAdapter.closeAll();

            m_pInstance = null;
        }
Ejemplo n.º 6
0
        public String loadClientID()
        {
            String clientID = "";

            lock ( m_mxLoadClientID )
            {
                boolean bResetClient = false;
                {
                    IDBResult res = getUserDB().executeSQL("SELECT client_id,reset from client_info");
                    if (!res.isEnd())
                    {
                        clientID     = res.getStringByIdx(0);
                        bResetClient = res.getIntByIdx(1) > 0;
                    }
                }

                if (clientID.length() == 0)
                {
                    clientID = requestClientIDByNet();

                    IDBResult res = getUserDB().executeSQL("SELECT * FROM client_info");
                    if (!res.isEnd())
                    {
                        getUserDB().executeSQL("UPDATE client_info SET client_id=?", clientID);
                    }
                    else
                    {
                        getUserDB().executeSQL("INSERT INTO client_info (client_id) values (?)", clientID);
                    }

                    if (ClientRegister.getInstance() != null)
                    {
                        ClientRegister.getInstance().startUp();
                    }
                }
                else if (bResetClient)
                {
                    if (!resetClientIDByNet(clientID))
                    {
                        stopSync();
                    }
                    else
                    {
                        getUserDB().executeSQL("UPDATE client_info SET reset=? where client_id=?", 0, clientID);
                    }
                }
            }

            return(clientID);
        }
Ejemplo n.º 7
0
        public void login(String name, String password, SyncNotify.SyncNotification oNotify)
        {
            try {
                /*
                 *                      processServerSources("{\"sources\":{ \"ProductEx\":{ "+
                 *              "\"sync_type\":\"incremental\", \"partition\":\"application\", \"source_id\":\"7\","+
                 *              " \"sync_priority\":\"0\", \"model_type\":\"fixed_schema\", "+
                 *              " \"schema\":{\"version\":\"1.1\", \"property\":{\"brand\":\"string\", \"price\":\"string\", \"quantity\":\"string\", \"name\":\"string\", "+
                 *              " \"image_url\":\"blob\", \"image_url_ex\":\"blob,overwrite\"}, "+
                 *              " \"index\":[{\"by_brand_price1\":\"brand,price\"}, {\"by_quantity1\":\"quantity\"}], \"unique_index\":[{\"by_name1\":\"name\"}]}, "+
                 *              " \"belongs_to\":{\"brand\":\"Customer\"}}}}");//, \"schema_version\":\"1.0\"
                 */
                NetResponse resp = null;
                m_bStopByUser = false;

                try{
                    resp = getNet().pullCookies(getProtocol().getLoginUrl(), getProtocol().getLoginBody(name, password), this);
                    int nErrCode = RhoAppAdapter.getErrorFromResponse(resp);
                    if (nErrCode != RhoAppAdapter.ERR_NONE)
                    {
                        getNotify().callLoginCallback(oNotify, nErrCode, resp.getCharData());
                        return;
                    }
                }catch (Exception exc)
                {
                    LOG.ERROR("Login failed.", exc);
                    getNotify().callLoginCallback(oNotify, RhoAppAdapter.getNetErrorCode(exc), "");
                    return;
                }

                String strSession = resp.getCharData();
                if (strSession == null || strSession.length() == 0)
                {
                    LOG.ERROR("Return empty session.");
                    getNotify().callLoginCallback(oNotify, RhoAppAdapter.ERR_UNEXPECTEDSERVERRESPONSE, "");
                    return;
                }

                if (isStoppedByUser())
                {
                    return;
                }

                IDBResult res = getUserDB().executeSQL("SELECT * FROM client_info");
                if (!res.isEnd())
                {
                    getUserDB().executeSQL("UPDATE client_info SET session=?", strSession);
                }
                else
                {
                    getUserDB().executeSQL("INSERT INTO client_info (session) values (?)", strSession);
                }

                if (RHOCONF().isExist("rho_sync_user"))
                {
                    String strOldUser = RHOCONF().getString("rho_sync_user");
                    if (name.compareTo(strOldUser) != 0)
                    {
                        if (isNoThreadedMode())
                        {
                            RhoRuby.resetDBOnSyncUserChanged();
                        }
                        else
                        {
                            NetResponse resp1 = getNet().pushData(getNet().resolveUrl("/system/resetDBOnSyncUserChanged"), "", null);
                        }
                    }
                }
                RHOCONF().setString("rho_sync_user", name, true);

                getNotify().callLoginCallback(oNotify, RhoAppAdapter.ERR_NONE, "");

                if (ClientRegister.getInstance() != null)
                {
                    getUserDB().executeSQL("UPDATE client_info SET token_sent=?", 0);
                    ClientRegister.getInstance().startUp();
                }
            }catch (Exception exc)
            {
                LOG.ERROR("Login failed.", exc);
                getNotify().callLoginCallback(oNotify, RhoAppAdapter.ERR_RUNTIME, "");
            }
        }