Ejemplo n.º 1
0
        boolean downloadBlob(CAttrValue value)
        {
            String fName  = makeFileName(value);
            String url    = value.m_strValue;
            int    nQuest = url.lastIndexOf('?');

            if (nQuest > 0)
            {
                url += "&";
            }
            else
            {
                url += "?";
            }
            url += "client_id=" + getSync().getClientID();

            try{
                NetResponse resp = getNet().pullFile(url, fName, getSync(), null);
                if (!resp.isOK())
                {
                    getSync().stopSync();
                    m_nErrCode = RhoAppAdapter.getErrorFromResponse(resp);
                    return(false);
                }
            }catch (Exception exc)
            {
                m_nErrCode = RhoAppAdapter.getNetErrorCode(exc);
                throw exc;
            }

            value.m_strValue = CFilePath.getRelativePath(fName, CRhodesApp.getRhoRootPath());

            return(true);
        }
Ejemplo n.º 2
0
        public override Stream OpenInputFileStream(string path)
        {
            Stream st = null;

            StreamResourceInfo sr = Application.GetResourceStream(new Uri(CFilePath.removeFirstSlash(path), UriKind.Relative));

            if (sr != null)
            {
                st = sr.Stream;
            }

            if (st == null)
            {
                try
                {
                    CRhoFile file = new CRhoFile();
                    file.open(path, CRhoFile.EOpenModes.OpenReadOnly);
                    st = file.getStream();
                }
                catch (Exception exc)
                {
                    throw new System.IO.FileNotFoundException();
                }
            }

            if (st == null)
            {
                throw new System.IO.FileNotFoundException();
            }

            return(st);
        }
Ejemplo n.º 3
0
        String processDispatch(CRoute route, String method, String uri, String query, String body)
        {
            Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
            Object rhoResp = RhoRuby.callServe(rhoReq);

            String strRedirectUrl = getRedirectUrl(rhoResp);

            if (strRedirectUrl.Length > 0)
            {
                return(strRedirectUrl);
            }

            String strFilePath = RHODESAPP().canonicalizeRhoPath(uri) + ".gen.html";

            if (route.id.Length > 0)
            {
                strFilePath = CFilePath.join(m_root, route.application + "/" + route.model + "/" + route.action) + ".gen.html";
            }

            CRhoFile.recursiveCreateDir(strFilePath);
            CRhoFile.writeDataToFile(strFilePath, getResponseBody(rhoResp));

            if (method == "GET")
            {
                RHODESAPP().keepLastVisitedUrl(uri);
            }

            return(strFilePath);
        }
Ejemplo n.º 4
0
        public void open(String strPath, String strSqlScript, String strEncryptionInfo)
        {
            try
            {
                String dbURI = RHODESAPP().resolveDBFilesPath(strPath);
                dbURI = CFilePath.removeFirstSlash(dbURI);
                boolean bEncrypted = strEncryptionInfo != null && strEncryptionInfo.length() > 0;
                //DatabaseSecurityOptions dbso = new DatabaseSecurityOptions(bEncrypted);

                boolean bExist = CRhoFile.isFileExist(strPath);

                int res = Sqlite3.sqlite3_open(dbURI, ref m_db);
                if (res != Sqlite3.SQLITE_OK)
                {
                    throw new DBException(res, "Could not open database file: " + strPath);
                }

                res = Sqlite3.sqlite3_exec(m_db, "PRAGMA journal_mode=PERSIST", 0, 0, 0);
                if (res != Sqlite3.SQLITE_OK)
                {
                    Sqlite3.sqlite3_close(m_db);
                    m_db = null;
                    throw new DBException(res, "Cannot set journal mode to PERSIST: " + strPath);
                }

                string[] ar1 = CRhoFile.enumDirectory("db");

                if (!bExist)
                {
                    createSchema(strSqlScript);
                }

                Sqlite3.sqlite3_create_function(m_db, "rhoOnDeleteObjectRecord", 3, Sqlite3.SQLITE_ANY, 0,
                                                DBAdapter.SyncBlob_DeleteCallback, null, null);
                Sqlite3.sqlite3_create_function(m_db, "rhoOnUpdateObjectRecord", 3, Sqlite3.SQLITE_ANY, 0,
                                                DBAdapter.SyncBlob_UpdateCallback, null, null);
                Sqlite3.sqlite3_create_function(m_db, "rhoOnDeleteSchemaRecord", 1, Sqlite3.SQLITE_ANY, 0,
                                                DBAdapter.SyncBlob_DeleteSchemaCallback, null, null);
                Sqlite3.sqlite3_create_function(m_db, "rhoOnUpdateSchemaRecord", 2, Sqlite3.SQLITE_ANY, 0,
                                                DBAdapter.SyncBlob_UpdateSchemaCallback, null, null);

                string[] ar2 = CRhoFile.enumDirectory("db");

                if (m_bPendingTransaction)
                {
                    startTransaction();
                }

                m_bPendingTransaction = false;
            }
            catch (Exception exc)
            {
                throw new DBException(exc);
            }
            finally
            {
                m_nInsideTransaction = 0;
            }
        }
