Ejemplo n.º 1
0
 public void loadFromConf(RhoConf oRhoConf)
 {
     if (oRhoConf.isExist("MinSeverity"))
     {
         setMinSeverity(oRhoConf.getInt("MinSeverity"));
     }
     if (oRhoConf.isExist("LogToOutput"))
     {
         setLogToOutput(oRhoConf.getBool("LogToOutput"));
     }
     if (oRhoConf.isExist("LogToFile"))
     {
         setLogToFile(oRhoConf.getBool("LogToFile"));
     }
     if (oRhoConf.isExist("LogFilePath"))
     {
         setLogFilePath(oRhoConf.getString("LogFilePath"));
     }
     if (oRhoConf.isExist("MaxLogFileSize"))
     {
         setMaxLogFileSize(oRhoConf.getInt("MaxLogFileSize"));
     }
     if (oRhoConf.isExist("LogCategories"))
     {
         setEnabledCategories(oRhoConf.getString("LogCategories"));
     }
     if (oRhoConf.isExist("ExcludeLogCategories"))
     {
         setDisabledCategories(oRhoConf.getString("ExcludeLogCategories"));
     }
 }
Ejemplo n.º 2
0
        public String getRegisterBody(String strClientID)
        {
            int port = RhoConf.getInstance().getInt("push_port");

            return(SyncThread.getSyncEngine().getProtocol().getClientRegisterBody(strClientID, m_strDevicePin,
                                                                                  port > 0 ? port : DEFAULT_PUSH_PORT, RHODESAPP().getPlatform()));
        }
Ejemplo n.º 3
0
        void doBulkSync()
        {
            //	    processServerSources("{\"partition\":\"" + "application" + "\"}");

            if (!RhoConf.getInstance().isExist("bulksync_state"))
            {
                return;
            }

            int nBulkSyncState = RhoConf.getInstance().getInt("bulksync_state");;

            if (nBulkSyncState >= 1 || !isContinueSync())
            {
                return;
            }

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

            Vector <String> arPartNames = DBAdapter.getDBAllPartitionNames();

            for (int i = 0; i < (int)arPartNames.size() && isContinueSync(); i++)
            {
                loadBulkPartition((String)arPartNames.elementAt(i));
            }

            if (isContinueSync())
            {
                RhoConf.getInstance().setInt("bulksync_state", 1, true);
                getNotify().fireBulkSyncNotification(true, "", "", RhoAppAdapter.ERR_NONE);
            }
        }
Ejemplo n.º 4
0
 public void startUp()
 {
     if (RhoConf.getInstance().getString("syncserver").length() > 0)
     {
         start(epLow);
         stopWait();
     }
 }
Ejemplo n.º 5
0
        public String getClientResetUrl(String strClientID)
        {
            String strUrl     = RhoConf.getInstance().getPath("syncserver") + "clientreset?client_id=" + strClientID;
            String strSources = RhoConf.getInstance().getString("reset_models");

            if (strSources.length() > 0)
            {
                strUrl += strSources;
            }

            return(strUrl);
        }
Ejemplo n.º 6
0
        public void setSyncServer(String syncserver)
        {
            String strOldSrv = RhoConf.getInstance().getString("syncserver");
            String strNewSrv = syncserver != null ? syncserver : "";

            if (strOldSrv.compareTo(strNewSrv) != 0)
            {
                RhoConf.getInstance().setString("syncserver", syncserver, true);

                getUserDB().executeSQL("DELETE FROM client_info");

                logout_int();
            }
        }
Ejemplo n.º 7
0
        public String getServerQueryUrl(String strAction)
        {
            String strUrl = RhoConf.getInstance().getPath("syncserver");

            if (strAction.length() > 0)
            {
                strUrl = CFilePath.join(strUrl, strAction);
            }
            else
            {
                strUrl = strUrl.substring(0, strUrl.length() - 1);
            }

            return(strUrl);
        }
Ejemplo n.º 8
0
 public String getLoginUrl()
 {
     if (RhoConf.getInstance().getPath("syncserver").Equals("http://rhoconnect-spec-wp.heroku.com/application/"))
     {
         return("http://rhoconnect-spec-wp.heroku.com/api/application/clientlogin");
     }
     else if (RhoConf.getInstance().getPath("syncserver").Equals("http://rhodes-samples-server.heroku.com/application/"))
     {
         return("http://rhodes-samples-server.heroku.com/api/application/clientlogin");
     }
     else
     {
         return(RhoConf.getInstance().getPath("syncserver") + "clientlogin");
     }
 }
