예제 #1
0
 RhoConf RHOCONF()
 {
     return(RhoConf.getInstance());
 }
예제 #2
0
 public String getStartPage()
 {
     return(RhoConf.getInstance().getString("start_path"));
 }
예제 #3
0
 public String getOptionsPage()
 {
     return(RhoConf.getInstance().getString("options_path"));
 }
예제 #4
0
        void loadBulkPartition(String strPartition)
        {
            DBAdapter dbPartition = getDB(strPartition);
            String    serverUrl = RhoConf.getInstance().getPath("syncserver");
            String    strUrl = serverUrl + "bulk_data";
            String    strQuery = "?client_id=" + m_clientID + "&partition=" + strPartition;
            String    strDataUrl = "", strCmd = "", strCryptKey = "";

            getNotify().fireBulkSyncNotification(false, "start", strPartition, RhoAppAdapter.ERR_NONE);

            while (strCmd.length() == 0 && isContinueSync())
            {
                NetResponse resp = getNet().pullData(strUrl + strQuery, this);
                if (!resp.isOK() || resp.getCharData() == null)
                {
                    LOG.ERROR("Bulk sync failed: server return an error.");
                    stopSync();
                    getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.getErrorFromResponse(resp));
                    return;
                }

                LOG.INFO("Bulk sync: got response from server: " + resp.getCharData());

                String    szData     = resp.getCharData();
                JSONEntry oJsonEntry = new JSONEntry(szData);
                strCmd = oJsonEntry.getString("result");
                if (oJsonEntry.hasName("url"))
                {
                    strDataUrl = oJsonEntry.getString("url");
                }

                if (strCmd.compareTo("wait") == 0)
                {
                    int nTimeout = RhoConf.getInstance().getInt("bulksync_timeout_sec");
                    if (nTimeout == 0)
                    {
                        nTimeout = 5;
                    }

                    SyncThread.getInstance().wait(nTimeout);
                    strCmd = "";
                }
            }

            if (strCmd.compareTo("nop") == 0)
            {
                LOG.INFO("Bulk sync return no data.");
                getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.ERR_NONE);
                return;
            }

            if (!isContinueSync())
            {
                return;
            }

            getNotify().fireBulkSyncNotification(false, "download", strPartition, RhoAppAdapter.ERR_NONE);

            String fDataName     = makeBulkDataFileName(strDataUrl, dbPartition.getDBPath(), "");
            String strZip        = ".rzip";
            String strSqlDataUrl = CFilePath.join(getHostFromUrl(serverUrl), strDataUrl) + strZip;

            LOG.INFO("Bulk sync: download data from server: " + strSqlDataUrl);
            {
                NetResponse resp1 = getNet().pullFile(strSqlDataUrl, fDataName + strZip, this, null);
                if (!resp1.isOK())
                {
                    LOG.ERROR("Bulk sync failed: cannot download database file.");
                    stopSync();
                    getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.getErrorFromResponse(resp1));
                    return;
                }
            }

            if (!isContinueSync())
            {
                return;
            }

            LOG.INFO("Bulk sync: unzip db");

            if (!RHODESAPP().unzip_file(fDataName + strZip))
            {
                CRhoFile.deleteFile(fDataName + strZip);
                LOG.ERROR("Bulk sync failed: cannot unzip database file.");
                stopSync();
                getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.ERR_UNEXPECTEDSERVERRESPONSE);
                return;
            }
            CRhoFile.deleteFile(fDataName + strZip);

            LOG.INFO("Bulk sync: start change db");
            getNotify().fireBulkSyncNotification(false, "change_db", strPartition, RhoAppAdapter.ERR_NONE);

            dbPartition.setBulkSyncDB(fDataName, strCryptKey);
            processServerSources("{\"partition\":\"" + strPartition + "\"}");

            LOG.INFO("Bulk sync: end change db");
            getNotify().fireBulkSyncNotification(false, "", strPartition, RhoAppAdapter.ERR_NONE);
        }
