本文整理汇总了C#中Microsoft.AspNet.FileProviders.PhysicalFileProvider.GetFileInfo方法的典型用法代码示例。如果您正苦于以下问题:C# PhysicalFileProvider.GetFileInfo方法的具体用法?C# PhysicalFileProvider.GetFileInfo怎么用?C# PhysicalFileProvider.GetFileInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.FileProviders.PhysicalFileProvider
的用法示例。
在下文中一共展示了PhysicalFileProvider.GetFileInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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")
});
}
示例3: 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);
}
示例4: 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);
}
}
示例5: GetFileInfoReturnsNotFoundFileInfoForEmptyPath
public void GetFileInfoReturnsNotFoundFileInfoForEmptyPath()
{
using (var provider = new PhysicalFileProvider(Path.GetTempPath()))
{
var info = provider.GetFileInfo(string.Empty);
Assert.IsType(typeof(NotFoundFileInfo), info);
}
}
示例6: 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);
}
}
}
示例7: 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);
}
示例8: SubPathActsAsRoot
public void SubPathActsAsRoot()
{
var provider = new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, "sub"));
var info = provider.GetFileInfo("File2.txt");
info.ShouldNotBe(null);
info.Exists.ShouldBe(true);
}
示例9: Missing_Hidden_And_FilesStartingWithPeriod_ReturnFalse
public void Missing_Hidden_And_FilesStartingWithPeriod_ReturnFalse()
{
var root = Path.GetTempPath();
var hiddenFileName = Path.Combine(root, Guid.NewGuid().ToString());
File.WriteAllText(hiddenFileName, "Content");
var fileNameStartingWithPeriod = Path.Combine(root, ".", Guid.NewGuid().ToString());
File.WriteAllText(fileNameStartingWithPeriod, "Content");
var fileInfo = new FileInfo(hiddenFileName);
File.SetAttributes(hiddenFileName, fileInfo.Attributes | FileAttributes.Hidden);
var provider = new PhysicalFileProvider(Path.GetTempPath());
provider.GetFileInfo(Guid.NewGuid().ToString()).Exists.ShouldBe(false);
provider.GetFileInfo(hiddenFileName).Exists.ShouldBe(false);
provider.GetFileInfo(fileNameStartingWithPeriod).Exists.ShouldBe(false);
}
示例10: Configure
public void Configure(IApplicationBuilder app, IApplicationEnvironment appEnv, IHostingEnvironment hostEnv, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(LogginConfiguration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseIISPlatformHandler();
app.UseApiErrorHandler();
app.UseMvc();
app.UseSwaggerGen("swagger/{apiVersion}/swagger.json");
app.UseSwaggerUi("swagger/ui");
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")
});
app.UseNotFoundHandler();
}
示例11: ModifyContent_And_Delete_File_Succeeds_And_Callsback_RegisteredTokens
public async Task ModifyContent_And_Delete_File_Succeeds_And_Callsback_RegisteredTokens()
{
var fileName = Guid.NewGuid().ToString();
var fileLocation = Path.Combine(Path.GetTempPath(), fileName);
File.WriteAllText(fileLocation, "OldContent");
var provider = new PhysicalFileProvider(Path.GetTempPath());
var fileInfo = provider.GetFileInfo(fileName);
Assert.Equal(new FileInfo(fileInfo.PhysicalPath).Length, fileInfo.Length);
Assert.True(fileInfo.Exists);
var token1 = provider.Watch(fileName);
var token2 = provider.Watch(fileName);
// Valid token1 created.
Assert.NotNull(token1);
Assert.False(token1.HasChanged);
Assert.True(token1.ActiveChangeCallbacks);
// Valid token2 created.
Assert.NotNull(token2);
Assert.False(token2.HasChanged);
Assert.True(token2.ActiveChangeCallbacks);
// token is the same for a specific file.
Assert.Equal(token2, token1);
IChangeToken token3 = null;
IChangeToken token4 = null;
token1.RegisterChangeCallback(state =>
{
var infoFromState = state as IFileInfo;
token3 = provider.Watch(infoFromState.Name);
Assert.NotNull(token3);
token3.RegisterChangeCallback(_ => { }, null);
Assert.False(token3.HasChanged);
}, state: fileInfo);
token2.RegisterChangeCallback(state =>
{
var infoFromState = state as IFileInfo;
token4 = provider.Watch(infoFromState.Name);
Assert.NotNull(token4);
token4.RegisterChangeCallback(_ => { }, null);
Assert.False(token4.HasChanged);
}, state: fileInfo);
// Write new content.
File.WriteAllText(fileLocation, "OldContent + NewContent");
Assert.True(fileInfo.Exists);
// Wait for callbacks to be fired.
await Task.Delay(WaitTimeForTokenToFire);
Assert.True(token1.HasChanged);
Assert.True(token2.HasChanged);
// token is the same for a specific file.
Assert.Same(token4, token3);
// A new token is created.
Assert.NotEqual(token1, token3);
// Delete the file and verify file info is updated.
File.Delete(fileLocation);
fileInfo = provider.GetFileInfo(fileName);
Assert.False(fileInfo.Exists);
Assert.False(new FileInfo(fileLocation).Exists);
// Wait for callbacks to be fired.
await Task.Delay(WaitTimeForTokenToFire);
Assert.True(token3.HasChanged);
Assert.True(token4.HasChanged);
}
示例12: SubPathActsAsRoot
public void SubPathActsAsRoot()
{
var provider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "sub"));
var info = provider.GetFileInfo("File2.txt");
Assert.NotNull(info);
Assert.True(info.Exists);
}
示例13: Exists_WithFileStartingWithPeriod_ReturnsFalse
public void Exists_WithFileStartingWithPeriod_ReturnsFalse()
{
// Set stuff up on disk
var root = Path.GetTempPath();
var fileNameStartingWithPeriod = "." + Guid.NewGuid().ToString();
var physicalFileNameStartingWithPeriod = Path.Combine(root, fileNameStartingWithPeriod);
File.WriteAllText(physicalFileNameStartingWithPeriod, "Content");
// Use the file provider to try to read the file info back
var provider = new PhysicalFileProvider(root);
var file = provider.GetFileInfo(fileNameStartingWithPeriod);
Assert.False(file.Exists);
Assert.Throws<FileNotFoundException>(() => file.CreateReadStream());
}
示例14: Exists_WithHiddenFile_ReturnsFalse
public void Exists_WithHiddenFile_ReturnsFalse()
{
// Set stuff up on disk
var root = Path.GetTempPath();
var tempFileName = Guid.NewGuid().ToString();
var physicalHiddenFileName = Path.Combine(root, tempFileName);
File.WriteAllText(physicalHiddenFileName, "Content");
var fileInfo = new FileInfo(physicalHiddenFileName);
File.SetAttributes(physicalHiddenFileName, fileInfo.Attributes | FileAttributes.Hidden);
// Use the file provider to try to read the file info back
var provider = new PhysicalFileProvider(root);
var file = provider.GetFileInfo(tempFileName);
Assert.False(file.Exists);
Assert.Throws<FileNotFoundException>(() => file.CreateReadStream());
}
示例15: Exists_WithNonExistingFile_ReturnsFalse
public void Exists_WithNonExistingFile_ReturnsFalse()
{
// Set stuff up on disk (nothing to set up here because we're testing a non-existing file)
var root = Path.GetTempPath();
var nonExistingFileName = Guid.NewGuid().ToString();
// Use the file provider to try to read the file info back
var provider = new PhysicalFileProvider(root);
var file = provider.GetFileInfo(nonExistingFileName);
Assert.False(file.Exists);
Assert.Throws<FileNotFoundException>(() => file.CreateReadStream());
}