public void Copy_Razor_files_to_AWS_Bucket()
        {
            var fs = new FileSystemVirtualPathProvider(appHost, "~/../RazorRockstars.WebHost".MapHostAbsolutePath());

            var skipDirs = new[] { "bin", "obj" };
            var matchingFileTypes = new[] { "cshtml", "md", "css", "js", "png", "jpg" };
            var replaceHtmlTokens = new Dictionary<string, string> {
                { "title-bg.png", "title-bg-aws.png" }, //Title Background
                { "https://gist.github.com/3617557.js", "https://gist.github.com/mythz/396dbf54ce6079cc8b2d.js" }, //AppHost.cs
                { "https://gist.github.com/3616766.js", "https://gist.github.com/mythz/ca524426715191b8059d.js" }, //S3 RockstarsService.cs
                { "RazorRockstars.WebHost/RockstarsService.cs", "RazorRockstars.S3/RockstarsService.cs" },         //S3 RockstarsService.cs
                { "http://github.com/ServiceStackApps/RazorRockstars/",
                  "https://github.com/ServiceStackApps/RazorRockstars/tree/master/src/RazorRockstars.S3" }         //Link to GitHub project
            };

            foreach (var file in fs.GetAllFiles())
            {
                if (skipDirs.Any(x => file.VirtualPath.StartsWith(x))) continue;
                if (!matchingFileTypes.Contains(file.Extension)) continue;

                if (file.Extension == "cshtml")
                {
                    var html = file.ReadAllText();
                    replaceHtmlTokens.Each(x => html = html.Replace(x.Key, x.Value));
                    s3.WriteFile(file.VirtualPath, html);
                }
                else
                {
                    s3.WriteFile(file);
                }
            }
        }
Ejemplo n.º 2
0
        public void Import_RestFiles_into_S3()
        {
            var fs = new FileSystemVirtualPathProvider(appHost, "~/restfiles".MapHostAbsolutePath());
            var skipDirs = new[] { "restfiles/files" };

            foreach (var file in fs.GetAllFiles())
            {
                if (skipDirs.Any(x => file.VirtualPath.StartsWith(x))) continue;
                s3.WriteFile(file, "restfiles/files".CombineWith(file.VirtualPath));
            }
        }
        public override void OnConfigLoad()
        {
            if (app != null)
            {
                //Initialize VFS
                var env = app.ApplicationServices.GetService<IHostingEnvironment>();
                Config.WebHostPhysicalPath = env.ContentRootPath;

                //Set VirtualFiles to point to ContentRootPath (Project Folder)
                VirtualFiles = new FileSystemVirtualPathProvider(this, env.ContentRootPath);
            }
        }
Ejemplo n.º 4
0
        private void ImportData()
        {
            var dir = new FileSystemVirtualPathProvider(this, BaseDir ?? Config.WebHostPhysicalPath);

            var fileSettings = dir.GetFile("app.settings");
            var appSettings = fileSettings != null
                ? new DictionarySettings(fileSettings.ReadAllText().ParseKeyValueText(delimiter: " "))
                : new DictionarySettings();

            var fileServerLabels = dir.GetFile("server.labels");
            var serverLabels = fileServerLabels != null
                ? fileServerLabels.ReadAllText().ParseKeyValueText(delimiter: " ")
                : null;

            var fileTestLabels = dir.GetFile("test.labels");
            var testLabels = fileTestLabels != null
                ? fileTestLabels.ReadAllText().ParseKeyValueText(delimiter: " ")
                : null;

            using (var admin = Resolve<AdminServices>())
            {
                var db = admin.Db;
                db.DropAndCreateTable<TestPlan>();
                db.DropAndCreateTable<TestRun>();
                db.DropAndCreateTable<TestResult>();

                const int planId = 1;
                admin.CreateTestPlan(new TestPlan
                {
                    Id = planId,
                    Name = appSettings.Get("TestPlanName", "Benchmarks"),
                    ServerLabels = serverLabels,
                    TestLabels = testLabels,
                });

                var testRun = admin.CreateTestRun(planId);


                var files = UploadFile != null
                    ? dir.GetAllMatchingFiles(UploadFile)
                    : dir.GetAllMatchingFiles("*.txt")
                        .Concat(dir.GetAllMatchingFiles("*.zip"));

                admin.Request = new BasicRequest
                {
                    Files = files.Map(x => new HttpFile
                    {
                        ContentLength = x.Length,
                        ContentType = MimeTypes.GetMimeType(x.Name),
                        FileName = x.Name,
                        InputStream = x.OpenRead(),
                    } as IHttpFile).ToArray()
                };

                if (admin.Request.Files.Length > 0)
                {
                    admin.Post(new UploadTestResults
                    {
                        TestPlanId = 1,
                        TestRunId = testRun.Id,
                        CreateNewTestRuns = true,
                    });
                }
            }
        }
        public void Update_Razor_and_Markdown_pages_at_runtime()
        {
            var fs = new FileSystemVirtualPathProvider(appHost, "~/../RazorRockstars.WebHost".MapHostAbsolutePath());

            var kurtRazor = fs.GetFile("stars/dead/cobain/default.cshtml");
            s3.WriteFile(kurtRazor.VirtualPath, "[UPDATED RAZOR] " + kurtRazor.ReadAllText());

            var kurtMarkdown = fs.GetFile("stars/dead/cobain/Content.md");
            s3.WriteFile(kurtMarkdown.VirtualPath, "[UPDATED MARKDOWN] " + kurtMarkdown.ReadAllText());
        }