예제 #1
0
        public void TestAddRemoveFileSystem()
        {
            var fs = new AggregateFileSystem();

            Assert.Throws <ArgumentNullException>(() => fs.AddFileSystem(null));
            Assert.Throws <ArgumentException>(() => fs.AddFileSystem(fs));

            var memfs = new MemoryFileSystem();

            fs.AddFileSystem(memfs);
            Assert.Throws <ArgumentException>(() => fs.AddFileSystem(memfs));

            Assert.Throws <ArgumentNullException>(() => fs.RemoveFileSystem(null));

            var memfs2 = new MemoryFileSystem();

            Assert.Throws <ArgumentException>(() => fs.RemoveFileSystem(memfs2));

            var list = fs.GetFileSystems();

            Assert.Equal(1, list.Count);
            Assert.Equal(memfs, list[0]);

            fs.RemoveFileSystem(memfs);

            list = fs.GetFileSystems();
            Assert.Equal(0, list.Count);
        }
        private void ConfigureFileServer(IAppBuilder app, HostConfig config)
        {
            // use a file server to serve all static content (js, css, content, html, ...) and also configure default files (eg: index.html to be the default entry point)

            // create file system that will locate the files
            var fileSystem = AggregateFileSystem.FromWebUiPhysicalPaths(config.RootDirectory);

            // setup default documents
            app.UseDefaultFiles(new DefaultFilesOptions
            {
                FileSystem       = fileSystem,
                DefaultFileNames = new List <string>
                {
                    "views/index.html"
                }
            });


            // start file server to share website static content
            // wrapper around: StaticFiles + DefaultFiles + DirectoryBrowser
            var fileServerOptions = new FileServerOptions
            {
                EnableDirectoryBrowsing = false,
                FileSystem = fileSystem,
            };

            fileServerOptions.StaticFileOptions.ContentTypeProvider = new FileServerContentTypeProvider();

            app.UseFileServer(fileServerOptions);
        }
예제 #3
0
        protected AggregateFileSystem GetCommonAggregateFileSystem(out MemoryFileSystem fs1, out MemoryFileSystem fs2, out MemoryFileSystem fs3)
        {
            // ----------------------------------------------
            // This creates the following AggregateFileSystem
            // ----------------------------------------------
            // /a                 -> fs2
            //     /a             -> fs1
            //        a.txt       -> fs1
            //     /b             -> fs1
            //        b.i         -> fs1
            //     /C             -> fs2
            //     /d             -> fs2
            //     a.txt          -> fs2
            //     A.txt          -> fs2
            //     b.txt          -> fs2
            //     c.txt1         -> fs2
            //     d.i            -> fs2
            //     f.i1           -> fs2
            //     E              -> fs2
            // /b                 -> fs1
            //    b.i             -> fs1
            // /C                 -> fs2
            // /d                 -> fs3
            // A.txt              -> fs3
            // b.txt              -> fs2
            // c.txt1             -> fs3
            // d.i                -> fs3
            // f.i1               -> fs3
            // E                  -> fs2

            fs1 = new MemoryFileSystem()
            {
                Name = "mem0"
            };
            CreateFolderStructure(fs1);
            fs2      = fs1.Clone();
            fs2.Name = "mem1";
            fs3      = fs2.Clone();
            fs3.Name = "mem2";

            // Delete part of fs2 so that it will fallback to fs1
            fs2.DeleteDirectory("/a/a", true);
            fs2.DeleteDirectory("/a/b", true);
            fs2.DeleteDirectory("/b", true);

            // Delete on fs3 to fallback to fs2 and fs1
            fs3.DeleteDirectory("/a", true);
            fs3.DeleteDirectory("/C", true);
            fs3.DeleteFile("/b.txt");
            fs3.DeleteFile("/E");

            var aggfs = new AggregateFileSystem(fs1);

            aggfs.AddFileSystem(fs2);
            aggfs.AddFileSystem(fs3);

            return(aggfs);
        }
예제 #4
0
        protected override IFileSystem GetTemplateFileSystem()
        {
            // GitHubRelease template is based on the "Default" template
            // => create aggregate file system with the files of both the "Default" and "GitHubRelease" templates
            var templateFileSystem = new AggregateFileSystem();

            templateFileSystem.AddFileSystem(base.GetTemplateFileSystem());
            templateFileSystem.AddFileSystem(CreateEmbeddedResourcesFileSystem("/templates/GitHubRelease"));

            return(templateFileSystem);
        }
예제 #5
0
        public void TestFallback()
        {
            // aggregate_fs (fs)
            //      => aggregate_fs (subFs)
            //              => memory_fs (subFsMemFs)
            //      => memory_fs (subMemFs)
            //      => memory_fs (root)
            var root       = new MemoryFileSystem();
            var fs         = new AggregateFileSystem(root);
            var subFsMemFs = new MemoryFileSystem();
            var subFs      = new AggregateFileSystem(subFsMemFs);

            fs.AddFileSystem(subFs);
            var subMemFs = new MemoryFileSystem();

            fs.AddFileSystem(subMemFs);

            root.CreateDirectory("/a");
            root.CreateDirectory("/b");
            root.CreateDirectory("/c");
            {
                using var a = root.OpenFile("/a.txt", FileMode.Create, FileAccess.Write);
                using var b = root.OpenFile("/b.txt", FileMode.Create, FileAccess.Write);
                using var c = root.OpenFile("/c.txt", FileMode.Create, FileAccess.Write);
            }
            subFsMemFs.CreateDirectory("/b");
            {
                using var b = subFsMemFs.OpenFile("/b.txt", FileMode.Create, FileAccess.Write);
            }
            subMemFs.CreateDirectory("/a");
            {
                using var a = subMemFs.OpenFile("/a.txt", FileMode.Create, FileAccess.Write);
            }

            var findA = fs.FindFirstFileSystemEntry("/a");

            Assert.Equal(subMemFs, findA?.FileSystem);

            var findB = fs.FindFirstFileSystemEntry("/b");

            Assert.Equal(subFsMemFs, findB?.FileSystem);

            var findC = fs.FindFirstFileSystemEntry("/c");

            Assert.Equal(root, findC?.FileSystem);

            Assert.True(fs.DirectoryExists("/c"));
            Assert.True(fs.DirectoryExists("/b"));
            Assert.True(fs.DirectoryExists("/a"));

            Assert.True(fs.FileExists("/c.txt"));
            Assert.True(fs.FileExists("/b.txt"));
            Assert.True(fs.FileExists("/a.txt"));
        }
예제 #6
0
        public SiteObject(ILoggerFactory loggerFactory = null)
        {
            var sharedFolder = Path.Combine(Path.GetDirectoryName(typeof(SiteObject).GetTypeInfo().Assembly.Location), SharedFolderName);

            _contentFileSystems = new List <IFileSystem>();
            var sharedPhysicalFileSystem = new PhysicalFileSystem();

            // Make sure that SharedFileSystem is a read-only filesystem
            SharedFileSystem     = new ReadOnlyFileSystem(new SubFileSystem(sharedPhysicalFileSystem, sharedPhysicalFileSystem.ConvertPathFromInternal(sharedFolder)));
            SharedMetaFileSystem = SharedFileSystem.GetOrCreateSubFileSystem(LunetFolder);

            _fileSystem = new AggregateFileSystem(SharedFileSystem);

            MetaFileSystem = new SubFileSystem(_fileSystem, LunetFolder);

            ConfigFile = new FileEntry(_fileSystem, UPath.Root / DefaultConfigFileName);

            StaticFiles  = new PageCollection();
            Pages        = new PageCollection();
            DynamicPages = new PageCollection();

            // Create the logger
            LoggerFactory = loggerFactory ?? Microsoft.Extensions.Logging.LoggerFactory.Create(builder =>
            {
                builder.AddProvider(new LoggerProviderIntercept(this))
                .AddFilter(LogFilter)
                .AddConsole();
            });

            Log          = LoggerFactory.CreateLogger("lunet");
            ContentTypes = new ContentTypeManager();

            DefaultPageExtension = DefaultPageExtensionValue;

            Html = new HtmlObject(this);
            SetValue(SiteVariables.Html, Html, true);

            CommandLine = new LunetCommandLine(this);

            Statistics = new SiteStatistics();

            Scripts = new ScriptingPlugin(this);

            Content = new ContentPlugin(this);

            Plugins = new OrderedList <ISitePlugin>();

            _pluginBuilders = new ContainerBuilder();
            _pluginBuilders.RegisterInstance(LoggerFactory).As <ILoggerFactory>();
            _pluginBuilders.RegisterInstance(this);
        }
예제 #7
0
        public void TestFindFileSystemEntries()
        {
            var fs = new AggregateFileSystem();

            var memfs1 = new MemoryFileSystem();

            memfs1.WriteAllText("/a.txt", "content1");
            memfs1.WriteAllText("/b", "notused");
            fs.AddFileSystem(memfs1);

            var memfs2 = new MemoryFileSystem();

            memfs2.WriteAllText("/a.txt", "content2");
            memfs2.CreateDirectory("/b");
            fs.AddFileSystem(memfs2);

            {
                var entries = fs.FindFileSystemEntries("/a.txt");
                Assert.Equal(2, entries.Count);

                Assert.IsType <FileEntry>(entries[0]);
                Assert.IsType <FileEntry>(entries[1]);
                Assert.Equal(memfs2, entries[0].FileSystem);
                Assert.Equal(memfs1, entries[1].FileSystem);
                Assert.Equal("/a.txt", entries[0].Path.FullName);
                Assert.Equal("/a.txt", entries[1].Path.FullName);
            }

            {
                var entries = fs.FindFileSystemEntries("/b");
                Assert.Single(entries);

                Assert.IsType <DirectoryEntry>(entries[0]);
                Assert.Equal(memfs2, entries[0].FileSystem);
                Assert.Equal("/b", entries[0].Path.FullName);
            }

            {
                var entry = fs.FindFirstFileSystemEntry("/a.txt");
                Assert.NotNull(entry);

                Assert.IsType <FileEntry>(entry);
                Assert.Equal(memfs2, entry.FileSystem);
                Assert.Equal("/a.txt", entry.Path.FullName);
            }
        }
