本文整理汇总了C#中Microsoft.AspNet.FileProviders.PhysicalFileProvider类的典型用法代码示例。如果您正苦于以下问题:C# PhysicalFileProvider类的具体用法?C# PhysicalFileProvider怎么用?C# PhysicalFileProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PhysicalFileProvider类属于Microsoft.AspNet.FileProviders命名空间,在下文中一共展示了PhysicalFileProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFileInfoReturnsNotFoundFileInfoForRelativePathAboveRootPath
public void GetFileInfoReturnsNotFoundFileInfoForRelativePathAboveRootPath()
{
using (var provider = new PhysicalFileProvider(Path.GetTempPath()))
{
var info = provider.GetFileInfo(Path.Combine("..", Guid.NewGuid().ToString()));
Assert.IsType(typeof(NotFoundFileInfo), info);
}
}
示例2: GetFileInfoReturnsNotFoundFileInfoForEmptyPath
public void GetFileInfoReturnsNotFoundFileInfoForEmptyPath()
{
using (var provider = new PhysicalFileProvider(Path.GetTempPath()))
{
var info = provider.GetFileInfo(string.Empty);
Assert.IsType(typeof(NotFoundFileInfo), info);
}
}
示例3: UseDocumentation
private static void UseDocumentation(IApplicationBuilder app, IApplicationEnvironment appEnv)
{
var documentationFilesProvider = new PhysicalFileProvider(appEnv.ApplicationBasePath);
app.UseDocumentation(new DocumentationOptions()
{
DefaultFileName = "index",
RequestPath = "/docs",
NotFoundHtmlFile = documentationFilesProvider.GetFileInfo("DocumentationTemplates\\NotFound.html"),
LayoutFile = documentationFilesProvider.GetFileInfo("DocumentationTemplates\\Layout.html")
});
}
示例4: ExistingFilesReturnTrue
public void ExistingFilesReturnTrue()
{
var provider = new PhysicalFileProvider(Environment.CurrentDirectory);
var info = provider.GetFileInfo("File.txt");
info.ShouldNotBe(null);
info.Exists.ShouldBe(true);
info = provider.GetFileInfo("/File.txt");
info.ShouldNotBe(null);
info.Exists.ShouldBe(true);
}
示例5: ExistingFilesReturnTrue
public void ExistingFilesReturnTrue()
{
var provider = new PhysicalFileProvider(Directory.GetCurrentDirectory());
var info = provider.GetFileInfo("File.txt");
Assert.NotNull(info);
Assert.True(info.Exists);
info = provider.GetFileInfo("/File.txt");
Assert.NotNull(info);
Assert.True(info.Exists);
}
示例6: NoMatch_PassesThrough
public async Task NoMatch_PassesThrough(string baseUrl, string baseDir, string requestUrl)
{
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
{
var server = StaticFilesTestServer.Create(app => app.UseStaticFiles(options =>
{
options.RequestPath = new PathString(baseUrl);
options.FileProvider = fileProvider;
}));
var response = await server.CreateRequest(requestUrl).GetAsync();
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
}
示例7: Configure
public void Configure(IApplicationBuilder app, IApplicationEnvironment environemnt)
{
app.UseIISPlatformHandler();
app.UseFileServer();
var provider = new PhysicalFileProvider(Path.Combine(environemnt.ApplicationBasePath, "node_modules"));
var options = new FileServerOptions();
options.RequestPath = "/node_modules";
options.StaticFileOptions.FileProvider = provider;
options.EnableDirectoryBrowsing = true;
app.UseFileServer(options);
app.UseMvc();
}
示例8: GetFileInfoReturnsNotFoundFileInfoForHiddenFile
public void GetFileInfoReturnsNotFoundFileInfoForHiddenFile()
{
using (var root = new DisposableFileSystem())
{
using (var provider = new PhysicalFileProvider(root.RootPath))
{
var fileName = Guid.NewGuid().ToString();
var filePath = Path.Combine(root.RootPath, fileName);
File.Create(filePath);
var fileInfo = new FileInfo(filePath);
File.SetAttributes(filePath, fileInfo.Attributes | FileAttributes.Hidden);
var info = provider.GetFileInfo(fileName);
Assert.IsType(typeof(NotFoundFileInfo), info);
}
}
}
示例9: DisplaysSourceCodeLines_ForAbsolutePaths
public void DisplaysSourceCodeLines_ForAbsolutePaths(string absoluteFilePath)
{
// Arrange
var rootPath = Directory.GetCurrentDirectory();
// PhysicalFileProvider handles only relative paths but we fall back to work with absolute paths too
var provider = new PhysicalFileProvider(rootPath);
// Act
var middleware = GetErrorPageMiddleware(provider);
var stackFrame = middleware.GetStackFrame("func1", absoluteFilePath, lineNumber: 10);
// Assert
// Lines 4-16 (inclusive) is the code block
Assert.Equal(4, stackFrame.PreContextLine);
Assert.Equal(GetCodeLines(4, 9), stackFrame.PreContextCode);
Assert.Equal(GetCodeLines(10, 10), stackFrame.ContextCode);
Assert.Equal(GetCodeLines(11, 16), stackFrame.PostContextCode);
}
示例10: NoMatch_PassesThrough
public async Task NoMatch_PassesThrough(string baseUrl, string baseDir, string requestUrl)
{
using (var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), baseDir)))
{
var server = StaticFilesTestServer.Create(app =>
{
app.UseDefaultFiles(options =>
{
options.RequestPath = new PathString(baseUrl);
options.FileProvider = fileProvider;
});
app.Run(context => context.Response.WriteAsync(context.Request.Path.Value));
});
var response = await server.CreateClient().GetAsync(requestUrl);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(requestUrl, await response.Content.ReadAsStringAsync()); // Should not be modified
}
}
示例11: BeforeCompile
/// <inheritdoc />
/// <remarks>Pre-compiles all Razor views in the application.</remarks>
public virtual void BeforeCompile(IBeforeCompileContext context)
{
var compilerOptionsProvider = _appServices.GetRequiredService<ICompilerOptionsProvider>();
var loadContextAccessor = _appServices.GetRequiredService<IAssemblyLoadContextAccessor>();
var compilationSettings = GetCompilationSettings(compilerOptionsProvider, context.ProjectContext);
var fileProvider = new PhysicalFileProvider(context.ProjectContext.ProjectDirectory);
var viewCompiler = new RazorPreCompiler(
context,
loadContextAccessor,
fileProvider,
_memoryCache,
compilationSettings)
{
GenerateSymbols = GenerateSymbols
};
viewCompiler.CompileViews();
}
示例12: CreateJSEngine
private static JSPool.IJsPool CreateJSEngine(IServiceProvider provider)
{
var ieConfig = new JavaScriptEngineSwitcher.Msie.Configuration.MsieConfiguration
{
EngineMode = JavaScriptEngineSwitcher.Msie.JsEngineMode.ChakraEdgeJsRt
};
var appEnv = provider.GetRequiredService<IApplicationEnvironment>();
var fileProvider = new PhysicalFileProvider(appEnv.ApplicationBasePath);
var jsPath = fileProvider.GetFileInfo("wwwroot/js/server.js").PhysicalPath;
var poolConfig = new JSPool.JsPoolConfig();
poolConfig.MaxUsagesPerEngine = 20;
poolConfig.StartEngines = 2;
poolConfig.EngineFactory = () => new JavaScriptEngineSwitcher.Msie.MsieJsEngine(ieConfig);
poolConfig.Initializer = engine => InitialiseJSRuntime(jsPath, engine);
poolConfig.WatchFiles = new[] { jsPath };
return new JSPool.JsPool(poolConfig);
}
示例13: ReloadOnChanged
public static IConfigurationRoot ReloadOnChanged(
this IConfigurationRoot config,
string basePath,
string filename)
{
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
if (basePath == null)
{
throw new ArgumentNullException(nameof(basePath));
}
if (filename == null)
{
throw new ArgumentNullException(nameof(filename));
}
var fileProvider = new PhysicalFileProvider(basePath);
return ReloadOnChanged(config, fileProvider, filename);
}
示例14: Main
public void Main(string[] args)
{
Console.WriteLine("Root path : {0}", _appEnvironment.ApplicationBasePath);
Console.WriteLine();
var physicalFileProvider = new PhysicalFileProvider(_appEnvironment.ApplicationBasePath);
physicalFileProvider.GetInfo(@"c:\github\kichalla\FileProvidersExample\src\FileProvidersExample\Program.cs");
physicalFileProvider.GetInfo("Program.cs");
physicalFileProvider.GetInfo("/Program.cs");
physicalFileProvider.GetInfo(@"\Program.cs");
physicalFileProvider.GetInfo("FileProvidersExample/Program.cs");
physicalFileProvider.GetInfo("/FileProvidersExample/Program.cs");
physicalFileProvider.GetInfo(@"\FileProvidersExample\Program.cs");
Console.WriteLine("***********************************************************");
var embeddedProvider = new EmbeddedFileProvider(this.GetType().GetTypeInfo().Assembly, "FileProvidersExample.EmbeddedResources");
embeddedProvider.GetInfo("Blah.cshtml");
embeddedProvider.GetInfo("/Views/Home/Index.cshtml");
embeddedProvider.GetInfo("Views/Home/Index.cshtml");
embeddedProvider.GetInfo(@"\Views\Home\Index.cshtml");
embeddedProvider.GetInfo(@"Views\Home\Index.cshtml");
}
示例15: Triggers_With_Regular_Expression_Pointing_To_SubFolder
public async Task Triggers_With_Regular_Expression_Pointing_To_SubFolder()
{
var subFolderName = Guid.NewGuid().ToString();
var pattern1 = "**/*";
var pattern2 = string.Format("{0}/**/*.cshtml", subFolderName);
var root = Path.GetTempPath();
var fileName = Guid.NewGuid().ToString();
var subFolder = Path.Combine(root, subFolderName);
Directory.CreateDirectory(subFolder);
int pattern1TriggerCount = 0, pattern2TriggerCount = 0;
var provider = new PhysicalFileProvider(root);
var trigger1 = provider.Watch(pattern1);
trigger1.RegisterExpirationCallback(_ => { pattern1TriggerCount++; }, null);
var trigger2 = provider.Watch(pattern2);
trigger2.RegisterExpirationCallback(_ => { pattern2TriggerCount++; }, null);
File.WriteAllText(Path.Combine(root, fileName + ".cshtml"), "Content");
await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);
pattern1TriggerCount.ShouldBe(1);
pattern2TriggerCount.ShouldBe(0);
trigger1 = provider.Watch(pattern1);
trigger1.RegisterExpirationCallback(_ => { pattern1TriggerCount++; }, null);
// Register this trigger again.
var trigger3 = provider.Watch(pattern2);
trigger3.RegisterExpirationCallback(_ => { pattern2TriggerCount++; }, null);
trigger3.ShouldBe(trigger2);
File.WriteAllText(Path.Combine(subFolder, fileName + ".cshtml"), "Content");
await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);
pattern1TriggerCount.ShouldBe(2);
pattern2TriggerCount.ShouldBe(2);
Directory.Delete(subFolder, true);
File.Delete(Path.Combine(root, fileName + ".cshtml"));
}