예제 #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);
        }
예제 #2
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);
            }
        }
예제 #3
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)));
        }
예제 #4
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);
            }
        }
예제 #5
0
        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);
        }
예제 #6
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";
            }
        }
예제 #7
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();
            }
        }