Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        private void saveToFile(String szName)
        {
            m_mapChangedValues.put(szName, getString(szName));

            String strData = saveChangesToString();

            CRhoFile.writeStringToFile(getConfFilePath() + CONF_CHANGES, strData);
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
 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;
 }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
0
        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);
                }
            }
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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);
                }
            }
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
	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);
		}
	}
Exemplo n.º 20
0
 public CFileInputStream(CRhoFile oFile)
 {
     m_oFile = oFile;
 }
Exemplo n.º 21
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));
	    }
        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;
        }
Exemplo n.º 23
0
 public CFileInputStream(CRhoFile oFile)
 {
     m_oFile = oFile;
 }
        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;
        }
Exemplo n.º 25
0
	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);
	}
Exemplo n.º 26
0
        private void loadFromResource()
        {
            String strSettings = CRhoFile.readStringFromResourceFile(CONF_FILENAME);

            loadFromString(strSettings, m_mapValues);
        }