public void Configuration(IAppBuilder app) { #if DEBUG app.UseErrorPage(); #endif var staticWebContentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\WebStaticContent"; var physicalFileSystem = new PhysicalFileSystem(staticWebContentPath); var options = new FileServerOptions(); options.EnableDefaultFiles = true; options.FileSystem = physicalFileSystem; options.EnableDirectoryBrowsing = true; options.StaticFileOptions.FileSystem = physicalFileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" }; var host = Cake23Host.GetInstance(); if (host.AllowCORS) { app.UseCors(CorsOptions.AllowAll); } app.UseFileServer(options); app.MapSignalR(); HttpConfiguration config = new HttpConfiguration(); var hostName = Cake23Host.GetInstance().Connection.UserName; config.Routes.MapHttpRoute("Templates", "client/{templateName}", new { controller = "Template", templateName = "index", userName = hostName }); config.Routes.MapHttpRoute("Remoteria", "remote/{templateName}/{userName}", new { controller = "Remote", templateName = "index", userName = hostName }); app.UseWebApi(config); }
public static Cake23Host GetInstance() { if (_singleton == null) { _singleton = new Cake23Host(); } return(_singleton); }
public HttpResponseMessage Get(string userName, string templateName) { try { var templatesPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\WebTemplates\\remote"; var path = templatesPath + "\\" + templateName + ".cshtml"; var index = templatesPath + "\\index.cshtml"; if (File.Exists(path) && path != index) { var response = new HttpResponseMessage(HttpStatusCode.OK); var template = File.ReadAllText(path); var result = Engine.Razor.RunCompile(template, templateName, null, new { Host = Cake23Host.GetInstance(), UserName = userName }); response.Content = new StringContent(result, System.Text.Encoding.UTF8, "text/html"); return(response); } else if (File.Exists(index)) { var response = new HttpResponseMessage(HttpStatusCode.OK); var template = File.ReadAllText(index); var result = Engine.Razor.RunCompile(template, "remoteIndex", null, new { Host = Cake23Host.GetInstance(), UserName = userName, FileNames = Directory.GetFiles(templatesPath, "*.cshtml").Select(filepath => Path.GetFileNameWithoutExtension(filepath)) }); response.Content = new StringContent(result, System.Text.Encoding.UTF8, "text/html"); return(response); } else { // Directory.GetFiles(templatesPath, "*.cshtml").Select(filepath => Path.GetFileNameWithoutExtension(filepath)); return(new HttpResponseMessage(HttpStatusCode.NotFound)); } } catch (Exception e) { return(new HttpResponseMessage(HttpStatusCode.NotFound)); } }