コード例 #1
0
        public void Copy_Razor_files_to_AWS_Bucket()
        {
            var fs = new FileSystemVirtualFiles("~/../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);
                }
            }
        }
コード例 #2
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());
    }
コード例 #3
0
        public object Any(Protoc request)
        {
            var tmpId = (Request as IHasStringId)?.Id?.Replace("|", "").Replace(".", "") ?? Guid.NewGuid().ToString();
            var files = request.Files ?? new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(request.ProtoUrl))
            {
                var fileName = request.ProtoUrl.EndsWith(".proto")
                    ? request.ProtoUrl.LastRightPart('/')
                    : "services.proto";
                files[fileName] = request.ProtoUrl.GetStringFromUrl();
            }

            if (Request.Files.Length > 0)
            {
                foreach (var httpFile in Request.Files)
                {
                    var fileName = httpFile.FileName ?? httpFile.Name;
                    if (!fileName.EndsWith(".proto") && !fileName.EndsWith(".zip"))
                    {
                        throw new ArgumentException($"Unsupported file '{fileName}'. Only .proto or .zip files supported.");
                    }

                    if (fileName.EndsWith(".zip"))
                    {
                        var tmpZipPath = Path.GetTempFileName();
                        var tmpDir     = Path.Combine(Path.GetTempPath(), "protoc-api", tmpId);
                        httpFile.SaveTo(tmpZipPath);

                        ZipFile.ExtractToDirectory(tmpZipPath, tmpDir);

                        var tmpDirInfo      = new DirectoryInfo(tmpDir);
                        var hasProtoRootDir = tmpDirInfo.GetFiles("*.proto").Length > 0;
                        var fsZipDir        = !hasProtoRootDir && tmpDirInfo.GetDirectories().Length == 1
                            ? new FileSystemVirtualFiles(tmpDirInfo.GetDirectories()[0].FullName)
                            : new FileSystemVirtualFiles(tmpDirInfo.FullName);

                        foreach (var file in fsZipDir.GetAllFiles().Where(x => x.Extension == "proto"))
                        {
                            files[file.VirtualPath] = file.ReadAllText();
                        }
                    }
                    else
                    {
                        files[fileName] = httpFile.InputStream.ReadToEnd();
                    }
                }
            }

            if (files.IsEmpty())
            {
                throw new ArgumentNullException(nameof(request.Files));
            }

            var tmpPath = Path.Combine(ProtocConfig.TempDirectory, tmpId);
            var outPath = Path.Combine(tmpPath, "out");

            try { Directory.CreateDirectory(outPath); } catch {}

            var fs = new FileSystemVirtualFiles(tmpPath);

            fs.WriteFiles(files);

            var langOptions = ProtocConfig.Languages[request.Lang];
            var args        = StringBuilderCache.Allocate();

            var outArgs = "";

            if (!langOptions.OutModifiers.IsEmpty())
            {
                foreach (var modifier in langOptions.OutModifiers)
                {
                    if (outArgs.Length > 0)
                    {
                        outArgs += ",";
                    }
                    outArgs += modifier;
                }
                if (outArgs.Length > 0)
                {
                    outArgs += ":";
                }
            }

            var grpcOut = "";

            if (langOptions.GrpcOutModifiers != null)
            {
                grpcOut = " --grpc_out=";
                for (var i = 0; i < langOptions.GrpcOutModifiers.Length; i++)
                {
                    if (i > 0)
                    {
                        grpcOut += ",";
                    }

                    var modifier = langOptions.GrpcOutModifiers[i];
                    grpcOut += modifier;
                }

                if (langOptions.GrpcOutModifiers.Length > 0)
                {
                    grpcOut += ":";
                }
                grpcOut += "out";
            }

            args.AppendFormat($"-I . -I \"{ProtocConfig.ProtoIncludeDirectory}\" --{langOptions.Lang}_out={outArgs}out{grpcOut}");

            if (!langOptions.GrpcWebModifiers.IsEmpty())
            {
                var webArgs = "";
                foreach (var modifier in langOptions.GrpcWebModifiers)
                {
                    if (webArgs.Length > 0)
                    {
                        webArgs += ",";
                    }
                    webArgs += modifier;
                }
                if (webArgs.Length > 0)
                {
                    webArgs += ":";
                }
                args.AppendFormat($" --grpc-web_out={webArgs}out");
            }

            if (!langOptions.Args.IsEmpty())
            {
                foreach (var arg in langOptions.Args)
                {
                    args.Append($" {arg}");
                }
            }

            if (!langOptions.IndividuallyPerFile)
            {
                foreach (var entry in files)
                {
                    args.Append($" {entry.Key}");
                }

                exec(tmpPath, StringBuilderCache.ReturnAndFree(args));
            }
            else
            {
                var argsBase = StringBuilderCache.ReturnAndFree(args);
                foreach (var entry in files)
                {
                    exec(tmpPath, $"{argsBase} {entry.Key}");
                }
            }

            var serviceName = files.Count == 1 ? files.Keys.First() : "grpc";
            var archiveUrl  = Request.ResolveAbsoluteUrl(new GetArchive {
                RequestId = tmpId, FileName = $"{serviceName}.{langOptions.Lang}.zip"
            }.ToGetUrl());

            if (Request.QueryString["zip"] != null)
            {
                return(new HttpResult(new ProtocResponse {
                    ArchiveUrl = archiveUrl
                })
                {
                    Location = archiveUrl
                });
            }

            var response = new ProtocResponse {
                GeneratedFiles = new Dictionary <string, string>(),
                ArchiveUrl     = archiveUrl,
            };

            var fsOut    = new FileSystemVirtualFiles(Path.Combine(tmpPath, "out"));
            var genFiles = fsOut.GetAllFiles();

            foreach (var virtualFile in genFiles)
            {
                response.Lang = request.Lang;
                response.GeneratedFiles[virtualFile.VirtualPath] = virtualFile.GetTextContentsAsMemory().ToString();
            }

            return(response);
        }