示例#1
0
        public static async Task <int> Main(string[] args)
        {
            if (args.Contains("--standalone"))
            {
                await StandaloneGeneratorRunner.RunAsync(args);

                return(0);
            }

            if (args.Contains("--launch-debugger") && !Debugger.IsAttached)
            {
                Debugger.Launch();
            }

            if (!HasServerArgument(args))
            {
                Console.WriteLine("Not a valid invocation of this AutoRest extension. Invoke this extension through the AutoRest pipeline.");
                return(1);
            }

            var connection = new JsonRpcConnection(Console.OpenStandardInput(), Console.OpenStandardOutput(),
                                                   new Dictionary <string, IncomingRequestAction>
            {
                { nameof(IncomingMessageSerializer.GetPluginNames), (c, r) => r.GetPluginNames(PluginProcessor.PluginNames) },
                { nameof(IncomingMessageSerializer.Process), (c, r) => r.Process(c, PluginStart) },
                { nameof(IncomingMessageSerializer.Shutdown), (c, r) => r.Shutdown(c.CancellationTokenSource) }
            });

            connection.Start();

            Console.Error.WriteLine("Shutting Down");
            return(0);
        }
示例#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);
        }