Пример #1
0
        static async Task RunAsync()
        {
            var settings  = new SigSpecGeneratorSettings();
            var generator = new SigSpecGenerator(settings);

            // TODO: Add PR to SignalR Core with new IHubDescriptionCollectionProvider service
            var document = await generator.GenerateForHubsAsync(new Dictionary <string, Type>
            {
                { "chat", typeof(ChatHub) }
            });

            var json = document.ToJson();

            Console.WriteLine("\nGenerated SigSpec document:");
            Console.WriteLine(json);
            Console.ReadKey();

            var tsCodeGeneratorSettings = new SigSpecToTypeScriptGeneratorSettings();
            var tsCodeGenerator         = new SigSpecToTypeScriptGenerator(tsCodeGeneratorSettings);
            var file = tsCodeGenerator.GenerateFile(document);

            Console.WriteLine("\n\nGenerated SigSpec TypeScript code:");
            Console.WriteLine(file);
            Console.ReadKey();

            var codeGeneratorSettings = new SigSpecToCSharpGeneratorSettings();
            var codeGenerator         = new SigSpecToCSharpGenerator(codeGeneratorSettings);

            file = codeGenerator.GenerateClients(document);

            Console.WriteLine("\n\nGenerated SigSpec CSharp clients:");
            Console.WriteLine(file);
            Console.ReadKey();
        }
Пример #2
0
        static void Run(string path)
        {
            var settings  = new SigSpecGeneratorSettings();
            var generator = new SigSpecGenerator(settings);

            // TODO: Add PR to SignalR Core with new IHubDescriptionCollectionProvider service
            var document = generator.GenerateForHubs(new Dictionary <string, Type>
            {
                { "room", typeof(RoomHub) },
                { "game", typeof(GameHub) },
            });

            var json = document.ToJson();

            Console.WriteLine("\nGenerated SigSpec document:");
            Console.WriteLine(json);

            var codeGeneratorSettings = new SigSpecToTypeScriptGeneratorSettings();
            var codeGenerator         = new SigSpecToTypeScriptGenerator(codeGeneratorSettings);
            var file = codeGenerator.GenerateFile(document);

            Console.WriteLine("\n\nGenerated SigSpec TypeScript code:");
            Console.WriteLine(file);
            var fi = new FileInfo(path);

            if (fi.Exists)
            {
                fi.Delete();
            }
            //Create a file to write to.
            using (var sw = fi.CreateText())
            {
                sw.Write(file);
            }
            Console.WriteLine(fi.FullName);
        }
Пример #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSignalR();

            // TODO: Automatically look hubs up
            services.AddSigSpecDocument(options =>
            {
                options.Hubs["/chat"] = typeof(ChatHub);

                options.OutputPath        = "sigspec.json";
                options.CommandLineAction = document => // run cli with "donet run -- --sigspec""
                {
                    var generator = new SigSpecToTypeScriptGenerator(
                        new SigSpecToTypeScriptGeneratorSettings
                    {
                        TypeScriptGeneratorSettings =
                        {
                            TypeStyle = TypeScriptTypeStyle.Interface
                        }
                    });

                    var code = generator.GenerateFile(document);
                    File.WriteAllText("signalr-api.ts", code);
                };
            });

            services.AddCors(c =>
            {
                c.AddDefaultPolicy(policy =>
                {
                    policy.AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowAnyOrigin();
                });
            });
        }