• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# FileProviders.PhysicalFileProvider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.AspNet.FileProviders.PhysicalFileProvider的典型用法代码示例。如果您正苦于以下问题:C# PhysicalFileProvider类的具体用法?C# PhysicalFileProvider怎么用?C# PhysicalFileProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PhysicalFileProvider类属于Microsoft.AspNet.FileProviders命名空间,在下文中一共展示了PhysicalFileProvider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
     }
 }
开发者ID:leloulight,项目名称:FileSystem,代码行数:8,代码来源:PhysicalFileProviderTests.cs


示例2: 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


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


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


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


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


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


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


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


示例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
            }
        }
开发者ID:leloulight,项目名称:StaticFiles,代码行数:19,代码来源:DefaultFilesMiddlewareTests.cs


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


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


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


示例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");
        }
开发者ID:kichalla,项目名称:FileProviders,代码行数:23,代码来源:Program.cs


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


示例16: Triggers_With_Regular_Expression_Filters

        public async Task Triggers_With_Regular_Expression_Filters()
        {
            var pattern1 = "**/*";
            var pattern2 = "*.cshtml";
            var root = Path.GetTempPath();
            var fileName = Guid.NewGuid().ToString();
            var subFolder = Path.Combine(root, Guid.NewGuid().ToString());
            Directory.CreateDirectory(subFolder);

            int pattern1TriggerCount = 0, pattern2TriggerCount = 0;
            Action<object> callback1 = _ => { pattern1TriggerCount++; };
            Action<object> callback2 = _ => { pattern2TriggerCount++; };

            var provider = new PhysicalFileProvider(root);
            var trigger1 = provider.Watch(pattern1);
            trigger1.RegisterExpirationCallback(callback1, null);
            var trigger2 = provider.Watch(pattern2);
            trigger2.RegisterExpirationCallback(callback2, null);

            File.WriteAllText(Path.Combine(root, fileName + ".cshtml"), "Content");

            await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);
            pattern1TriggerCount.ShouldBe(1);
            pattern2TriggerCount.ShouldBe(1);

            trigger1 = provider.Watch(pattern1);
            trigger1.RegisterExpirationCallback(callback1, null);
            trigger2 = provider.Watch(pattern2);
            trigger2.RegisterExpirationCallback(callback2, null);
            File.WriteAllText(Path.Combine(subFolder, fileName + ".txt"), "Content");

            await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);
            pattern1TriggerCount.ShouldBe(2);
            pattern2TriggerCount.ShouldBe(1);

            Directory.Delete(subFolder, true);
            File.Delete(Path.Combine(root, fileName + ".cshtml"));
        }
开发者ID:sujiantao,项目名称:FileSystem,代码行数:38,代码来源:PhysicalFileProviderTests.cs


示例17: Triggers_With_Path_Not_Ending_With_Slash

        public async Task Triggers_With_Path_Not_Ending_With_Slash()
        {
            var provider = new PhysicalFileProvider(Path.GetTempPath());
            string directoryName = Guid.NewGuid().ToString();
            string fileName = Guid.NewGuid().ToString();

            int triggerCount = 0;
            // Matches file/directory with this name.
            var fileTrigger = provider.Watch("/" + directoryName);
            fileTrigger.RegisterExpirationCallback(_ => { triggerCount++; }, null);

            Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), directoryName));
            await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);
            triggerCount.ShouldBe(1);

            // Matches file/directory with this name.
            fileTrigger = provider.Watch("/" + fileName);
            fileTrigger.RegisterExpirationCallback(_ => { triggerCount++; }, null);

            File.WriteAllText(Path.Combine(Path.GetTempPath(), fileName), "Content");
            await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);
            triggerCount.ShouldBe(2);
        }
开发者ID:sujiantao,项目名称:FileSystem,代码行数:23,代码来源:PhysicalFileProviderTests.cs


示例18: Triggers_With_Path_Ending_With_Slash

        public async Task Triggers_With_Path_Ending_With_Slash()
        {
            var provider = new PhysicalFileProvider(Path.GetTempPath());
            string fileName = Guid.NewGuid().ToString();
            string folderName = Guid.NewGuid().ToString();

            int triggerCount = 0;
            var fileTrigger = provider.Watch("/" + folderName + "/");
            fileTrigger.RegisterExpirationCallback(_ => { triggerCount++; }, null);

            var folderPath = Path.Combine(Path.GetTempPath(), folderName);
            Directory.CreateDirectory(folderPath);
            File.WriteAllText(Path.Combine(folderPath, fileName), "Content");

            await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);
            triggerCount.ShouldBe(1);

            fileTrigger = provider.Watch("/" + folderName + "/");
            fileTrigger.RegisterExpirationCallback(_ => { triggerCount++; }, null);

            File.AppendAllText(Path.Combine(folderPath, fileName), "UpdatedContent");
            await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);
            triggerCount.ShouldBe(2);

            fileTrigger = provider.Watch("/" + folderName + "/");
            fileTrigger.RegisterExpirationCallback(_ => { triggerCount++; }, null);

            File.Delete(Path.Combine(folderPath, fileName));
            await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);
            triggerCount.ShouldBe(3);
        }
