String processDispatch(CRoute route, String method, String uri, String query, String body) { 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(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(strFilePath); }
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)); }
bool parse_route(String uri, CRoute route) { if (uri.StartsWith(RHODESAPP().getHomeUrl())) { uri = uri.Substring(RHODESAPP().getHomeUrl().Length + 1); } if (uri.StartsWith(m_root)) { uri = uri.Substring(m_root.Length + 1); } else if (uri.StartsWith("/")) { uri = uri.Remove(0, 1); } String[] arParts = uri.Split('/'); if (arParts.Length > 0) { route.application = arParts[0]; } if (arParts.Length < 2) { return(false); } route.model = arParts[1]; if (arParts.Length < 3) { return(true); } String aoi = arParts[2]; if (CRoute.isid(aoi)) { route.id = aoi; if (arParts.Length > 3) { route.action = arParts[3]; } } else { if (arParts.Length > 3) { route.id = arParts[3]; } route.action = aoi; } return(true); }
public boolean processBrowserRequest(Uri uri) { if (!uri.OriginalString.StartsWith(RHODESAPP().getHomeUrl()) && (uri.IsAbsoluteUri || uri.OriginalString.StartsWith("res:"))) { return(false); } String query = ""; String url = uri.OriginalString; url = url.StartsWith(RHODESAPP().getHomeUrl()) ? url.substring(RHODESAPP().getHomeUrl().length()) : url; int nFrag = url.LastIndexOf('#'); if (nFrag >= 0) { url = url.Substring(0, nFrag); } int nQuery = url.IndexOf('?'); if (nQuery >= 0) { query = url.Substring(nQuery + 1); url = url.Substring(0, nQuery); } if (url.EndsWith(".gen.html") || (isknowntype(url) && url.StartsWith(m_root))) { return(false); } CRoute route = new CRoute(); if (dispatch(url, route)) { addQueueCommand(new CServerCommand(this, route, "GET", url, query, "", CServerCommand.scDispatch)); return(true); } String fullPath = url.StartsWith(m_root) ? url : CFilePath.join(m_root, url); String strIndexFile = getIndex(fullPath); if (strIndexFile.Length > 0) { addQueueCommand(new CServerCommand(this, route, "GET", url, query, "", CServerCommand.scIndex)); return(true); } return(false); }
public CServerCommand(CHttpServer Parent, CRoute route, String method, String uri, String query, String body, int nCommand) { m_Parent = Parent; m_method = method; m_uri = uri; m_query = query; m_body = body; m_route = route; m_nCommand = nCommand; }
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); }
public bool call_ruby_method(String uri, String body, out String strReply) { CRoute route = new CRoute(); strReply = String.Empty; if (!dispatch(uri, route)) { if (route.application.equalsIgnoreCase("system")) { if (route.model.equalsIgnoreCase("geolocation")) { //TODO: geolocation //showGeoLocation(); return(true); } else if (route.model.equalsIgnoreCase("loadserversources")) { RhoRuby.loadServerSources(body); return(true); } else if (route.model.equalsIgnoreCase("loadallsyncsources")) { RhoRuby.loadAllSyncSources(); return(true); } else if (route.model.equalsIgnoreCase("resetDBOnSyncUserChanged")) { RhoRuby.resetDBOnSyncUserChanged(); return(true); } } return(false); } Dictionary <String, String> headers = new Dictionary <String, String>(); headers.Add("Content-Type", "application/x-www-form-urlencoded"); Object rhoReq = create_request_hash(route, "POST", uri, String.Empty, headers, body); Object rhoResp = RhoRuby.callServe(rhoReq); strReply = getResponseBodyString(rhoResp); return(true); }
Object create_request_hash(CRoute route, String method, String uri, String query, Dictionary <String, String> headers, String body) { Object hash = RhoRuby.createHash(); if (route != null) { RhoRuby.hashAdd(hash, "application", route.application); RhoRuby.hashAdd(hash, "model", route.model); if (route.action.Length > 0) { RhoRuby.hashAdd(hash, "action", route.action); } if (route.id.Length > 0) { RhoRuby.hashAdd(hash, "id", route.id); } } RhoRuby.hashAdd(hash, "request-method", method); RhoRuby.hashAdd(hash, "request-uri", uri); RhoRuby.hashAdd(hash, "request-query", query); Object hash_headers = RhoRuby.createHash(); if (headers != null) { Dictionary <String, String> .Enumerator hashEnum = headers.GetEnumerator(); while (hashEnum.MoveNext()) { RhoRuby.hashAdd(hash_headers, hashEnum.Current.Key, hashEnum.Current.Value); } } RhoRuby.hashAdd(hash, "headers", hash_headers); if (body.Length > 0) { RhoRuby.hashAdd(hash, "request-body", body); } return(hash); }
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); }
public CServerCommand(CHttpServer Parent, CRoute route, String method, String uri, IDictionary headers, IDictionary data, int nCommand, String strAjaxContext, int tabIndex) { m_Parent = Parent; m_method = (null != method) ? method.toUpperCase() : "GET"; m_uri = (0 <= uri.indexOf('?')) ? uri.substring(0, uri.indexOf('?')) : uri; m_route = route; m_nCommand = nCommand; m_strAjaxContext = strAjaxContext; m_iTabIndex = tabIndex; m_body = ""; m_headers = new Dictionary <String, String>(); if (null != headers) { foreach (object key in headers.Keys) { m_headers[key.ToString()] = headers[key].ToString(); } } // Query parameters from URL are added first, then data parameters added. m_query = (0 <= uri.indexOf('?')) ? uri.substring(uri.indexOf('?') + 1) : ""; if (null != data) { StringBuilder sb = new StringBuilder(m_query); foreach (object key in data.Keys) { if (0 < sb.Length) { sb.Append("&"); } sb.Append(key.ToString() + "=" + (null != data[key] ? data[key].ToString() : "")); } m_query = sb.ToString(); } }
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); }
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); }
public boolean processBrowserRequest(String reqType, Uri uri, IDictionary headers, IDictionary data, String strAjaxContext, int tabIndex = -1) { boolean bAjaxCall = !(strAjaxContext == null || strAjaxContext.length() == 0); if (!uri.OriginalString.StartsWith(RHODESAPP().getHomeUrl()) && (uri.IsAbsoluteUri || uri.OriginalString.StartsWith("res:"))) return false; String query = ""; String url = uri.OriginalString; url = url.StartsWith(RHODESAPP().getHomeUrl()) ? url.substring(RHODESAPP().getHomeUrl().length()) : url; int nFrag = url.LastIndexOf('#'); if (nFrag >= 0) url = url.Substring(0, nFrag); int nQuery = url.IndexOf('?'); if (nQuery >= 0) { query = url.Substring(nQuery + 1); url = url.Substring(0, nQuery); } if (url.EndsWith(".gen.html") || (isknowntype(url) && url.StartsWith(m_root))) return false; CRoute route = new CRoute(); if (dispatch(url, route)) { addQueueCommand(new CServerCommand(this, route, reqType, url + (0 < query.Length ? ("?"+query) : ""), headers, data, CServerCommand.scDispatch, strAjaxContext, tabIndex)); //addQueueCommand(new CServerCommand(this, route, bAjaxCall ? "GET" : "GET", url, query, "", CServerCommand.scDispatch, strAjaxContext)); return true; } String fullPath = url.StartsWith(m_root) ? url : CFilePath.join(m_root, url); String strIndexFile = getIndex(fullPath); if (strIndexFile.Length > 0) { addQueueCommand(new CServerCommand(this, route, reqType, url, headers, data, CServerCommand.scIndex, strAjaxContext, tabIndex)); //addQueueCommand(new CServerCommand(this, route, bAjaxCall ? "GET" : "GET", url, query, "", CServerCommand.scIndex, strAjaxContext)); return true; } return false; }
public boolean processBrowserRequest(Uri uri) { if (!uri.OriginalString.StartsWith(RHODESAPP().getHomeUrl()) && (uri.IsAbsoluteUri || uri.OriginalString.StartsWith("res:"))) return false; String query = ""; String url = uri.OriginalString; url = url.StartsWith(RHODESAPP().getHomeUrl()) ? url.substring(RHODESAPP().getHomeUrl().length()) : url; int nFrag = url.LastIndexOf('#'); if (nFrag >= 0) url = url.Substring(0, nFrag); int nQuery = url.IndexOf('?'); if (nQuery >= 0) { query = url.Substring(nQuery + 1); url = url.Substring(0, nQuery); } if (url.EndsWith(".gen.html") || (isknowntype(url) && url.StartsWith(m_root))) return false; CRoute route = new CRoute(); if (dispatch(url, route)) { addQueueCommand(new CServerCommand(this, route, "GET", url, query, "", CServerCommand.scDispatch)); return true; } String fullPath = url.StartsWith(m_root) ? url : CFilePath.join(m_root, url); String strIndexFile = getIndex(fullPath); if (strIndexFile.Length > 0) { addQueueCommand(new CServerCommand(this, route, "GET", url, query, "", CServerCommand.scIndex)); return true; } return false; }
/* CResponse decide(String method, String uri, String query, String body) { //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); }*/ public bool call_ruby_method(String uri, String body, out String strReply) { CRoute route = new CRoute(); strReply = String.Empty; if (!dispatch(uri, route)) { if (route.application.equalsIgnoreCase("system")) { if (route.model.equalsIgnoreCase("geolocation")) { //TODO: geolocation //showGeoLocation(); return true; } else if (route.model.equalsIgnoreCase("loadserversources")) { RhoRuby.loadServerSources(body); return true; } else if (route.model.equalsIgnoreCase("loadallsyncsources")) { RhoRuby.loadAllSyncSources(); return true; } else if (route.model.equalsIgnoreCase("resetDBOnSyncUserChanged")) { RhoRuby.resetDBOnSyncUserChanged(); return true; } } return false; } Dictionary<String, String> headers = new Dictionary<String, String>(); headers.Add("Content-Type","application/x-www-form-urlencoded"); Object rhoReq = create_request_hash(route, "POST", uri, String.Empty, headers, body); Object rhoResp = RhoRuby.callServe(rhoReq); strReply = getResponseBodyString(rhoResp); return true; }
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; }
String processDispatch(CRoute route, String method, String uri, String query, String body) { 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 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 strFilePath; }
public CServerCommand(CHttpServer Parent, CRoute route, String method, String uri, IDictionary headers, IDictionary data, int nCommand, String strAjaxContext, int tabIndex) { m_Parent = Parent; m_method = (null != method) ? method.toUpperCase() : "GET"; m_uri = (0 <= uri.indexOf('?')) ? uri.substring(0, uri.indexOf('?')) : uri; m_route = route; m_nCommand = nCommand; m_strAjaxContext = strAjaxContext; m_iTabIndex = tabIndex; m_body = ""; m_headers = new Dictionary<String, String>(); if (null != headers) { foreach (object key in headers.Keys) { m_headers[key.ToString()] = headers[key].ToString(); } } // Query parameters from URL are added first, then data parameters added. m_query = (0 <= uri.indexOf('?')) ? uri.substring(uri.indexOf('?') + 1) : ""; if (null != data) { StringBuilder sb = new StringBuilder(m_query); foreach (object key in data.Keys) { if (0 < sb.Length) sb.Append("&"); sb.Append(key.ToString() + "=" + (null != data[key] ? data[key].ToString() : "")); } m_query = sb.ToString(); } }
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; }
bool parse_route(String uri, CRoute route) { if (uri.StartsWith(RHODESAPP().getHomeUrl())) uri = uri.Substring(RHODESAPP().getHomeUrl().Length + 1); if (uri.StartsWith(m_root)) uri = uri.Substring(m_root.Length+1); else if ( uri.StartsWith("/") ) uri = uri.Remove(0, 1 ); String[] arParts = uri.Split('/'); if (arParts.Length > 0 ) route.application = arParts[0]; if (arParts.Length < 2) return false; route.model = arParts[1]; if (arParts.Length < 3) return true; String aoi = arParts[2]; if (CRoute.isid(aoi)) { route.id = aoi; if (arParts.Length > 3) route.action = arParts[3]; } else { if (arParts.Length > 3) route.id = arParts[3]; route.action = aoi; } return true; }
Object create_request_hash(CRoute route, String method, String uri, String query, Dictionary<String, String> headers, String body) { Object hash = RhoRuby.createHash(); if ( route != null ) { RhoRuby.hashAdd(hash, "application", route.application); RhoRuby.hashAdd(hash, "model", route.model); if ( route.action.Length > 0 ) RhoRuby.hashAdd(hash, "action", route.action); if ( route.id.Length > 0 ) RhoRuby.hashAdd(hash, "id", route.id); } RhoRuby.hashAdd(hash, "request-method", method); RhoRuby.hashAdd(hash, "request-uri", uri); RhoRuby.hashAdd(hash, "request-query", query); Object hash_headers = RhoRuby.createHash(); if (headers != null) { Dictionary<String, String>.Enumerator hashEnum = headers.GetEnumerator(); while (hashEnum.MoveNext()) { RhoRuby.hashAdd(hash_headers, hashEnum.Current.Key, hashEnum.Current.Value); } } RhoRuby.hashAdd(hash, "headers", hash_headers); if ( body.Length > 0 ) RhoRuby.hashAdd(hash, "request-body", body); return hash; }
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)); }
public boolean processBrowserRequest(String reqType, Uri uri, IDictionary headers, IDictionary data, String strAjaxContext, int tabIndex = -1) { boolean bAjaxCall = !(strAjaxContext == null || strAjaxContext.length() == 0); if (!uri.OriginalString.StartsWith(RHODESAPP().getHomeUrl()) && (uri.IsAbsoluteUri || uri.OriginalString.StartsWith("res:"))) { return(false); } String query = ""; String url = uri.OriginalString; url = url.StartsWith(RHODESAPP().getHomeUrl()) ? url.substring(RHODESAPP().getHomeUrl().length()) : url; int nFrag = url.LastIndexOf('#'); if (nFrag >= 0) { url = url.Substring(0, nFrag); } int nQuery = url.IndexOf('?'); if (nQuery >= 0) { query = url.Substring(nQuery + 1); url = url.Substring(0, nQuery); } if (url.EndsWith(".gen.html") || (isknowntype(url) && url.StartsWith(m_root))) { return(false); } CRoute route = new CRoute(); if (dispatch(url, route)) { addQueueCommand(new CServerCommand(this, route, reqType, url + (0 < query.Length ? ("?" + query) : ""), headers, data, CServerCommand.scDispatch, strAjaxContext, tabIndex)); //addQueueCommand(new CServerCommand(this, route, bAjaxCall ? "GET" : "GET", url, query, "", CServerCommand.scDispatch, strAjaxContext)); return(true); } String fullPath = url.StartsWith(m_root) ? url : CFilePath.join(m_root, url); String strIndexFile = getIndex(fullPath); if (strIndexFile.Length > 0) { addQueueCommand(new CServerCommand(this, route, reqType, url, headers, data, CServerCommand.scIndex, strAjaxContext, tabIndex)); //addQueueCommand(new CServerCommand(this, route, bAjaxCall ? "GET" : "GET", url, query, "", CServerCommand.scIndex, strAjaxContext)); return(true); } return(false); }