protected WorkflowState PostRouterRendering(WorkflowContinuation <PostRouteWorkflowData> wc, PostRouteWorkflowData data) { string template = data.HtmlResponse.Html; IWebSessionService sessionSvc = ServiceManager.Get <IWebSessionService>(); List <string> objectNames = new List <string>() { "session", "context", "cfg" }; List <object> objects = new List <object>() { sessionSvc, data.Context, ServiceManager.Get <IAppConfigService>() }; objectNames.AddRange(appTemplateObjects.Keys); objects.AddRange(appTemplateObjects.Values); try { string newHtml = templateEngine.Parse(template, objectNames.ToArray(), objects.ToArray()); data.HtmlResponse.Html = newHtml; } catch (Exception ex) { // ServiceManager.Get<ILoggerService>().Log(ex); ServiceManager.Get <ISemanticProcessor>().ProcessInstance <LoggerMembrane, ST_Exception>(ex2 => ex2.Exception = ex); } return(WorkflowState.Continue); }
public static WorkflowState StaticResponse( WorkflowContinuation <HttpListenerContext> workflowContinuation, HttpListenerContext context) { // Get the request. HttpListenerRequest request = context.Request; HttpListenerResponse response = context.Response; // Get the path, everything up to the first ? and excluding the leading "/" string path = request.RawUrl.LeftOf("?").RightOf("/"); string ext = path.RightOfRightmostOf('.'); FileExtensionHandler extHandler; if (extensionLoaderMap.TryGetValue(ext, out extHandler)) { byte[] data = extHandler.Loader(context, path, ext); response.ContentEncoding = Encoding.UTF8; context.Response.ContentType = extHandler.ContentType; context.Response.ContentLength64 = data.Length; context.Response.OutputStream.Write(data, 0, data.Length); response.StatusCode = 200; // OK response.OutputStream.Close(); } return(WorkflowState.Continue); }
/// <summary> /// Only intranet IP addresses are allowed. /// </summary> public static WorkflowState WhiteList(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper) { string url = wrapper.Context.Request.RemoteEndPoint.ToString(); bool valid = url.StartsWith("192.168") || url.StartsWith("127.0.0.1") || url.StartsWith("[::1]"); WorkflowState ret = valid ? WorkflowState.Continue : WorkflowState.Abort; return(ret); }
protected WorkflowState PostRouterInjectLayout(WorkflowContinuation <PostRouteWorkflowData> wc, PostRouteWorkflowData data) { string websitePath = ServiceManager.Get <IAppConfigService>().GetValue("WebsitePath"); string text = File.ReadAllText(Path.Combine(websitePath, "Layout\\_layout.html")); data.HtmlResponse.Html = text.Replace("<% content %>", data.HtmlResponse.Html); return(WorkflowState.Continue); }
/// <summary> /// Final step is to actually issue the response. /// </summary> public static WorkflowState Responder(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper) { wrapper.Stopwatch.Stop(); Server.CumulativeTime += wrapper.Stopwatch.ElapsedTicks; ++Server.Samples; wrapper.Context.Response.ContentEncoding = wrapper.PendingResponse.Encoding; wrapper.Context.Response.ContentType = wrapper.PendingResponse.MimeType; wrapper.Context.Response.ContentLength64 = wrapper.PendingResponse.Data.Length; wrapper.Context.Response.OutputStream.Write(wrapper.PendingResponse.Data, 0, wrapper.PendingResponse.Data.Length); wrapper.Context.Response.StatusCode = 200; // OK wrapper.Context.Response.Close(); return(WorkflowState.Continue); }
public static WorkflowState CsrfInjector(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper) { PendingPageResponse pageResponse = wrapper.PendingResponse as PendingPageResponse; if (pageResponse != null) { // For form postbacks. pageResponse.Html = pageResponse.Html.Replace("%AntiForgeryToken%", "<input name=" + "csrf".SingleQuote() + " type='hidden' value=" + wrapper.Session["_CSRF_"].ToString().SingleQuote() + " id='__csrf__'/>"); // For AJAX calls where the CSRF is in the RequestVerificationToken header: pageResponse.Html = pageResponse.Html.Replace("%CsrfValue%", wrapper.Session["_CSRF_"].ToString().SingleQuote()); } return(WorkflowState.Continue); }
/// <summary> /// Apply the Razor view engine to a page response. /// </summary> public static WorkflowState ViewEngine(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper) { PendingPageResponse pageResponse = wrapper.PendingResponse as PendingPageResponse; // Only send page responses to the templating engine. if (pageResponse != null) { string html = pageResponse.Html; string templateKey = html.GetHashCode().ToString(); // pageResponse.Html = Engine.Razor.RunCompile(html, templateKey, null, new { /* your dynamic model */ }); try { pageResponse.Html = Engine.Razor.RunCompile(html, templateKey, null, new { People = codeProject2015Mvp }); } catch (Exception ex) { // Helps with debugging runtime compilation errors! Console.WriteLine(ex.Message); } } return(WorkflowState.Continue); }
protected WorkflowState PreRouter(WorkflowContinuation <PreRouteWorkflowData> wc, PreRouteWorkflowData data) { return(WorkflowState.Continue); }
public static WorkflowState LogHit(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper) { Console.Write("."); return(WorkflowState.Continue); }
/// <summary> /// A workflow item, implementing a simple instrumentation of the client IP address, port, and URL. /// </summary> public static WorkflowState LogIPAddress(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper) { Console.WriteLine(wrapper.Context.Request.RemoteEndPoint.ToString() + " : " + wrapper.Context.Request.RawUrl); return(WorkflowState.Continue); }
protected WorkflowState PostRouterRendering(WorkflowContinuation<PostRouteWorkflowData> wc, PostRouteWorkflowData data) { string template = data.HtmlResponse.Html; IWebSessionService sessionSvc = ServiceManager.Get<IWebSessionService>(); List<string> objectNames = new List<string>() { "session", "context", "cfg" }; List<object> objects = new List<object>() { sessionSvc, data.Context, ServiceManager.Get<IAppConfigService>() }; objectNames.AddRange(appTemplateObjects.Keys); objects.AddRange(appTemplateObjects.Values); try { string newHtml = templateEngine.Parse(template, objectNames.ToArray(), objects.ToArray()); data.HtmlResponse.Html = newHtml; } catch (Exception ex) { // ServiceManager.Get<ILoggerService>().Log(ex); ServiceManager.Get<ISemanticProcessor>().ProcessInstance<LoggerMembrane, ST_Exception>(ex2 => ex2.Exception = ex); } return WorkflowState.Continue; }
protected WorkflowState PostRouterInjectLayout(WorkflowContinuation<PostRouteWorkflowData> wc, PostRouteWorkflowData data) { string websitePath = ServiceManager.Get<IAppConfigService>().GetValue("WebsitePath"); string text = File.ReadAllText(Path.Combine(websitePath, "Layout\\_layout.html")); data.HtmlResponse.Html = text.Replace("<% content %>", data.HtmlResponse.Html); return WorkflowState.Continue; }
protected WorkflowState PreRouter(WorkflowContinuation<PreRouteWorkflowData> wc, PreRouteWorkflowData data) { return WorkflowState.Continue; }
/// <summary> /// A workflow item, implementing a simple instrumentation of the client IP address, port, and URL. /// </summary> public static WorkflowState LogIPAddress(WorkflowContinuation <HttpListenerContext> workflowContinuation, HttpListenerContext context) { Console.WriteLine(context.Request.RemoteEndPoint.ToString() + " : " + context.Request.RawUrl); return(WorkflowState.Continue); }