Ejemplo n.º 9
0
 public static Boolean is_property_exists(RubyModule /*!*/ self, [NotNull] String /*!*/ name)
 {
     try
     {
         return(RhoConf.getInstance().isExist(name));
     }
     catch (Exception ex)
     {
         Exception rubyEx = self.Context.CurrentException;
         if (rubyEx == null)
         {
             rubyEx = RubyExceptionData.InitializeException(new RuntimeError(ex.Message.ToString()), ex.Message);
         }
         LOG.ERROR("is_property_exists", ex);
         throw rubyEx;
     }
 }
Ejemplo n.º 10
0
        String makeBulkDataFileName(String strDataUrl, String strDbPath, String strExt)
        {
            String strNewName = CFilePath.getBaseName(strDataUrl);
            String strOldName = RhoConf.getInstance().getString("bulksync_filename");

            if (strOldName.length() > 0 && strNewName.compareTo(strOldName) != 0)
            {
                String strFToDelete = CFilePath.changeBaseName(strDbPath, strOldName + strExt);
                LOG.INFO("Bulk sync: remove old bulk file '" + strFToDelete + "'");

                //RhoFile.deleteFile( strFToDelete.c_str() );
                CRhoFile.deleteFile(strFToDelete);
            }

            RhoConf.getInstance().setString("bulksync_filename", strNewName, true);

            return(CFilePath.changeBaseName(strDbPath, strNewName + strExt));
        }
Ejemplo n.º 11
0
        public static void set_property_by_name(RubyModule /*!*/ self, [NotNull] String /*!*/ name, Object value)
        {
            try
            {
                RhoConf.getInstance().setString(name, value as String, true);

                RhoLogger.getLogConf().loadFromConf(RhoConf.getInstance());
            }
            catch (Exception ex)
            {
                Exception rubyEx = self.Context.CurrentException;
                if (rubyEx == null)
                {
                    rubyEx = RubyExceptionData.InitializeException(new RuntimeError(ex.Message.ToString()), ex.Message);
                }
                LOG.ERROR("set_property_by_name", ex);
                throw rubyEx;
            }
        }
Ejemplo n.º 12
0
        SyncThread()
        {
            CThreadQueue.setLogCategory(LOG.getLogCategory());

            if (RhoConf.getInstance().isExist("sync_poll_interval"))
            {
                setPollInterval(RhoConf.getInstance().getInt("sync_poll_interval"));
            }

            m_oSyncEngine = new SyncEngine();
            m_oSyncEngine.setFactory();

            LOG.INFO("sync_poll_interval: " + RhoConf.getInstance().getInt("sync_poll_interval"));
            LOG.INFO("syncserver: " + RhoConf.getInstance().getString("syncserver"));
            LOG.INFO("bulksync_state: " + RhoConf.getInstance().getInt("bulksync_state"));

            //ClientRegister.Create();

            if (RhoConf.getInstance().getString("syncserver").length() > 0)
            {
                start(epLow);
            }
        }
Ejemplo n.º 13
0
 public String getStartPage()
 {
     return(RhoConf.getInstance().getString("start_path"));
 }
Ejemplo n.º 14
0
 public String getClientCreateUrl()
 {
     return(RhoConf.getInstance().getPath("syncserver") + "clientcreate");
 }
Ejemplo n.º 15
0
        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);
                }
            }
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
 public String getClientResetUrl(String strClientID)
 {
     return(RhoConf.getInstance().getPath("syncserver") + "clientreset?client_id=" + strClientID);
 }
Ejemplo n.º 18
0
 public String getOptionsPage()
 {
     return(RhoConf.getInstance().getString("options_path"));
 }
Ejemplo n.º 19
0
 public String getClientRegisterUrl()
 {
     return(RhoConf.getInstance().getPath("syncserver") + "clientregister");
 }
Ejemplo n.º 20
0
        public String getClientChangesUrl()
        {
            String strUrl = RhoConf.getInstance().getPath("syncserver");

            return(strUrl.substring(0, strUrl.length() - 1));
        }
Ejemplo n.º 21
0
 RhoConf RHOCONF()
 {
     return(RhoConf.getInstance());
 }
Ejemplo n.º 22
0
 public String getLoginUrl()
 {
     return(RhoConf.getInstance().getPath("syncserver") + "clientlogin");
 }