コード例 #1
0
ファイル: HttpServer.cs プロジェクト: joelbm24/rhodes
        bool dispatch(String uri, CRoute route)
        {
            if (isknowntype(uri))
            {
                return(false);
            }

            // Trying to parse route
            if (!parse_route(uri, route))
            {
                return(false);
            }

            // Convert CamelCase to underscore_case
            String controllerName = "";

            for (int i = 0; i < route.model.Length; i++)
            {
                if (Char.IsUpper(route.model[i]) && i > 0)
                {
                    controllerName += '_';
                }

                controllerName += route.model[i];
            }
            controllerName = controllerName.ToLower();

            String model_name_controller = m_root + "/" + route.application + "/" + route.model + "/" + controllerName + "_controller.rb";
            String controller            = m_root + "/" + route.application + "/" + route.model + "/controller.rb";

            return(CRhoFile.isResourceFileExist(model_name_controller) || CRhoFile.isResourceFileExist(controller));
        }
コード例 #2
0
 public override bool FileExists(string path)
 {
     if (path == "")
     {
         return(false);
     }
     return(CRhoFile.isResourceFileExist(path) || CRhoFile.isFileExist(path));
 }
コード例 #3
0
ファイル: HttpServer.cs プロジェクト: ycaihua/rhodes
        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);
        }
コード例 #4
0
ファイル: RhoKernelOps.cs プロジェクト: wurlinc/rhodes
        public static Object __rho_exist_in_resources(Object /*!*/ self, String path)
        {
            Object res = null;

            try
            {
                res = CRhoFile.isResourceFileExist(path);
            }
            catch (Exception ex)
            {
                LOG.HandleRubyException(ex, RhoRuby.rubyContext.CurrentException, "__rho_exist_in_resources");
            }

            return(res);
        }
コード例 #5
0
ファイル: HttpServer.cs プロジェクト: imustardsoft/rhodes
        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);
        }
コード例 #6
0
ファイル: HttpServer.cs プロジェクト: joelbm24/rhodes
        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));
        }
コード例 #7
0
ファイル: HttpServer.cs プロジェクト: ycaihua/rhodes
            public void execute()
            {
                String      strUrl = "";
                IDictionary result = null;

                if (m_nCommand == scDispatch)
                {
                    result = m_Parent.processDispatch(m_route, m_method, m_uri, m_headers, m_query, m_body);
                    strUrl = result[RESPONSE_BODY_FILEPATH].ToString();

                    if (isAjaxRequest() && result[RESPONSE_STATUS].ToString().equals(HTTP_REDIRECT_CODE))
                    {
                        IDictionary headers = new Dictionary <String, String>();
                        headers["X-Requested-With"] = "XMLHttpRequest";
                        if (!RHODESAPP().HttpServer.processBrowserRequest(
                                "GET",
                                new Uri(strUrl, UriKind.Relative),
                                headers,
                                new Dictionary <String, String>(),
                                m_strAjaxContext,
                                m_iTabIndex
                                ))
                        {
                            LOG.ERROR("Ajax request redirection failed.");
                        }
                        return;
                    }
                }
                else if (m_nCommand == scIndex)
                {
                    result = m_Parent.processIndex(m_route, m_method, m_uri, m_headers, m_query, m_body);
                    strUrl = result[RESPONSE_BODY_FILEPATH].ToString();
                }

                if (!isAjaxRequest())
                {
                    RHODESAPP().processWebNavigate(strUrl, -1);
                }
                else
                {
                    String res = CRhoFile.isResourceFileExist(strUrl) ? CRhoFile.readStringFromResourceFile(strUrl) : CRhoFile.readFileToString(strUrl);


                    IDictionary   headers     = new Dictionary <String, String>();
                    StringBuilder jsonHeaders = new StringBuilder();
                    foreach (object key in result.Keys)
                    {
                        if (
                            key.ToString().startsWith(PARAM_PREFIX_REQ) ||
                            key.ToString().startsWith(PARAM_PREFIX_RESP) ||
                            key.ToString().equals(RESPONSE_STATUS_MESSAGE) ||
                            key.ToString().equals(RESPONSE_STATUS)
                            )
                        {
                            continue;
                        }
                        headers[key.ToString()] = result[key].ToString();
                        jsonHeaders.AppendFormat("{0}\"{1}\": \"{2}\"",
                                                 (0 < jsonHeaders.Length) ? ", " : "",
                                                 key.ToString(), result[key].ToString());
                    }

                    String[] args = new String[5];
                    args[0] = m_strAjaxContext;
                    args[1] = res;
                    args[2] = "{" + jsonHeaders + "}";
                    args[3] = result[RESPONSE_STATUS_MESSAGE] != null ? result[RESPONSE_STATUS_MESSAGE].ToString() : "";
                    args[4] = result[RESPONSE_STATUS] != null ? result[RESPONSE_STATUS].ToString() : "";

                    RHODESAPP().processInvokeScriptArgs(AJAX_CALLBACK_FUNCNAME, args, m_iTabIndex);
                }
            }