public Core(Server server, HttpContext context, string viewstate = "", string type = "") { Server = server; Context = context; Request = context.Request; Response = context.Response; Session = context.Session; Sql = new Sql(this); Util = new Utility.Util(this); User = new User(); //load viewstate if (useViewState == true) { ViewStateId = viewstate; if(ViewStateId == "") { ViewStateId = Util.Str.CreateID(); } if (Session["viewstate-" + ViewStateId] != null) { ViewState vs = new ViewState(); vs = (ViewState)Util.Serializer.ReadObject(Util.Str.GetString(Session["viewstate-" + ViewStateId]), vs.GetType()); Page = vs.Page; Elements = new Elements(this, Page.themeFolder); }else { Page = new Page(); } }else { Page = new Page(); } if (Session["user"] != null) { User = (User)Util.Serializer.ReadObject(Util.Str.GetString(Session["user"]), User.GetType()); } //load references to Core R Sql.Load(); Page.Load(this); User.Load(this); //generate visitor id if (User.visitorId == "" || User.visitorId == null) { User.visitorId = Util.Str.CreateID(); } //detect request type & host type if (type == "service") { isWebService = true; } if (Request.Host.Value.IndexOf("localhost") >= 0 || Request.Host.Value.IndexOf("192.168.") >= 0) { isLocal = true; } }
public void Configure(IApplicationBuilder app) { //load application-wide memory store Server server = new Server(); //handle static files var options = new StaticFileOptions {ContentTypeProvider = new FileExtensionContentTypeProvider()}; ((FileExtensionContentTypeProvider)options.ContentTypeProvider).Mappings.Add( new KeyValuePair<string, string>(".less", "text/css")); app.UseStaticFiles(options); //exception handling var errOptions = new ErrorPageOptions(); errOptions.ShowSourceCode = true; errOptions.SourceCodeLineCount = 10; errOptions.SetDefaultVisibility(true); errOptions.ShowExceptionDetails = true; errOptions.ShowEnvironment = true; app.UseErrorPage(); //use session (3 hour timeout) app.UseInMemorySession(configure: s => s.IdleTimeout = TimeSpan.FromMinutes(60*3)); //run application app.Run(async (context) => { var strings = new Utility.Str(null); var requestStart = DateTime.Now; DateTime requestEnd; TimeSpan tspan; var path = context.Request.Path.ToString(); var paths = path.Split("/"[0]).Skip(1).ToArray(); String requestType = ""; var extension = strings.getFileExtension(path); server.requestCount += 1; if (paths.Length > 1) { if(paths[0]=="rennder") { //run a web service via ajax (e.g. /rennder/namespace/class/function) IFormCollection form = null; if(context.Request.ContentType != null) { if (context.Request.ContentType.IndexOf("application/x-www-form-urlencoded") >= 0) { }else if (context.Request.ContentType.IndexOf("multipart/form-data") >= 0) { //get files collection from form data form = await context.Request.ReadFormAsync(); } } //start the Web Service engine var ws = new Pipeline.WebService(server, context, paths, form); requestType = "service"; } } if(requestType == "" && extension == "") { //initial page request var r = new Pipeline.App(server, context); requestType = "page"; } if(requestType == "" && extension != "") { //file requestType = "file"; } if(requestType == "") { context.Response.ContentType = "text/html"; await context.Response.WriteAsync("Rennder is a drag & drop website CMS platform built for Windows, Linux, & Mac OSX."); } requestEnd = DateTime.Now; tspan = requestEnd - requestStart; server.requestTime += (tspan.Seconds); Console.WriteLine("GET {0} {1} ms {2}", context.Request.Path, tspan.Milliseconds, requestType); }); }