Exemple #1
0
        public async Task <bool> Execute(IPluginCommunication autoRest)
        {
            var ns = await autoRest.GetValue <string>("namespace");

            await autoRest.WriteFile($"{ns}.csproj", _csProjContent, "source-file-csharp");

            return(true);
        }
        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);
        }
 private string GetRequiredOption(IPluginCommunication autoRest, string name)
 {
     return(autoRest.GetValue <string?>(name).GetAwaiter().GetResult() ?? throw new InvalidOperationException($"{name} configuration parameter is required"));
 }