示例#1
0
        private static void cameraTask_Completed(object sender, PhotoResult e)
        {
            switch (e.TaskResult)
            {
            case TaskResult.OK:
                RhoClassFactory.createNetRequest().pushData(m_callback, "status=ok&image_uri=" + e.OriginalFileName + "&rho_callback=1", null);
                break;

            case TaskResult.None:
                RhoClassFactory.createNetRequest().pushData(m_callback, "status=error&message=Error&rho_callback=1", null);
                break;

            case TaskResult.Cancel:
                RhoClassFactory.createNetRequest().pushData(m_callback, "status=cancel&message=User cancelled operation&rho_callback=1", null);
                break;

            default:
                break;
            }

            //Code to display the photo on the page in an image control named myImage.
            //System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
            //bmp.SetSource(e.ChosenPhoto);
            //myImage.Source = bmp;
        }
示例#2
0
        public void setFactory()
        {
            m_NetRequest         = RhoClassFactory.createNetRequest();
            m_NetRequestClientID = RhoClassFactory.createNetRequest();

            m_oSyncNotify.setFactory();
        }
示例#3
0
        private ClientRegister(String device_pin)
        {
            m_strDevicePin  = device_pin;
            m_NetRequest    = RhoClassFactory.createNetRequest();
            m_nPollInterval = POLL_INTERVAL_SECONDS;

            startUp();
        }
示例#4
0
 public DBAdapter()
 {
     try{
         m_dbStorage = RhoClassFactory.createDBStorage();
     }catch (Exception exc) {
         LOG.ERROR("createDBStorage failed.", exc);
     }
 }
示例#5
0
 private static void messagePrompt_Completed(object sender, PopUpEventArgs <string, PopUpResult> e)
 {
     if (m_callback != "")
     {
         m_callback = RHODESAPP().canonicalizeRhoUrl(m_callback);
         RhoClassFactory.createNetRequest().pushData(m_callback, "button_id=" + m_buttonId.ToString() + "&button_title=" + m_buttonTitle + "&rho_callback=1", null);
     }
 }
示例#6
0
            public HttpCommand(String strCmd, RhoParams p)
            {
                m_params            = new RhoParams(p);
                m_eCmd              = translateCommand(strCmd);
                m_strCallback       = m_params.getString("callback");
                m_strCallbackParams = m_params.getString("callback_param");

                m_mapHeaders = m_params.getHash("headers");

                m_pNetRequest = RhoClassFactory.createNetRequest();
                m_pNetRequest.sslVerifyPeer(m_params.getBool("ssl_verify_peer"));
            }
示例#7
0
        private void WebBrowser_OnLoaded(object sender, RoutedEventArgs e)
        {
            if (RHODESAPP().Tab != null && RHODESAPP().Tab.SelectedIndex != m_index)
            {
                return;
            }
            if (RHODESAPP().m_transition)
            {
                RHODESAPP().m_transition = false;

                return;
            }
            OperatingSystem os = Environment.OSVersion;
            Version         vs = os.Version;

            if (vs.Minor < 10)
            {
                m_reload = true;
            }
            if (RHODESAPP().rhoView != null)
            {
                RHODESAPP().rhoView.BackHistory    = RHODESAPP().BackHistory;
                RHODESAPP().rhoView.ForwardHistory = RHODESAPP().ForwardHistory;
                RHODESAPP().rhoView.CurrentUri     = RHODESAPP().CurrentUri;
            }
            RHODESAPP().Init(webBrowser1, m_mainPage, m_layoutRoot, this);
            RHODESAPP().BackHistory    = m_backHistory;
            RHODESAPP().ForwardHistory = m_forwardHistory;
            RHODESAPP().CurrentUri     = m_currentUri;
            if (((!m_loadFirstTime && m_reload) || m_loadFirstTime) && m_strAction != null)
            {
                //bool callback = false;
                if (m_strAction.startsWith("callback:"))
                {
                    m_strAction = m_strAction.substring(9);
                    m_callback  = true;
                }
                m_strAction = RHODESAPP().canonicalizeRhoUrl(m_strAction);
                if (m_callback)
                {
                    RhoClassFactory.createNetRequest().pushData(m_strAction, "rho_callback=1", null);
                }
                else if (!m_callback)
                {
                    webBrowser1.Navigate(new Uri(m_strAction));
                }

                if (m_loadFirstTime)
                {
                    m_loadFirstTime = false;
                }
            }
        }