예제 #5
0
파일: DBAdapter.cs 프로젝트: wurlinc/rhodes
        void checkDBVersion()
        {
            DBVersion dbNewVer = new DBVersion();

            dbNewVer.m_strRhoVer = RhoRuby.getRhoDBVersion();
            dbNewVer.m_strAppVer = RhoConf.getInstance().getString("app_db_version");
            String strEncryptionInfo = getEncryptionInfo();

            dbNewVer.m_bEncrypted = strEncryptionInfo != null && strEncryptionInfo.length() > 0;
            dbNewVer.m_bSqlite    = true;

            DBVersion dbVer = new DBVersion();

            dbVer.fromFile(m_strDbVerPath);

            if (dbVer.m_strRhoVer.length() == 0)
            {
                dbNewVer.toFile(m_strDbVerPath);
                return;
            }

            boolean bRhoReset = dbVer.isRhoVerChanged(dbNewVer);
            boolean bAppReset = dbVer.isAppVerChanged(dbNewVer);

            boolean bDbFormatChanged = dbVer.isDbFormatChanged(dbNewVer);

            if (!bDbFormatChanged && dbVer.m_bEncrypted)
            {
                //TODO: check encryption key
                //if (!com.rho.RhoCrypto.isKeyExist(strEncryptionInfo) )
                //	bDbFormatChanged = true;
            }

            if (bDbFormatChanged)
            {
                LOG.INFO("Reset Database( format changed ):" + m_strDBPath);
            }

            if (bRhoReset && !bAppReset && !bDbFormatChanged)
            {
                bRhoReset = !migrateDB(dbVer, dbNewVer);
            }

            if (bRhoReset || bAppReset || bDbFormatChanged)
            {
                if (!bDbFormatChanged)
                {
                    IDBStorage db = null;
                    try
                    {
                        db = RhoClassFactory.createDBStorage();
                        if (db.isDbFileExists(m_strDBPath))
                        {
                            db.open(m_strDBPath, "", strEncryptionInfo);
                            IDBResult res = db.executeSQL("SELECT * FROM client_info", null, false, false);
                            if (!res.isEnd())
                            {
                                m_strClientInfoInsert = createInsertStatement(res, "client_info");
                                m_dataClientInfo      = res.getCurData();
                            }
                        }
                    }catch (Exception exc)
                    {
                        LOG.ERROR("Copy client_info table failed.", exc);
                    }finally
                    {
                        if (db != null)
                        {
                            try { db.close(); } catch (Exception) {  }
                        }
                    }
                }

                m_dbStorage.deleteAllFiles(m_strDBPath);

                if (this.m_strDbPartition.compareTo("user") == 0)           //do it only once
                {
                    String fName = makeBlobFolderName();
                    CRhoFile.deleteDirectory(fName);
                    makeBlobFolderName();             //Create folder back
                }

                dbNewVer.toFile(m_strDbVerPath);

                if (RhoConf.getInstance().isExist("bulksync_state") && RhoConf.getInstance().getInt("bulksync_state") != 0)
                {
                    RhoConf.getInstance().setInt("bulksync_state", 0, true);
                }
            }
        }
예제 #6
0
        public String getClientChangesUrl()
        {
            String strUrl = RhoConf.getInstance().getPath("syncserver");

            return(strUrl.substring(0, strUrl.length() - 1));
        }
예제 #7
0
 public String getClientRegisterUrl()
 {
     return(RhoConf.getInstance().getPath("syncserver") + "clientregister");
 }
예제 #8
0
 public String getClientCreateUrl()
 {
     return(RhoConf.getInstance().getPath("syncserver") + "clientcreate");
 }
예제 #9
0
 public String getClientResetUrl(String strClientID)
 {
     return(RhoConf.getInstance().getPath("syncserver") + "clientreset?client_id=" + strClientID);
 }
예제 #10
0
 public String getLoginUrl()
 {
     return(RhoConf.getInstance().getPath("syncserver") + "clientlogin");
 }