开发者ID:sujiantao,项目名称:FileSystem,代码行数:31,代码来源:PhysicalFileProviderTests.cs


示例19: Trigger_Fired_For_File_Or_Directory_Create_And_Delete

        public async Task Trigger_Fired_For_File_Or_Directory_Create_And_Delete()
        {
            var root = Path.GetTempPath();
            var provider = new PhysicalFileProvider(root);
            string fileName = Guid.NewGuid().ToString();
            string directoryName = Guid.NewGuid().ToString();

            int triggerCount = 0;
            var fileTrigger = provider.Watch(fileName);
            fileTrigger.RegisterExpirationCallback(_ => { triggerCount++; }, null);
            var directoryTrigger = provider.Watch(directoryName);
            directoryTrigger.RegisterExpirationCallback(_ => { triggerCount++; }, null);

            fileTrigger.ShouldNotBe(directoryTrigger);

            File.WriteAllText(Path.Combine(root, fileName), "Content");
            Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), directoryName));

            // Wait for triggers to fire.
            await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);

            triggerCount.ShouldBe(2);

            fileTrigger.IsExpired.ShouldBe(true);
            directoryTrigger.IsExpired.ShouldBe(true);

            fileTrigger = provider.Watch(fileName);
            fileTrigger.RegisterExpirationCallback(_ => { triggerCount++; }, null);
            directoryTrigger = provider.Watch(directoryName);
            directoryTrigger.RegisterExpirationCallback(_ => { triggerCount++; }, null);

            File.Delete(Path.Combine(root, fileName));
            Directory.Delete(Path.Combine(Path.GetTempPath(), directoryName));

            // Wait for triggers to fire.
            await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);
            triggerCount.ShouldBe(4);
        }
开发者ID:sujiantao,项目名称:FileSystem,代码行数:38,代码来源:PhysicalFileProviderTests.cs


示例20: Triggers_NotFired_For_FileNames_Starting_With_Period_And_Hidden_Files

        public async Task Triggers_NotFired_For_FileNames_Starting_With_Period_And_Hidden_Files()
        {
            var root = Path.GetTempPath();
            var hiddenFileName = Path.Combine(root, Guid.NewGuid().ToString());
            File.WriteAllText(hiddenFileName, "Content");
            var systemFileName = Path.Combine(root, Guid.NewGuid().ToString());
            File.WriteAllText(systemFileName, "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);
            fileInfo = new FileInfo(systemFileName);
            File.SetAttributes(systemFileName, fileInfo.Attributes | FileAttributes.System);

            var provider = new PhysicalFileProvider(Path.GetTempPath());
            var hiddenFileTrigger = provider.Watch(Path.GetFileName(hiddenFileName));
            var triggerFileNameStartingPeriod = provider.Watch(Path.GetFileName(fileNameStartingWithPeriod));
            var systemFileTrigger = provider.Watch(Path.GetFileName(systemFileName));

            hiddenFileTrigger.IsExpired.ShouldBe(false);
            triggerFileNameStartingPeriod.IsExpired.ShouldBe(false);
            systemFileTrigger.IsExpired.ShouldBe(false);

            File.AppendAllText(hiddenFileName, "Appending text");
            File.WriteAllText(fileNameStartingWithPeriod, "Updated Contents");
            File.AppendAllText(systemFileName, "Appending text");

            // Wait for triggers to fire.
            await Task.Delay(WAIT_TIME_FOR_TRIGGER_TO_FIRE);

            hiddenFileTrigger.IsExpired.ShouldBe(false);
            triggerFileNameStartingPeriod.IsExpired.ShouldBe(false);
            systemFileTrigger.IsExpired.ShouldBe(false);
        }
开发者ID:sujiantao,项目名称:FileSystem,代码行数:34,代码来源:PhysicalFileProviderTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Hosting.WebApplicationBuilder类代码示例发布时间:2022-05-26
下一篇:
C# Extensibility.TelemetryConfiguration类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap