public void SetUp()
 {
     ServiceStackHost.Instance.VirtualFileSources = pathProvider = new MemoryVirtualFiles();
     markdownFormat = new MarkdownFormat
     {
         VirtualPathProvider = pathProvider,
     };
 }
 public void SetUp()
 {
     HostContext.AppHost.VirtualFileSources = pathProvider = new MemoryVirtualFiles();
     markdownFormat = new MarkdownFormat
     {
         VirtualPathProvider = pathProvider,
     };
 }
        protected override void InitializeFileSystem(MemoryVirtualFiles fileSystem)
        {
            base.InitializeFileSystem(fileSystem);

            fileSystem.WriteFile("/views/v1.cshtml", View1Html);
            fileSystem.WriteFile("/views/v2.cshtml", View2Html);
            fileSystem.WriteFile("/views/v3.cshtml", View3Html);
        }
        public void OnBeforeEachTest()
        {
            RazorFormat.Instance = null;

            var fileSystem = new MemoryVirtualFiles();

            RazorFormat = new RazorFormat
            {
                VirtualFileSources = fileSystem,
                EnableLiveReload   = false,
            }.Init();
        }
Exemplo n.º 5
0
            public override List <IVirtualPathProvider> GetVirtualFileSources()
            {
                var existingProviders = base.GetVirtualFileSources();
                var memFs             = new MemoryVirtualFiles();

                foreach (var entry in HtmlFiles)
                {
                    memFs.AppendFile(entry.Key, entry.Value);
                }

                existingProviders.Insert(0, memFs);
                return(existingProviders);
            }
            public override List <IVirtualPathProvider> GetVirtualFileSources()
            {
                var existingProviders = base.GetVirtualFileSources();
                var memFs             = new MemoryVirtualFiles();

                memFs.WriteFile("/file.js", "console.log('foo')");
                memFs.WriteFile("/file.css", ".foo{}");
                memFs.WriteFile("/file.txt", "foo");
                memFs.WriteFile("/default.html", "<body>foo</body>");

                //Give new Memory FS highest priority
                existingProviders.Insert(0, memFs);
                return(existingProviders);
            }
Exemplo n.º 7
0
        public override List <IVirtualPathProvider> GetVirtualFileSources()
        {
            var existingProviders = base.GetVirtualFileSources();
            //return existingProviders;

            var memFs = new MemoryVirtualFiles();

            //Get FileSystem Provider
            var fs = existingProviders.First(x => x is FileSystemVirtualFiles);

            //Process all .html files:
            foreach (var file in fs.GetAllMatchingFiles("*.html"))
            {
                var contents = Minifiers.HtmlAdvanced.Compress(file.ReadAllText());
                memFs.WriteFile(file.VirtualPath, contents);
            }

            //Process all .css files:
            foreach (var file in fs.GetAllMatchingFiles("*.css")
                     .Where(file => !file.VirtualPath.EndsWith(".min.css")))
            {
                var contents = Minifiers.Css.Compress(file.ReadAllText());
                memFs.WriteFile(file.VirtualPath, contents);
            }

            //Process all .js files
            foreach (var file in fs.GetAllMatchingFiles("*.js")
                     .Where(file => !file.VirtualPath.EndsWith(".min.js")))
            {
                try
                {
                    var js       = file.ReadAllText();
                    var contents = Minifiers.JavaScript.Compress(js);
                    memFs.WriteFile(file.VirtualPath, contents);
                }
                catch (Exception ex)
                {
                    //Report any errors in StartUpErrors collection on ?debug=requestinfo
                    base.OnStartupException(new Exception("JSMin Error in {0}: {1}".Fmt(file.VirtualPath, ex.Message)));
                }
            }

            //Give new Memory FS highest priority
            existingProviders.Insert(0, memFs);
            return(existingProviders);
        }
Exemplo n.º 8
0
 public void Does_evaluate_init_page()
 {
     using (new BasicAppHost
     {
         ConfigureAppHost = host => {
             var templateFiles = new MemoryVirtualFiles();
             templateFiles.WriteFile("_init.html", "{{ initFilter }}");
             host.AddVirtualFileSources.Add(templateFiles);
             host.Plugins.Add(new SharpPagesFeature {
                 ScriptMethods = { new InitFilter() }
             });
         }
     }.Init())
     {
         Assert.That(InitFilter.HasInit);
     }
 }