Ejemplo n.º 5
0
        bool isknowntype(String uri)
        {
            String[] ignored_exts = { ".css", ".js", ".html", ".htm", ".png", ".bmp", ".jpg", ".jpeg", ".gif" };

            String strExt = CFilePath.getExtension(uri).ToLower();

            return(find_in_string_array(strExt, ignored_exts));
        }
Ejemplo n.º 6
0
        //public static IDBResult createResult(){
        //	return getInstance().m_dbStorage.createResult();
        //}

        public String makeBlobFolderName()
        {
            String fName = CFilePath.join(CRhodesApp.getRhoRootPath(), "db/db-files");

            CRhoFile.recursiveCreateDir(fName);

            return(fName);
        }
Ejemplo n.º 7
0
        public boolean processBrowserRequest(Uri uri)
        {
            if (!uri.OriginalString.StartsWith(RHODESAPP().getHomeUrl()) &&
                (uri.IsAbsoluteUri || uri.OriginalString.StartsWith("res:")))
            {
                return(false);
            }

            String query = "";
            String url   = uri.OriginalString;

            url = url.StartsWith(RHODESAPP().getHomeUrl()) ? url.substring(RHODESAPP().getHomeUrl().length()) : url;

            int nFrag = url.LastIndexOf('#');

            if (nFrag >= 0)
            {
                url = url.Substring(0, nFrag);
            }

            int nQuery = url.IndexOf('?');

            if (nQuery >= 0)
            {
                query = url.Substring(nQuery + 1);
                url   = url.Substring(0, nQuery);
            }

            if (url.EndsWith(".gen.html") || (isknowntype(url) && url.StartsWith(m_root)))
            {
                return(false);
            }

            CRoute route = new CRoute();

            if (dispatch(url, route))
            {
                addQueueCommand(new CServerCommand(this, route, "GET", url, query, "", CServerCommand.scDispatch));

                return(true);
            }

            String fullPath = url.StartsWith(m_root) ? url : CFilePath.join(m_root, url);

            String strIndexFile = getIndex(fullPath);

            if (strIndexFile.Length > 0)
            {
                addQueueCommand(new CServerCommand(this, route, "GET", url, query, "", CServerCommand.scIndex));

                return(true);
            }

            return(false);
        }
Ejemplo n.º 8
0
        String getIndex(String path)
        {
            String[] index_files = { "index_erb.rb", "index.html", "index.htm", "index.php", "index.cgi" };

            if (CFilePath.getExtension(path).Length == 0)
            {
                return(CFilePath.join(path, index_files[0]));
            }

            String strFileName = CFilePath.getBaseName(path);

            return(find_in_string_array(strFileName, index_files) ? path : "");
        }
Ejemplo n.º 9
0
        public override Stream OpenInputFileStream(string path)
        {
            System.Diagnostics.Debug.WriteLine("open_file: " + path, "");

            StreamResourceInfo sr = Application.GetResourceStream(new Uri(CFilePath.removeFirstSlash(path), UriKind.Relative));

            if (sr == null)
            {
                throw new System.IO.FileNotFoundException();
            }

            return(sr.Stream);
        }
