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; }
void readChanges() { String strTimestamp = CRhoFile.readStringFromResourceFile(CONF_FILENAME + CONF_TIMESTAMP); if (CRhoFile.isFileExist(getConfFilePath() + CONF_CHANGES)) { String strSettings = CRhoFile.readStringFromFile(getConfFilePath() + CONF_CHANGES); loadFromString(strSettings, m_mapChangedValues); String strOldTimestamp = ""; if (m_mapChangedValues.containsKey(CONF_TIMESTAMP_PROP)) { strOldTimestamp = (String)m_mapChangedValues.get(CONF_TIMESTAMP_PROP); } if (strTimestamp.compareTo(strOldTimestamp) != 0) { checkConflicts(); } loadFromString(strSettings, m_mapValues); } else { m_mapChangedValues.put(CONF_TIMESTAMP_PROP, strTimestamp); } }
public void Init(WebBrowser browser, PhoneApplicationPage appMainPage, Grid layoutRoot, RhoView rhoView) { initAppUrls(); RhoLogger.InitRhoLog(); LOG.INFO("Init"); CRhoFile.recursiveCreateDir(CFilePath.join(getBlobsDirPath(), " ")); m_webBrowser = browser; if (m_appMainPage == null) { m_appMainPage = appMainPage; } if (m_layoutRoot == null) { m_layoutRoot = layoutRoot; } //m_appMainPage.ApplicationBar = null; if (m_httpServer == null) { m_httpServer = new CHttpServer(CFilePath.join(getRhoRootPath(), "apps")); } m_rhoView = rhoView; if (m_rhoView.MasterView) { m_masterView = rhoView; } }
public static byte[] readResourceFile(String path) { byte[] content = new byte[0]; path = CFilePath.removeFirstSlash(path); if (!CRhoFile.isResourceFileExist(path)) { return(content); } var task = StorageFile.GetFileFromApplicationUriAsync(new Uri(path, UriKind.Relative)).AsTask(); task.Wait(); var sr = task.Result; var streamTask = sr.OpenStreamForReadAsync(); streamTask.Wait(); using (System.IO.BinaryReader br = new BinaryReader(streamTask.Result)) { content = br.ReadBytes((int)streamTask.Result.Length); } return(content); }
public void Init(WebBrowser browser) { initAppUrls(); RhoLogger.InitRhoLog(); LOG.INFO("Init"); CRhoFile.recursiveCreateDir(CFilePath.join(getBlobsDirPath(), " ")); m_webBrowser = browser; m_httpServer = new CHttpServer(CFilePath.join(getRhoRootPath(), "apps")); CRhoResourceMap.deployContent(); RhoRuby.Init(m_webBrowser); DBAdapter.initAttrManager(); LOG.INFO("Starting sync engine..."); SyncThread sync = null; try{ sync = SyncThread.Create(); }catch (Exception exc) { LOG.ERROR("Create sync failed.", exc); } if (sync != null) { //sync.setStatusListener(this); } RhoRuby.InitApp(); RhoRuby.call_config_conflicts(); RHOCONF().conflictsResolved(); }
private void saveToFile(String szName) { m_mapChangedValues.put(szName, getString(szName)); String strData = saveChangesToString(); CRhoFile.writeStringToFile(getConfFilePath() + CONF_CHANGES, strData); }
public void conflictsResolved() { if (m_mapConflictedValues.size() == 0) { return; } String strTimestamp = CRhoFile.readStringFromResourceFile(CONF_FILENAME + CONF_TIMESTAMP); setString(CONF_TIMESTAMP_PROP, strTimestamp, true); m_mapConflictedValues.clear(); }
public void stopApp() { string[] ar1 = CRhoFile.enumDirectory("db"); RhoRuby.Stop(); SyncThread.getInstance().Destroy(); RhoLogger.close(); m_UIWaitEvent.Close(); string[] ar2 = CRhoFile.enumDirectory("db"); int i = 0; //net::CAsyncHttp::Destroy(); }
public void close(){ if ( m_pFile != null ){ try{ m_pFile.close(); }catch(Exception ){} m_pFile = null; } if ( m_pPosFile != null ){ try{ m_pPosFile.close(); }catch(Exception ){} m_pPosFile = null; } m_nCirclePos = -1; m_nFileLogSize = 0; }
public static void deployContent() { String newMap = CRhoFile.readStringFromResourceFile(RHODESAPP().canonicalizeRhoPath("RhoBundleMap.txt")); String curMap = CRhoFile.readStringFromFile(RHODESAPP().canonicalizeRhoPath("RhoBundleMap.txt")); if (curMap == "") { copyMap(newMap); } else if (curMap != newMap) { clearMap(curMap); copyMap(newMap); } }
private static void clearMap(String strMap) { string[] files = strMap.Split('\n'); for (int i = 0; i < files.Length - 1; i++) { String[] values = files[i].Split('|'); String strFile = RHODESAPP().canonicalizeRhoPath(values[0]); if (CRhoFile.isFileExist(strFile)) { CRhoFile.deleteFile(strFile); } } }
public static void InitRhoConf() { m_Instance = new RhoConf(); String szRootPath = ""; try{ CRhoFile.recursiveCreateDir(CRhodesApp.getRhoRootPath()); szRootPath = CRhodesApp.getRhoRootPath(); }catch (Exception) {} m_Instance.setConfFilePath(szRootPath + CONF_FILENAME); m_Instance.setRhoRootPath(szRootPath); }
public static void deployContent() { String newMap = CRhoFile.readStringFromResourceFile("RhoBundleMap.txt"); String curMap = CRhoFile.readStringFromFile("RhoBundleMap.txt"); if (curMap == "") { copyMap(newMap); } else if (curMap != newMap) { clearMap(curMap); copyMap(newMap); } }
private static void copyMap(String strMap) { string[] files = strMap.Split('\n'); for (int i = 0; i < files.Length - 1; i++) { String[] values = files[i].Split('|'); String strFile = values[0]; CRhoFile.recursiveCreateDir(strFile); CRhoFile.writeDataToFile(strFile, CRhoFile.readResourceFile(strFile)); } CRhoFile.writeStringToFile("RhoBundleMap.txt", strMap); }
private static void clearMap(String strMap) { string[] files = strMap.Split('\n'); for (int i = 0; i < files.Length - 1; i++) { String[] values = files[i].Split('|'); String strFile = values[0]; if (CRhoFile.isFileExist(strFile)) { CRhoFile.deleteFile(strFile); } } }
public static byte[] readResourceFile(String path) { byte[] content = new byte[0]; path = CFilePath.removeFirstSlash(path); if (!CRhoFile.isResourceFileExist(path)) { return(content); } StreamResourceInfo sr = Application.GetResourceStream(new Uri(path, UriKind.Relative)); using (System.IO.BinaryReader br = new BinaryReader(sr.Stream)) { content = br.ReadBytes((int)sr.Stream.Length); } return(content); }
private static void copyMap(String strMap) { string[] files = strMap.Split('\n'); for (int i = 0; i < files.Length - 1; i++) { String[] values = files[i].Split('|'); String strFile = values[0]; String strDstFile = values[1]; System.Diagnostics.Debugger.Log(0, "", strDstFile + "\n"); CRhoFile.recursiveCreateDir(strDstFile); CRhoFile.writeDataToFile(strDstFile, CRhoFile.readResourceFile(strFile)); } CRhoFile.writeStringToFile("RhoBundleMap.txt", strMap); }
public static String readStringFromResourceFile(String path) { string content = ""; path = CFilePath.removeFirstSlash(path); if (!CRhoFile.isResourceFileExist(path)) { return(content); } StreamResourceInfo sr = Application.GetResourceStream(new Uri(path, UriKind.Relative)); using (System.IO.BinaryReader br = new BinaryReader(sr.Stream)) { char[] str = br.ReadChars((int)sr.Stream.Length); content = new string(str); } return(content); }
public void writeLogMessage(String strMsg) { try{ int len = strMsg.length(); if ( m_pFile == null ) m_pFile = new CRhoFile(); if ( !m_pFile.isOpened() ){ m_pFile.open( getLogConf().getLogFilePath(), CRhoFile.EOpenModes.OpenForAppend ); m_nFileLogSize = (int)m_pFile.size(); loadLogPosition(); } if ( getLogConf().getMaxLogFileSize() > 0 ) { if ( ( m_nCirclePos >= 0 && m_nCirclePos + len > getLogConf().getMaxLogFileSize() ) || ( m_nCirclePos < 0 && m_nFileLogSize + len > getLogConf().getMaxLogFileSize() ) ) { m_pFile.movePosToStart(); m_nFileLogSize = 0; m_nCirclePos = 0; } } //int nWritten = m_pFile.writeString(strMsg); m_pFile.writeString(strMsg); m_pFile.flush(); if ( m_nCirclePos >= 0 ) m_nCirclePos += len; else m_nFileLogSize += len; saveLogPosition(); }catch(Exception exc){ log(exc.Message); } }
public CFileInputStream(CRhoFile oFile) { m_oFile = oFile; }
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)); }
public override Stream OpenInputFileStream(string path, FileMode mode, FileAccess access, FileShare share) { //TODO: OpenInputFileStream with params Stream st = null; if (access == FileAccess.Read) return OpenInputFileStream(path); else { CRhoFile file = new CRhoFile(); file.open(path, CRhoFile.EOpenModes.OpenForReadWrite); st = file.getStream(); } if (st == null) throw new System.IO.FileNotFoundException(); return st; }
public override Stream OpenInputFileStream(string path, FileMode mode, FileAccess access, FileShare share) { //TODO: OpenInputFileStream with params Stream st = null; if (access == FileAccess.Read) { st = OpenInputFileStream(path); if (st == null) { CRhoFile file = new CRhoFile(); file.open(path, CRhoFile.EOpenModes.OpenReadOnly); st = file.getStream(); } } else { CRhoFile file = new CRhoFile(); file.open(path, CRhoFile.EOpenModes.OpenForReadWrite); st = file.getStream(); } return st; }
private void loadLogPosition() { if ( m_pPosFile == null ) m_pPosFile = new CRhoFile(); if ( !m_pPosFile.isOpened() ){ String strPosPath = getLogConf().getLogFilePath() + "_pos"; m_pPosFile.open( strPosPath, CRhoFile.EOpenModes.OpenForReadWrite ); } if (!m_pPosFile.isOpened()) return; m_pPosFile.movePosToStart(); String strPos = m_pPosFile.readString(); if (strPos.length() == 0) return; m_nCirclePos = int.Parse(strPos); if (m_nCirclePos < 0 || m_nCirclePos > (int)m_nFileLogSize) m_nCirclePos = -1; if (m_nCirclePos >= 0) m_pFile.setPosTo(m_nCirclePos); }
private void loadFromResource() { String strSettings = CRhoFile.readStringFromResourceFile(CONF_FILENAME); loadFromString(strSettings, m_mapValues); }