public void Configuration(IAppBuilder app) { container.Install(new ControllerInstaller(), new DefaultInstaller()); IFileSystem fileSystem = new EmbeddedResourceFileSystem("BotBrown.www.dist"); HttpConfiguration config = new HttpConfiguration(); config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); config.DependencyResolver = new WindsorDependencyResolver(container); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseFileServer(new FileServerOptions { FileSystem = fileSystem, EnableDirectoryBrowsing = true }); #if DEBUG app.UseErrorPage(); #endif //app.UseWelcomePage("/"); }
public void Configuration(IAppBuilder appBuilder) { var config = new HttpConfiguration(); var container = ContainerConfig.Build(); WebApiConfig.Register(config, container); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); appBuilder.UseAutofacMiddleware(container); appBuilder.UseAutofacWebApi(config); appBuilder.UseWebApi(config); var fileSystem = new EmbeddedResourceFileSystem(typeof(Global).Assembly, "Editor.Front"); var options = new FileServerOptions { FileSystem = fileSystem }; options.StaticFileOptions.FileSystem = fileSystem; options.StaticFileOptions.ServeUnknownFileTypes = true; appBuilder.UseFileServer(options); appBuilder.MapWebSocketPattern <EditorWebSocket>("/ws/editor/(?<documentId>[0-9A-Fa-f\\-]{36})/(?<clientId>[0-9A-Fa-f\\-]{36})", new AutofacServiceLocator(container)); }
static void embeddedFS() { string content = "test embedded resource"; string deepContent = "deep file"; var filePath = FileSystemPath.Root.AppendFile("test.txt"); var resDir = FileSystemPath.Root.AppendDirectory("resDir"); var deepFilePath = resDir.AppendFile("deepFile.txt"); EmbeddedResourceFileSystem eRscFS = new EmbeddedResourceFileSystem(Assembly.GetAssembly(typeof(Program))); Assert.True(eRscFS.Exists(filePath)); using (var stream = eRscFS.OpenFile(filePath, FileAccess.Read)) { using (var reader = new StreamReader(stream)) { string value = reader.ReadToEnd(); Assert.Equal(content, value); } } Assert.True(eRscFS.Exists(deepFilePath)); using (var stream = eRscFS.OpenFile(deepFilePath, FileAccess.Read)) { using (var reader = new StreamReader(stream)) { string value = reader.ReadToEnd(); Assert.Equal(deepContent, value); } } var entities = eRscFS.GetEntities(FileSystemPath.Root); var recentities = eRscFS.GetEntitiesRecursive(FileSystemPath.Root); ; }
public void TryGetDirInfo_with_no_matching_base_namespace() { var provider = new EmbeddedResourceFileSystem("Unknown.Namespace"); IEnumerable<IFileInfo> files; provider.TryGetDirectoryContents(string.Empty, out files).ShouldBe(false); provider.TryGetDirectoryContents("/", out files).ShouldBe(true); files.Count().ShouldBe(0); }
public void TryGetDirInfo_without_slash() { var provider = new EmbeddedResourceFileSystem("Microsoft.Owin.StaticFiles.Tests.Resources"); IEnumerable<IFileInfo> files; provider.TryGetDirectoryContents(string.Empty, out files).ShouldBe(false); provider.TryGetDirectoryContents("file", out files).ShouldBe(false); provider.TryGetDirectoryContents("file.txt", out files).ShouldBe(false); }
public void When_TryGetFileInfo_and_resource_does_not_exist_then_should_not_get_file_info() { var provider = new EmbeddedResourceFileSystem("Microsoft.Owin.FileSystems.Tests.Resources"); IFileInfo fileInfo; provider.TryGetFileInfo("/DoesNotExist.Txt", out fileInfo).ShouldBe(false); fileInfo.ShouldBe(null); }
public void TryGetDirInfo_with_no_matching_base_namespace() { var provider = new EmbeddedResourceFileSystem("Unknown.Namespace"); IEnumerable <IFileInfo> files; provider.TryGetDirectoryContents(string.Empty, out files).ShouldBe(false); provider.TryGetDirectoryContents("/", out files).ShouldBe(true); files.Count().ShouldBe(0); }
public void TryGetDirInfo_without_slash() { var provider = new EmbeddedResourceFileSystem("Microsoft.Owin.FileSystems.Tests.Resources"); IEnumerable <IFileInfo> files; provider.TryGetDirectoryContents(string.Empty, out files).ShouldBe(false); provider.TryGetDirectoryContents("file", out files).ShouldBe(false); provider.TryGetDirectoryContents("file.txt", out files).ShouldBe(false); }
private static void ConfigureStaticFiles(IAppBuilder appBuilder) { var staticFileSystem = new EmbeddedResourceFileSystem(typeof(Guncho.Site.Site).Assembly, typeof(Guncho.Site.Site).Namespace); appBuilder.UseDefaultFiles(new DefaultFilesOptions { FileSystem = staticFileSystem }); appBuilder.UseStaticFiles(new StaticFileOptions { FileSystem = staticFileSystem }); }
public void TryGetDirInfo_with_slash() { var provider = new EmbeddedResourceFileSystem("Microsoft.Owin.FileSystems.Tests.Resources"); IEnumerable<IFileInfo> files; provider.TryGetDirectoryContents("/", out files).ShouldBe(true); files.Count().ShouldBe(2); provider.TryGetDirectoryContents("/file", out files).ShouldBe(false); provider.TryGetDirectoryContents("/file/", out files).ShouldBe(false); provider.TryGetDirectoryContents("/file.txt", out files).ShouldBe(false); provider.TryGetDirectoryContents("/file/txt", out files).ShouldBe(false); }
public static IAppBuilder UseEmbeddedFiles(this IAppBuilder app, Assembly assembly, string baseNamespace) { var fileSystem = new EmbeddedResourceFileSystem(assembly, baseNamespace); var fileServerOptions = new FileServerOptions { StaticFileOptions = { ServeUnknownFileTypes = true }, FileSystem = fileSystem }; app.UseFileServer(fileServerOptions); return(app); }
public ScriptInjectionMiddlewareTests() { _host = TestServer.Create(app => { app.UseScriptInjection("/livereload.js"); IFileSystem reloadFilesystem = new EmbeddedResourceFileSystem(ContentAssembly, ContentNamespace); app.UseStaticFiles(new StaticFileOptions { RequestPath = PathString.Empty, FileSystem = reloadFilesystem, ServeUnknownFileTypes = true }); }); }
protected async Task GetErrorPage(StreamWriter writer, Exception error, SourceLocation location) { var fileSystem = new EmbeddedResourceFileSystem(typeof(WebInitializer).Assembly); string content; using (var reader = new StreamReader(fileSystem.OpenRead(PathInfo.Create("Core/error_partial.html")))) { content = await reader.ReadToEndAsync(); } var templateInfo = new StringTemplateInfo("error", content); var view = await((IViewEngine)Resolver.GetService(typeof(IViewEngine))) .CreateViewAsync(templateInfo, typeof(ErrorViewModel)).ConfigureAwait(false); if (location == null) { var modelWithoutLocation = new ErrorViewModel { ErrorMessage = error.Message, Details = error.StackTrace }; view.Render(modelWithoutLocation, new RenderingContext(writer)); return; } var templateRepository = (ITemplateRepository)this.Resolver.GetService(typeof(ITemplateRepository)); var sourceTemplate = await templateRepository.GetTemplateAsync(location.TemplateId).ConfigureAwait(false); string sourceTemplateSource; using (var reader = new StreamReader(sourceTemplate.Open())) { sourceTemplateSource = await reader.ReadToEndAsync().ConfigureAwait(false); } var model = new ErrorViewModel { TemplateId = location.TemplateId, ErrorMessage = error.Message, Details = error.StackTrace, Before = sourceTemplateSource.Substring(0, location.Index), Node = sourceTemplateSource.Substring(location.Index, location.Length), After = sourceTemplateSource.Substring(location.Index + location.Length), Text = HttpUtility.JavaScriptStringEncode(sourceTemplateSource), Range = GetRange(sourceTemplateSource, location) }; view.Render(model, new RenderingContext(writer)); }
public void When_TryGetFileInfo_and_resources_in_path_then_should_get_file_infos() { var provider = new EmbeddedResourceFileSystem("Microsoft.Owin.FileSystems.Tests"); IFileInfo fileInfo; provider.TryGetFileInfo("/Resources.File.txt", out fileInfo).ShouldBe(true); fileInfo.ShouldNotBe(null); fileInfo.LastModified.ShouldNotBe(default(DateTime)); fileInfo.Length.ShouldBeGreaterThan(0); fileInfo.IsDirectory.ShouldBe(false); fileInfo.PhysicalPath.ShouldBe(null); fileInfo.Name.ShouldBe("Resources.File.txt"); }
public void TryGetDirInfo_with_slash() { var provider = new EmbeddedResourceFileSystem("Microsoft.Owin.FileSystems.Tests.Resources"); IEnumerable <IFileInfo> files; provider.TryGetDirectoryContents("/", out files).ShouldBe(true); files.Count().ShouldBe(2); provider.TryGetDirectoryContents("/file", out files).ShouldBe(false); provider.TryGetDirectoryContents("/file/", out files).ShouldBe(false); provider.TryGetDirectoryContents("/file.txt", out files).ShouldBe(false); provider.TryGetDirectoryContents("/file/txt", out files).ShouldBe(false); }
public void Configuration(IAppBuilder app) { // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888 // If you want to enable ASP.NET Web API: // 1) Install Microsoft.AspNet.WebApi.Owin NuGet package. (ex."PM> Install-Package Microsoft.AspNet.WebApi.Owin") // 2) Import "System.Web.Http" namespace. (insert "using System.Web.Http;" at head of this file) // 3) Uncomment lines below. // After this, you can implement API controllers with attribute routing. //// Confiure ASP.NET Web API //var config = new HttpConfiguration(); //config.MapHttpAttributeRoutes(); //app.UseWebApi(config); // Configure OWIN Static Files middleware to provide contents from embedded resources. var appSettings = ConfigurationManager.AppSettings; if (appSettings["use:OwinStaticFiles"] != "false") { var fileSystem = new EmbeddedResourceFileSystem(this.GetType().Assembly, this.GetType().Namespace); app.UseDefaultFiles(new DefaultFilesOptions { FileSystem = fileSystem, DefaultFileNames = new List <string> { "index.html" } }); app.UseStaticFiles(new StaticFileOptions { FileSystem = fileSystem, ServeUnknownFileTypes = true, OnPrepareResponse = context => { var headers = context.OwinContext.Response.Headers; // If you use AngulaJS at client side, it's recomended about // appending "Cache-control: no-cache" header in response to avoid "cache tatooing". headers.Add("Cache-control", new[] { "no-cache" }); // If you want to determine which content source (embedded resouces via Owin Static Files middleware, // or local file system via IIS) responded, this custom response header will helps you. headers.Add("X-StaticFile-Hanler", new[] { "OwinStaticFiles" }); } }); } }
public static void ServeEmbeddedFiles(this IAppBuilder app) { var fileSystem = new EmbeddedResourceFileSystem(Web.Namespace + ".Static"); SharedOptions sharedOptions = new SharedOptions { FileSystem = fileSystem, RequestPath = new PathString("/static") }; var staticOptions = new StaticFileOptions(sharedOptions) { ServeUnknownFileTypes = true, OnPrepareResponse = context => context.OwinContext.Response.Headers.Set("Cache-Control", MaxAgeString) }; app.UseStaticFiles(staticOptions); }
private void ConfigureWebApp(IAppBuilder app) { #if DEBUG app.Use(typeof(NoCacheMiddleware)); #endif var contentTypeProvider = new FileExtensionContentTypeProvider(); contentTypeProvider.Mappings.Add(".json", "application/json"); app.UseFileServer(new FileServerOptions() { RequestPath = new PathString("/tiles"), FileSystem = new PhysicalFileSystem(MiMapConfig.Config.TilesDirectory), #if DEBUG EnableDirectoryBrowsing = true, #endif EnableDefaultFiles = true, StaticFileOptions = { ContentTypeProvider = contentTypeProvider, } }); #if FALSE var contentFileSystem = new PhysicalFileSystem("S:\\Development\\Projects\\MiNET-MiMap\\MiMap.Web\\Content"); #else var contentFileSystem = new EmbeddedResourceFileSystem(typeof(MiMapWebServer).Assembly, GetType().Namespace + ".Content"); #endif app.UseFileServer(new FileServerOptions { FileSystem = contentFileSystem, #if DEBUG EnableDirectoryBrowsing = true, #endif EnableDefaultFiles = true }); // Widget Stuff WidgetManager.ConfigureHttp(app); }
public static string ExecuteJavascript(string view, object model, string viewName) { using (var context = new JavascriptContext()) { var fileSystem = new EmbeddedResourceFileSystem(typeof(WebInitializer).Assembly); using (var reader = new StreamReader(fileSystem.OpenRead(PathInfo.Create("Core/js/ViewEngine.js")))) { context.Run(reader.ReadToEnd()); } context.Run("var repo = { actions: {}, register: function(name, action) { this.actions[name] = action; } };"); context.Run(view); context.SetParameter("m", model); context.Run( "var ctx = new Tcn.StringRenderingContext(); repo.actions[\"" + viewName + "\"].render(ctx, m); var result = ctx.out;"); return((string)context.GetParameter("result")); } }
// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder appBuilder) { // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); // Enable attribute based routing // http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2 config.MapHttpAttributeRoutes(); config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); //appBuilder.UseStaticFiles("/static"); //const string rootFolder = "."; //System.Reflection.Assembly ass = ; var fileSystem = new EmbeddedResourceFileSystem(Assembly.GetAssembly(typeof(StaticClass)), "TypeScriptHTMLApp"); var options = new StaticFileOptions { FileSystem = fileSystem }; //appBuilder.UseFileServer(options); //appBuilder.UseDirectoryBrowser(); appBuilder.UseStaticFiles(options); var defOptions = new DefaultFilesOptions { DefaultFileNames = { "index.html" }, FileSystem = fileSystem }; appBuilder.UseDefaultFiles(defOptions); appBuilder.UseWebApi(config); }
public CustomFileSystem(IDictionary <string, string> replaceDictionary) { this.inner = new EmbeddedResourceFileSystem(this.GetType().Assembly.GetName().Name + ".Content"); this.replaceDict = replaceDictionary; }
private void OwinBuilder(IAppBuilder app) { IFileSystem outputFolder = new PhysicalFileSystem(LocalPath); if (LiveReloadClients != null) { // Inject LiveReload script tags to HTML documents, needs to run first as it overrides output stream app.UseScriptInjection($"{VirtualDirectory ?? string.Empty}/livereload.js?host=localhost&port={Port}"); // Host ws:// (this also needs to go early in the pipeline so WS can return before virtual directory, etc.) app.MapFleckRoute <ReloadClient>("/livereload", connection => { ReloadClient reloadClient = (ReloadClient)connection; reloadClient.Logger = _loggerProvider?.CreateLogger("LiveReload"); LiveReloadClients.Add(reloadClient); }); } // Support for virtual directory if (!string.IsNullOrEmpty(VirtualDirectory)) { app.UseVirtualDirectory(VirtualDirectory); } // Disable caching app.Use((c, t) => { c.Response.Headers.Append("Cache-Control", "no-cache, no-store, must-revalidate"); c.Response.Headers.Append("Pragma", "no-cache"); c.Response.Headers.Append("Expires", "0"); return(t()); }); // Support for extensionless URLs if (Extensionless) { app.UseExtensionlessUrls(new ExtensionlessUrlsOptions { FileSystem = outputFolder }); } // Serve up all static files app.UseDefaultFiles(new DefaultFilesOptions { RequestPath = PathString.Empty, FileSystem = outputFolder, DefaultFileNames = new List <string> { "index.html", "index.htm", "home.html", "home.htm", "default.html", "default.html" } }); app.UseStaticFiles(new StaticFileOptions { RequestPath = PathString.Empty, FileSystem = outputFolder, ServeUnknownFileTypes = true }); if (LiveReloadClients != null) { // Host livereload.js (do this last so virtual directory rewriting applies) Assembly liveReloadAssembly = typeof(ReloadClient).Assembly; string rootNamespace = typeof(ReloadClient).Namespace; IFileSystem reloadFilesystem = new EmbeddedResourceFileSystem(liveReloadAssembly, $"{rootNamespace}"); app.UseStaticFiles(new StaticFileOptions { RequestPath = PathString.Empty, FileSystem = reloadFilesystem, ServeUnknownFileTypes = true }); } }
public EmbeddedResourceFileSystem2(string baseNamespace) { _fileSystem = new EmbeddedResourceFileSystem(baseNamespace); _baseNamespace = baseNamespace; _resourceNames = Assembly.GetCallingAssembly().GetManifestResourceNames(); }