예제 #8
0
        public ScribanBaseTemplate(ChangeLogConfiguration configuration)
        {
            m_Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            m_Filesystem    = new Lazy <IFileSystem>(() =>
            {
                var fileSystem = GetTemplateFileSystem();

                if (!String.IsNullOrEmpty(TemplateSettings.CustomDirectory))
                {
                    var physicalFileSystem = new PhysicalFileSystem();
                    var path = physicalFileSystem.ConvertPathFromInternal(TemplateSettings.CustomDirectory);

                    var aggregateFileSystem = new AggregateFileSystem(fileSystem);
                    aggregateFileSystem.AddFileSystem(physicalFileSystem.GetOrCreateSubFileSystem(path));
                    fileSystem = aggregateFileSystem;
                }

                return(fileSystem);
            });
        }
예제 #9
0
        public SiteObject(ILoggerFactory loggerFactory = null)
        {
            ReadmeAsIndex = true;
            ErrorRedirect = "/404.html";
            var sharedFolder = Path.Combine(AppContext.BaseDirectory, SharedFolderName);

            _contentFileSystems = new List <IFileSystem>();
            var sharedPhysicalFileSystem = new PhysicalFileSystem();

            // Make sure that SharedFileSystem is a read-only filesystem
            SharedFileSystem     = new ReadOnlyFileSystem(new SubFileSystem(sharedPhysicalFileSystem, sharedPhysicalFileSystem.ConvertPathFromInternal(sharedFolder)));
            SharedMetaFileSystem = SharedFileSystem.GetOrCreateSubFileSystem(LunetFolder);

            _fileSystem = new AggregateFileSystem(SharedFileSystem);

            // MetaFileSystem provides an aggregate view of the shared meta file system + the user meta file system
            _metaFileSystem = new AggregateFileSystem(SharedMetaFileSystem);
            MetaFileSystem  = _metaFileSystem;

            ConfigFile = new FileEntry(_fileSystem, UPath.Root / DefaultConfigFileName);

            StaticFiles  = new PageCollection();
            Pages        = new PageCollection();
            DynamicPages = new PageCollection();

            // Create the logger
            LoggerFactory = loggerFactory ?? Microsoft.Extensions.Logging.LoggerFactory.Create(builder =>
            {
                // Similar to builder.AddSimpleConsole
                // But we are using our own console that stays on the same line if the message doesn't have new lines
                builder.AddConfiguration();
                builder.AddProvider(new LoggerProviderIntercept(this))
                .AddFilter(LogFilter)
                .AddConsoleFormatter <SimpleConsoleFormatter, SimpleConsoleFormatterOptions>(configure =>
                {
                    configure.SingleLine = true;
                });
                builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <ILoggerProvider, ConsoleLoggerProvider>());
                LoggerProviderOptions.RegisterProviderOptions <ConsoleLoggerOptions, ConsoleLoggerProvider>(builder.Services);
            });

            Log          = LoggerFactory.CreateLogger("lunet");
            ContentTypes = new ContentTypeManager();

            DefaultPageExtension = DefaultPageExtensionValue;

            Html = new HtmlPage(this);

            CommandLine = new LunetCommandLine(this);

            Statistics = new SiteStatistics();

            Scripts = new ScriptingPlugin(this);

            Content = new ContentPlugin(this);

            Plugins = new OrderedList <ISitePlugin>();

            Builtins      = new BuiltinsObject(this);
            ForceExcludes = new GlobCollection()
            {
                $"**/{LunetFolderName}/{BuildFolderName}/**",
                $"/{DefaultConfigFileName}",
            };
            Excludes = new GlobCollection()
            {
                "**/~*/**",
                "**/.*/**",
                "**/_*/**",
            };
            Includes = new GlobCollection()
            {
                $"**/{LunetFolderName}/**",
            };
            SetValue(SiteVariables.ForceExcludes, ForceExcludes, true);
            SetValue(SiteVariables.Excludes, Excludes, true);
            SetValue(SiteVariables.Includes, Includes, true);

            SetValue(SiteVariables.Pages, Pages, true);

            _pluginBuilders = new ContainerBuilder();
            _pluginBuilders.RegisterInstance(LoggerFactory).As <ILoggerFactory>();
            _pluginBuilders.RegisterInstance(this);
        }