當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。