Ejemplo n.º 10
0
        IDictionary processIndex(CRoute route, String method, String uri, Dictionary <String, String> headers, String query, String body)
        {
            Object rhoResp = new Dictionary <String, String>();

            String fullPath     = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);
            String strIndexFile = getIndex(fullPath);

            if (!CRhoFile.isResourceFileExist(strIndexFile))
            {
                String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeStringToFile(strFilePath, error);
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH]  = strFilePath;
                ((IDictionary)rhoResp)[RESPONSE_STATUS]         = "404";
                ((IDictionary)rhoResp)[RESPONSE_STATUS_MESSAGE] = "Not Found";
                return((IDictionary)rhoResp);
            }

            if (CFilePath.getExtension(fullPath).Length > 0)
            {
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH]  = strIndexFile;
                ((IDictionary)rhoResp)[RESPONSE_STATUS]         = "200";
                ((IDictionary)rhoResp)[RESPONSE_STATUS_MESSAGE] = "Ok";
                return((IDictionary)rhoResp);
            }

            Object rhoReq = create_request_hash(route, method, uri, query, headers, body);

            rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

            String strRedirectUrl = getRedirectUrl(rhoResp);

            if (strRedirectUrl.Length > 0)
            {
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH] = strRedirectUrl;
                return((IDictionary)rhoResp);
            }

            strIndexFile += ".gen.html";
            CRhoFile.recursiveCreateDir(strIndexFile);
            CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

            if (method == "GET")
            {
                RHODESAPP().keepLastVisitedUrl(uri);
            }

            ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH] = strIndexFile;
            return((IDictionary)rhoResp);
        }
Ejemplo n.º 11
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.º 12
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.º 13
0
        public NetResponse pullFile(String strUrl, String strFileName, IRhoSession oSession, Hashtable <String, String> headers)
        {
            NetResponse resp = null;

            m_isPullFile = true;

            m_bCancel = false;

            try{
                if (!strFileName.startsWith("file:"))
                {
                    try{
                        strFileName = CFilePath.join(CRhodesApp.getRhoRootPath(), strFileName);
                    } catch (IOException e) {
                        LOG.ERROR("getDirPath failed.", e);
                    }
                }

                m_pulledFile = RhoClassFactory.createFile();
                m_pulledFile.open(strFileName, CRhoFile.EOpenModes.OpenForReadWrite);
                m_pulledFile.setPosTo(m_pulledFile.size());

                do
                {
                    resp = doRequest("GET", strUrl, null, oSession, headers, m_pulledFile.size());
                }while(!m_bCancel && (resp == null || resp.isOK()) && m_nCurDownloadSize > 0);
            }finally{
                if (m_pulledFile != null)
                {
                    try { m_pulledFile.close(); }
                    catch (IOException e)
                    {
                        LOG.ERROR("file closing failed.", e);
                    }
                    m_pulledFile = null;
                }
            }

            copyHashtable(m_OutHeaders, headers);

            m_isPullFile       = false;
            m_nCurDownloadSize = 0;
            return(resp != null && !m_bCancel ? resp : makeResponse("", Convert.ToInt32(HttpStatusCode.InternalServerError)));
        }
Ejemplo n.º 14
0
        String processIndex(CRoute route, String method, String uri, String query, String body)
        {
            String fullPath     = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);
            String strIndexFile = getIndex(fullPath);

            if (!CRhoFile.isResourceFileExist(strIndexFile))
            {
                String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeStringToFile(strFilePath, error);
                return(strFilePath);
            }

            if (CFilePath.getExtension(fullPath).Length > 0)
            {
                return(strIndexFile);
            }

            Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
            Object rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

            String strRedirectUrl = getRedirectUrl(rhoResp);

            if (strRedirectUrl.Length > 0)
            {
                return(strRedirectUrl);
            }

            strIndexFile += ".gen.html";
            CRhoFile.recursiveCreateDir(strIndexFile);
            CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

            if (method == "GET")
            {
                RHODESAPP().keepLastVisitedUrl(uri);
            }

            return(strIndexFile);
        }
Ejemplo n.º 15
0
 public override string GetDirectoryName(string path)
 {
     return(Path.GetDirectoryName(CFilePath.removeLastSlash(path)));
 }
