public static LocalizePath ( IEnvironment env, string path ) : string | ||
env | IEnvironment | The environment data with information about preferred languages |
path | string | The file path of a resource |
Результат | string |
public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // path = /wifi/... //m_log.DebugFormat("[Wifi]: path = {0}", path); //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint); //foreach (object o in httpRequest.Query.Keys) // m_log.DebugFormat(" >> {0}={1}", o, httpRequest.Query[o]); string resource = GetParam(path); //m_log.DebugFormat("[Wifi]: resource {0}", resource); resource = Uri.UnescapeDataString(resource).Trim(WebAppUtils.DirectorySeparatorChars); Request request = RequestFactory.CreateRequest(resource, httpRequest, Localization.GetLanguageInfo(httpRequest.Headers.Get("accept-language"))); Environment env = new Environment(request); if (resource == string.Empty || resource.StartsWith("index.")) { if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero) { m_WebApp.Services.ComputeStatistics(); } httpResponse.ContentType = "text/html"; return(WebAppUtils.StringToBytes(m_WebApp.Services.DefaultRequest(env))); } else { string resourcePath = System.IO.Path.Combine(WebApp.DocsPath, resource); string type = WebAppUtils.GetContentType(resource); httpResponse.ContentType = type; //m_log.DebugFormat("[Wifi]: ContentType {0}", type); if (type.StartsWith("image")) { return(WebAppUtils.ReadBinaryResource(resourcePath)); } if (type.StartsWith("application")) { string res = WebAppUtils.ReadTextResource(resourcePath, true); return(WebAppUtils.StringToBytes(res)); } if (type.StartsWith("text")) { if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero) { m_WebApp.Services.ComputeStatistics(); } resourcePath = Localization.LocalizePath(env, resource); Processor p = new Processor(m_WebApp.WifiScriptFace, env); string res = p.Process(WebAppUtils.ReadTextResource(resourcePath)); if (res == string.Empty) { res = m_WebApp.Services.DefaultRequest(env); } return(WebAppUtils.StringToBytes(res)); } } httpResponse.ContentType = "text/plain"; string result = "Boo!"; return(WebAppUtils.StringToBytes(result)); }
public string LocalizePath(IEnvironment env, string path) { return(Localization.LocalizePath(env, path)); }