示例#8
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)));
        }
示例#9
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;
            }
        }
示例#10
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);
                }
            }
        }
示例#11
0
 public void setFactory()
 {
     m_NetRequest = RhoClassFactory.createNetRequest();
 }
示例#12
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";
            }
        }
示例#13
0
        private void GetRequestStreamCallback(IAsyncResult asyncResult)
        {
            Stream stream = null;

            try
            {
                stream = m_webRequest.EndGetRequestStream(asyncResult);
                if (m_strBody != null)
                {
                    stream.Write(new UTF8Encoding().GetBytes(m_strBody), 0, m_strBody.length());//TODO ASCII ???
                }
                else if (m_isMultiPart)
                {
                    for (int i = 0; i < (int)m_arItems.size(); i++)
                    {
                        MultipartItem oItem = (MultipartItem)m_arItems.elementAt(i);
                        stream.Write(new UTF8Encoding().GetBytes(oItem.m_strDataPrefix), 0, oItem.m_strDataPrefix.length());

                        if (oItem.m_strFilePath.length() > 0)
                        {
                            IInputStream fis  = null;
                            CRhoFile     file = RhoClassFactory.createFile();
                            try
                            {
                                file.open(oItem.m_strFilePath, CRhoFile.EOpenModes.OpenReadOnly);
                                if (!file.isOpened())
                                {
                                    LOG.ERROR("File not found: " + oItem.m_strFilePath);
                                    throw new Exception("File not found:" + oItem.m_strFilePath);
                                }

                                fis = file.getInputStream();
                                byte[] byteBuffer = new byte[1024 * 4];
                                int    nRead      = 0;
                                do
                                {
                                    nRead = fis.read(byteBuffer, 0, 1024 * 4);
                                    if (nRead > 0)
                                    {
                                        stream.Write(byteBuffer, 0, nRead);
                                    }
                                } while (nRead > 0);
                            }
                            finally
                            {
                                if (file != null)
                                {
                                    try { file.close(); }
                                    catch (IOException e)
                                    {
                                        LOG.ERROR("GetRequestStreamCallback: file close failed.", e);
                                    }
                                }
                            }
                        }
                        else
                        {
                            stream.Write(new UTF8Encoding().GetBytes(oItem.m_strBody), 0, oItem.m_strBody.length());
                        }
                    }
                    stream.Write(new UTF8Encoding().GetBytes(szMultipartPostfix), 0, szMultipartPostfix.length());
                }
                LOG.INFO("write body done");
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
                m_reqWaitEvent.Set();
            }
        }
示例#14
0
        private static void ClosePickerPage()
        {
            if (null != m_frame)
            {
                m_frame.Navigated         -= OnFrameNavigated;
                m_frame.NavigationStopped -= OnFrameNavigationStoppedOrFailed;
                m_frame.NavigationFailed  -= OnFrameNavigationStoppedOrFailed;

                m_frame = null;
                m_frameContentWhenOpened = null;
            }

            if (null != m_dateTimePickerPage)
            {
                m_dateValue = m_dateTimePickerPage.m_dateValue;
                m_timeValue = m_dateTimePickerPage.m_timeValue;
                DateTime result = new DateTime();

                switch (m_fmt)
                {
                case 0:
                    result = m_dateValue;    //TODO// + m_timeValue;
                    break;

                case 1:
                    result = m_dateValue;
                    break;

                case 2:
                    result = m_timeValue;
                    break;

                default:
                    break;
                }

                long sec = (result - new DateTime(1970, 1, 1)).Ticks / 10000000;

                if (m_callback != "")
                {
                    m_callback = RHODESAPP().canonicalizeRhoUrl(m_callback);
                    String body = "";
                    if (m_dateTimePickerPage.m_cancel == false)
                    {
                        body += "status=ok&result=" + sec.ToString();
                    }
                    else
                    {
                        body += "status=cancel";
                    }
                    if (m_opaque != null)
                    {
                        body += "&opaque=" + m_opaque;
                    }
                    body += "&rho_callback=1";
                    RhoClassFactory.createNetRequest().pushData(m_callback, body, null);
                    //m_frame.InvalidateArrange();
                }
                m_dateTimePickerPage = null;
            }
        }