Ejemplo n.º 16
0
        public CResponse decide(String method, String uri, String query, String body)
        {
            if (uri.EndsWith(".gen.html") || (isknowntype(uri) && uri.StartsWith(m_root)))
            {
                return(new CResponse(false));
            }

            if (process_registered(uri))
            {
                return(new CResponse(false));
            }

            CRoute route = new CRoute();

            if (dispatch(uri, route))
            {
                Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
                Object rhoResp = RhoRuby.callServe(rhoReq);

                String strRedirectUrl = getRedirectUrl(rhoResp);
                if (strRedirectUrl.Length > 0)
                {
                    return(new CResponse(strRedirectUrl));
                }

                String strFilePath = RHODESAPP().canonicalizeRhoPath(uri) + ".gen.html";
                if (route.id.Length > 0)
                {
                    strFilePath = CFilePath.join(m_root, route.application + "/" + route.model + "/" + route.action) + ".gen.html";
                }

                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeDataToFile(strFilePath, getResponseBody(rhoResp));

                if (method == "GET")
                {
                    RHODESAPP().keepLastVisitedUrl(uri);
                }

                return(new CResponse(strFilePath));
            }

            String fullPath = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);

            String strIndexFile = getIndex(fullPath);

            if (strIndexFile.Length > 0)
            {
                if (!CRhoFile.isResourceFileExist(strIndexFile))
                {
                    String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                    String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                    CRhoFile.recursiveCreateDir(strFilePath);
                    CRhoFile.writeStringToFile(strFilePath, error);
                    return(new CResponse(strFilePath));
                }

                if (CFilePath.getExtension(fullPath).Length > 0)
                {
                    return(new CResponse(strIndexFile));
                }

                Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
                Object rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

                String strRedirectUrl = getRedirectUrl(rhoResp);
                if (strRedirectUrl.Length > 0)
                {
                    return(new CResponse(strRedirectUrl));
                }

                strIndexFile += ".gen.html";
                CRhoFile.recursiveCreateDir(strIndexFile);
                CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

                if (method == "GET")
                {
                    RHODESAPP().keepLastVisitedUrl(uri);
                }

                return(new CResponse(strIndexFile));
            }

            return(new CResponse(false));
        }
Ejemplo n.º 17
0
        //static String szMultipartPostfix =
        //    "\r\n------------A6174410D6AD474183FDE48F5662FCC5--";

        //static String szMultipartContType =
        //    "multipart/form-data; boundary=----------A6174410D6AD474183FDE48F5662FCC5";

        void processMultipartItems(Vector <MultipartItem> arItems)
        {
            for (int i = 0; i < (int)arItems.size(); i++)
            {
                MultipartItem oItem = (MultipartItem)arItems.elementAt(i);

                if (oItem.m_strName.length() == 0)
                {
                    oItem.m_strName = "blob";
                }

                if (oItem.m_strFileName.length() == 0)
                {
                    if (oItem.m_strFilePath.length() > 0)
                    {
                        oItem.m_strFileName = CFilePath.getBaseName(oItem.m_strFilePath);
                    }
                    //else
                    //    oItem.m_strFileName = "doesnotmatter.txt";
                }

                oItem.m_strDataPrefix  = i > 0 ? "\r\n" : "";
                oItem.m_strDataPrefix +=
                    "------------A6174410D6AD474183FDE48F5662FCC5\r\n" +
                    "Content-Disposition: form-data; name=\"";
                oItem.m_strDataPrefix += oItem.m_strName + "\"";
                if (oItem.m_strFileName.length() > 0)
                {
                    oItem.m_strDataPrefix += "; filename=\"" + oItem.m_strFileName + "\"";
                }
                oItem.m_strDataPrefix += "\r\n";
                if (oItem.m_strContentType != null && oItem.m_strContentType.length() > 0)
                {
                    oItem.m_strDataPrefix += "Content-Type: " + oItem.m_strContentType + "\r\n";
                }

                long nContentSize = 0;
                if (oItem.m_strFilePath.length() > 0)
                {
                    //TODO: process file

/*	                SimpleFile file = null;
 *                          try{
 *                                  file = RhoClassFactory.createFile();
 *                                  file.open(oItem.m_strFilePath, true, true);
 *                                  nContentSize = file.length();
 *                                  if ( !file.isOpened() ){
 *                                          LOG.ERROR("File not found: " + oItem.m_strFilePath);
 *                                          throw new RuntimeException("File not found:" + oItem.m_strFilePath);
 *                                  }
 *                          }finally{
 *                                  if ( file != null )
 *                                          try{ file.close(); }catch(IOException e){}
 *                          }*/
                }
                else
                {
                    nContentSize = oItem.m_strBody.length();
                }

                if (oItem.m_strContentType != null && oItem.m_strContentType.length() > 0)
                {
                    oItem.m_strDataPrefix += "Content-Length: " + nContentSize + "\r\n";
                }

                oItem.m_strDataPrefix += "\r\n";
            }
        }
