当前位置: 首页>>代码示例>>C#>>正文


C# PhysicalFileProvider.GetFileInfo方法代码示例

本文整理汇总了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);
        }
开发者ID:IEvangelist,项目名称:FileSystem,代码行数:11,代码来源:PhysicalFileProviderTests.cs

示例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")
     });
 }
开发者ID:afantini,项目名称:aspnet-hypermedia-api-seed,代码行数:11,代码来源:Startup.cs

示例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);
        }
开发者ID:sujiantao,项目名称:FileSystem,代码行数:11,代码来源:PhysicalFileProviderTests.cs

示例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);
     }
 }
开发者ID:leloulight,项目名称:FileSystem,代码行数:8,代码来源:PhysicalFileProviderTests.cs

示例5: GetFileInfoReturnsNotFoundFileInfoForEmptyPath

 public void GetFileInfoReturnsNotFoundFileInfoForEmptyPath()
 {
     using (var provider = new PhysicalFileProvider(Path.GetTempPath()))
     {
         var info = provider.GetFileInfo(string.Empty);
         Assert.IsType(typeof(NotFoundFileInfo), info);
     }
 }
开发者ID:leloulight,项目名称:FileSystem,代码行数:8,代码来源:PhysicalFileProviderTests.cs

示例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);
                }
            }
        }
开发者ID:leloulight,项目名称:FileSystem,代码行数:18,代码来源:PhysicalFileProviderTests.cs

示例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);
        }
开发者ID:sitharus,项目名称:MHUI,代码行数:20,代码来源:Startup.cs

示例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);
 }
开发者ID:sujiantao,项目名称:FileSystem,代码行数:7,代码来源:PhysicalFileProviderTests.cs

示例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);
        }
开发者ID:sujiantao,项目名称:FileSystem,代码行数:16,代码来源:PhysicalFileProviderTests.cs

示例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();
        }
开发者ID:andresmoschini,项目名称:remote-media,代码行数:26,代码来源:Startup.cs

示例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);
        }
开发者ID:IEvangelist,项目名称:FileSystem,代码行数:70,代码来源:PhysicalFileProviderTests.cs

示例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);
 }
开发者ID:IEvangelist,项目名称:FileSystem,代码行数:7,代码来源:PhysicalFileProviderTests.cs

示例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());
        }
开发者ID:IEvangelist,项目名称:FileSystem,代码行数:15,代码来源:PhysicalFileProviderTests.cs

示例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());
        }
开发者ID:IEvangelist,项目名称:FileSystem,代码行数:17,代码来源:PhysicalFileProviderTests.cs

示例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());
        }
开发者ID:IEvangelist,项目名称:FileSystem,代码行数:13,代码来源:PhysicalFileProviderTests.cs


注:本文中的Microsoft.AspNet.FileProviders.PhysicalFileProvider.GetFileInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。