Exemplo n.º 9
0
        public void OnBeforeEachTest()
        {
            RazorFormat.Instance = null;

            var fileSystem = new MemoryVirtualFiles();

            fileSystem.WriteFile("/views/TheLayout.cshtml", LayoutHtml);
            InitializeFileSystem(fileSystem);

            RazorFormat = new RazorFormat
            {
                VirtualFileSources             = fileSystem,
                PageBaseType                   = typeof(CustomRazorBasePage <>),
                EnableLiveReload               = false,
                PrecompilePages                = PrecompileEnabled,
                WaitForPrecompilationOnStartup = WaitForPrecompileEnabled,
            }.Init();
        }
        public void 新增資料夾()
        {
            var executingAssembly = Assembly.GetExecutingAssembly();
            var rootPath          = Path.GetDirectoryName(executingAssembly.Location);
            var content           = "This is test string";
            var subPath           = "TestFolder";
            var subPath1          = $"{subPath}/1/1_1/1_1_1";
            var subPath2          = $"{subPath}/2";
            var fileSystem        = new FileSystemVirtualFiles(rootPath);

            fileSystem.EnsureDirectory(subPath1);
            fileSystem.EnsureDirectory(subPath2);
            fileSystem.AppendFile($"{subPath}/1.txt", content);
            var memoryFileSystem = new MemoryVirtualFiles();

            // var memoryFileSystem1 = fileSystem.GetMemoryVirtualFiles();

            // var nonDefaultValues = fileSystem.PopulateWithNonDefaultValues(memoryFileSystem);
            // var memoryFileSystem2 = memoryFileSystem.PopulateWith(fileSystem);

            var subFolder = new InMemoryVirtualDirectory(memoryFileSystem, subPath);
            var subFile   = new InMemoryVirtualFile(memoryFileSystem, subFolder);

            memoryFileSystem.AddFile(subFile);

            //無法單獨加入資料夾
            var subFolder1 = new InMemoryVirtualDirectory(memoryFileSystem, "1", subFolder);

            var subFolder2 = new InMemoryVirtualDirectory(memoryFileSystem, "1_1", subFolder1);

            subFolder2.AddFile("2.txt", content);

            var directories = memoryFileSystem.RootDirectory.Directories;
            var files       = memoryFileSystem.Files;

            Console.WriteLine();

            //
            // // memorySystem.AddFile(new InMemoryVirtualFile(fileSystem, directory));
            //
            // //            memorySystem.AppendFile($"{subPath1}/1.txt",content);
            // var files = memoryFileSystem.GetAllFiles();
        }
Exemplo n.º 11
0
        public override void Configure(Container container)
        {
            container.AddSingleton <IAuthRepository>(c =>
                                                     new InMemoryAuthRepository());

            var dbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);

            container.Register <IDbConnectionFactory>(dbFactory);

            container.AddSingleton <IAuthRepository>(c =>
                                                     new OrmLiteAuthRepository <AppUser, UserAuthDetails>(c.Resolve <IDbConnectionFactory>())
            {
                UseDistinctRoleTables = true
            });
            var memoryVirtualFiles = new MemoryVirtualFiles();

            VirtualFiles = memoryVirtualFiles;
            Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                                        new IAuthProvider[]
            {
                new BasicAuthProvider(AppSettings),
                new CredentialsAuthProvider(AppSettings),
                // new NetCoreIdentityAuthProvider(AppSettings)
                // {
                //     // Adapter to enable ServiceStack Auth in MVC
                //     AdminRoles = {"Admin"},
                // },
                new JwtAuthProvider(AppSettings)
                {
                    RequireSecureConnection = false,
                    AuthKeyBase64           = authKey
                },
            })
            {
            });
            Plugins.Add(new AutoQueryFeature()
            {
            });
            Plugins.Add(new ValidationFeature());
            ConfigureFn?.Invoke(this, container);
        }
Exemplo n.º 12
0
    public async Task Create_TypeScript_Definitions_Publish()
    {
        Directory.SetCurrentDirectory(NetCoreTestsDir);
        await ProcessUtils.RunShellAsync("rd /q /s types && tsc",
                                         onOut :   Console.WriteLine,
                                         onError : Console.Error.WriteLine);

        // Export API Explorer's .d.ts to 'explorer'
        Directory.Move("types/ui", "types/explorer");
        Directory.Move("types/admin-ui", "types/admin");

        FileSystemVirtualFiles.RecreateDirectory("dist");
        File.Copy("../NorthwindAuto/node_modules/@servicestack/client/dist/index.d.ts", "dist/client.d.ts");
        File.Copy("../NorthwindAuto/node_modules/@servicestack/client/dist/index.d.ts", "../NorthwindAuto/lib/client.d.ts", overwrite: true);

        var memFs   = new MemoryVirtualFiles();
        var typesFs = new FileSystemVirtualFiles("types");
        var distFs  = new FileSystemVirtualFiles("dist");

        var typesFile = typesFs.GetFile("lib/types.d.ts");

        memFs.WriteFile("0_" + typesFile.Name, typesFile);
        memFs.TransformAndCopy("shared", typesFs, distFs);

        memFs.Clear();
        memFs.TransformAndCopy("locode", typesFs, distFs);

        memFs.Clear();
        memFs.TransformAndCopy("explorer", typesFs, distFs);

        memFs.Clear();
        memFs.TransformAndCopy("admin", typesFs, distFs);

        var libFs = new FileSystemVirtualFiles("../../../../servicestack-ui".AssertDir());

        libFs.CopyFrom(distFs.GetAllFiles());
    }
Exemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InMemoryVirtualDirectory"/> class.
 /// </summary>
 /// <param name="pathProvider">The path provider.</param>
 /// <param name="dirPath">The dir path.</param>
 /// <param name="parentDir">The parent dir.</param>
 public InMemoryVirtualDirectory(MemoryVirtualFiles pathProvider, string dirPath, IVirtualDirectory parentDir = null)
     : base(pathProvider, parentDir)
 {
     this.pathProvider = pathProvider;
     this.DirPath      = dirPath;
 }
Exemplo n.º 14
0
 protected virtual void InitializeFileSystem(MemoryVirtualFiles fileSystem)
 {
 }