Example #1
0
        public static async Task RunAsync(string[] args)
        {
            var basePath = args.Single(a => !a.StartsWith("--"));

            var configuration = LoadConfiguration(basePath, File.ReadAllText(Path.Combine(basePath, "Configuration.json")));
            var codeModel     = CodeModelSerialization.DeserializeCodeModel(File.ReadAllText(Path.Combine(basePath, "CodeModel.yaml")));

            var workspace = await new CSharpGen().ExecuteAsync(codeModel, configuration);

            await foreach (var file in workspace.GetGeneratedFilesAsync())
            {
                if (string.IsNullOrEmpty(file.Text))
                {
                    continue;
                }
                var filename = Path.Combine(basePath, file.Name);
                Console.WriteLine($"Writing {filename}");
                Directory.CreateDirectory(Path.GetDirectoryName(filename));
                await File.WriteAllTextAsync(filename, file.Text);
            }
        }
Example #2
0
        public async Task <bool> Execute(IPluginCommunication autoRest)
        {
            string codeModelFileName = (await autoRest.ListInputs()).FirstOrDefault();

            if (string.IsNullOrEmpty(codeModelFileName))
            {
                throw new Exception("Generator did not receive the code model file.");
            }

            var codeModelYaml = await autoRest.ReadFile(codeModelFileName);

            CodeModel codeModel = CodeModelSerialization.DeserializeCodeModel(codeModelYaml);

            var configuration = new Configuration(
                new Uri(GetRequiredOption(autoRest, "output-folder")).LocalPath,
                GetRequiredOption(autoRest, "namespace"),
                autoRest.GetValue <string?>("library-name").GetAwaiter().GetResult(),
                new Uri(GetRequiredOption(autoRest, "shared-source-folder")).LocalPath,
                autoRest.GetValue <bool?>("save-inputs").GetAwaiter().GetResult() ?? false,
                autoRest.GetValue <bool?>("azure-arm").GetAwaiter().GetResult() ?? false,
                autoRest.GetValue <bool?>("public-clients").GetAwaiter().GetResult() ?? false
                );

            if (configuration.SaveInputs)
            {
                await autoRest.WriteFile("Configuration.json", StandaloneGeneratorRunner.SaveConfiguration(configuration), "source-file-csharp");

                await autoRest.WriteFile("CodeModel.yaml", codeModelYaml, "source-file-csharp");
            }

            var project = await ExecuteAsync(codeModel, configuration);

            await foreach (var file in project.GetGeneratedFilesAsync())
            {
                await autoRest.WriteFile(file.Name, file.Text, "source-file-csharp");
            }

            return(true);
        }