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


C# FileProviders.PhysicalFileProvider类代码示例

本文整理汇总了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);
     }
 }
开发者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


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