Ejemplo n.º 18
0
        public void rb_destroy_tables(Vector <String> vecIncludes, Vector <String> vecExcludes)
        {
            if (!m_bIsOpen)
            {
                return;
            }

            IDBStorage db = null;

            try{
                String dbNewName = CFilePath.changeBaseName(m_strDBPath, "resetdbtemp.sqlite");

                CRhoFile.deleteFile(dbNewName);
                CRhoFile.deleteFile(dbNewName + "-journal");
                CRhoFile.deleteFile(dbNewName + ".version");

                db = RhoClassFactory.createDBStorage();
                db.open(dbNewName, getSqlScript(), getEncryptionInfo());

                String[] vecTables = m_dbStorage.getAllTableNames();
                //IDBResult res;

                db.startTransaction();

                for (int i = 0; i < vecTables.Length; i++)
                {
                    String tableName = vecTables[i];
                    if (destroyTableName(tableName, vecIncludes, vecExcludes))
                    {
                        continue;
                    }

                    copyTable(tableName, this.m_dbStorage, db);
                }

                db.commit();
                db.close();

                String dbOldName = m_strDBPath;

                m_dbStorage.close();
                m_dbStorage = null;
                m_bIsOpen   = false;

                CRhoFile.deleteFilesInFolder(RHODESAPP().getBlobsDirPath());

                string[] ar1 = CRhoFile.enumDirectory("db");

                CRhoFile.deleteFile(dbOldName);
                CRhoFile.deleteFile(dbOldName + "-journal");
                CRhoFile.renameFile(dbNewName, dbOldName);
                CRhoFile.renameFile(dbNewName + "-journal", dbOldName + "-journal");

                string[] ar2 = CRhoFile.enumDirectory("db");

                m_dbStorage = RhoClassFactory.createDBStorage();
                m_dbStorage.open(m_strDBPath, getSqlScript(), getEncryptionInfo());
                m_bIsOpen = true;

                string[] ar3 = CRhoFile.enumDirectory("db");
                m_dbStorage.setDbCallback(new DBCallback(this));
            }catch (Exception e)
            {
                LOG.ERROR("destroy_table failed.", e);

                if (!m_bIsOpen)
                {
                    LOG.ERROR("destroy_table error.Try to open old DB.");
                    try{
                        m_dbStorage.open(m_strDBPath, getSqlScript(), getEncryptionInfo());
                        m_bIsOpen = true;
                    }catch (Exception exc)
                    {
                        LOG.ERROR("destroy_table open old table failed.", exc);
                    }
                }

                try {
                    if (db != null)
                    {
                        db.close();
                    }
                } catch (DBException e1) {
                    LOG.ERROR("closing of DB caused exception: " + e1.Message);
                }

                throw e;
            }
        }
Ejemplo n.º 19
0
        public boolean processBrowserRequest(String reqType, Uri uri, IDictionary headers, IDictionary data, String strAjaxContext, int tabIndex = -1)
        {
            boolean bAjaxCall = !(strAjaxContext == null || strAjaxContext.length() == 0);

            if (!uri.OriginalString.StartsWith(RHODESAPP().getHomeUrl()) &&
                (uri.IsAbsoluteUri || uri.OriginalString.StartsWith("res:")))
            {
                return(false);
            }

            String query = "";
            String url   = uri.OriginalString;

            url = url.StartsWith(RHODESAPP().getHomeUrl()) ? url.substring(RHODESAPP().getHomeUrl().length()) : url;

            int nFrag = url.LastIndexOf('#');

            if (nFrag >= 0)
            {
                url = url.Substring(0, nFrag);
            }

            int nQuery = url.IndexOf('?');

            if (nQuery >= 0)
            {
                query = url.Substring(nQuery + 1);
                url   = url.Substring(0, nQuery);
            }

            if (url.EndsWith(".gen.html") || (isknowntype(url) && url.StartsWith(m_root)))
            {
                return(false);
            }

            CRoute route = new CRoute();

            if (dispatch(url, route))
            {
                addQueueCommand(new CServerCommand(this, route, reqType,
                                                   url + (0 < query.Length ? ("?" + query) : ""),
                                                   headers, data, CServerCommand.scDispatch, strAjaxContext, tabIndex));
                //addQueueCommand(new CServerCommand(this, route, bAjaxCall ? "GET" : "GET", url, query, "", CServerCommand.scDispatch, strAjaxContext));

                return(true);
            }

            String fullPath = url.StartsWith(m_root) ? url : CFilePath.join(m_root, url);

            String strIndexFile = getIndex(fullPath);

            if (strIndexFile.Length > 0)
            {
                addQueueCommand(new CServerCommand(this, route, reqType, url, headers, data, CServerCommand.scIndex, strAjaxContext, tabIndex));
                //addQueueCommand(new CServerCommand(this, route, bAjaxCall ? "GET" : "GET", url, query, "", CServerCommand.scIndex, strAjaxContext));

                return(true);
            }

            return(false);
        }
Ejemplo n.º 20
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.º 21
0
        void processMultipartItems(Vector <MultipartItem> arItems)
        {
            for (int i = 0; i < (int)arItems.size(); i++)
            {
                MultipartItem oItem = (MultipartItem)arItems.elementAt(i);

                if (oItem.m_strName.length() == 0)
                {
                    oItem.m_strName = "blob";
                }

                if (oItem.m_strFileName.length() == 0)
                {
                    if (oItem.m_strFilePath.length() > 0)
                    {
                        oItem.m_strFileName = CFilePath.getBaseName(oItem.m_strFilePath);
                    }
                    //else
                    //    oItem.m_strFileName = "doesnotmatter.txt";
                }

                oItem.m_strDataPrefix  = i > 0 ? "\r\n" : "";
                oItem.m_strDataPrefix +=
                    "------------A6174410D6AD474183FDE48F5662FCC5\r\n" +
                    "Content-Disposition: form-data; name=\"";
                oItem.m_strDataPrefix += oItem.m_strName + "\"";
                if (oItem.m_strFileName.length() > 0)
                {
                    oItem.m_strDataPrefix += "; filename=\"" + oItem.m_strFileName + "\"";
                }
                oItem.m_strDataPrefix += "\r\n";
                if (oItem.m_strContentType != null && oItem.m_strContentType.length() > 0)
                {
                    oItem.m_strDataPrefix += "Content-Type: " + oItem.m_strContentType + "\r\n";
                }

                long nContentSize = 0;
                if (oItem.m_strFilePath.length() > 0)
                {
                    CRhoFile file = null;
                    try{
                        file = RhoClassFactory.createFile();
                        file.open(oItem.m_strFilePath, CRhoFile.EOpenModes.OpenReadOnly);
                        nContentSize = file.size();
                        if (!file.isOpened())
                        {
                            LOG.ERROR("File not found: " + oItem.m_strFilePath);
                            throw new Exception("File not found:" + oItem.m_strFilePath);
                        }
                    }finally{
                        if (file != null)
                        {
                            try{ file.close(); }catch (IOException e)
                            {
                                LOG.ERROR("file closing failed.", e);
                            }
                        }
                    }
                }
                else
                {
                    nContentSize = oItem.m_strBody.length();
                }

                if (oItem.m_strContentType != null && oItem.m_strContentType.length() > 0)
                {
                    oItem.m_strDataPrefix += "Content-Length: " + nContentSize + "\r\n";
                }

                oItem.m_strDataPrefix += "\r\n";
            }
        }