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(); }
/// <summary> /// Generates the document. /// </summary> /// <returns>The JSON.</returns> public async Task <string> GenerateJsonAsync() { var generator = new SigSpecGenerator(_settings); var document = await generator.GenerateForHubsAsync(_settings.Hubs, _settings.Template); return(document.ToJson()); }
public static void Generate <T>(string route, string outputPath) where T : class { var settings = new SigSpecGeneratorSettings(); var generator = new SigSpecGenerator(settings); var document = generator.GenerateForHubsAsync(new Dictionary <string, Type> { { "route".Trim('/'), typeof(T) } }).GetAwaiter().GetResult(); var codeGeneratorSettings = new SigSpecToJavaScriptGeneratorSettings(); var codeGenerator = new SigSpecToJavaScriptGenerator(codeGeneratorSettings); var file = codeGenerator.GenerateFile(document); File.WriteAllText(outputPath, file); }
private async Task RespondWithSigSpecJsonAsync(HttpResponse response) { response.StatusCode = 200; response.ContentType = "application/json;charset=utf-8"; var generator = new SigSpecGenerator(_settings); // TODO: Add PR to SignalR Core with new IHubDescriptionCollectionProvider service // TODO: Upgrade to .NET Core 3.1 var hubs = _settings.Hubs .ToDictionary(k => k.Name.ToLower(), k => k); var document = await generator.GenerateForHubsAsync(hubs, _settings.Template); var json = document.ToJson(); await response.WriteAsync(json, new UTF8Encoding(false)); }
/// <summary> /// Generates the _document. /// </summary> /// <returns>The JSON.</returns> public async Task <string> GenerateJsonAsync() { var generator = new SigSpecGenerator(_settings); await _semaphoreSlim.WaitAsync(); try { if (_document == null) { _document = await generator.GenerateForHubsAsync(_settings.Hubs, _settings.Template); } } finally { _semaphoreSlim.Release(); } return(_document.ToJson()); }
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); }
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> { { "progress", typeof(ProgressHub) } }); //var json = document.ToJson(); //Console.WriteLine("\nGenerated SigSpec document:"); //Console.WriteLine(json); //Console.ReadKey(); var codeGeneratorSettings = new SigSpecToJavaScriptGeneratorSettings(); var codeGenerator = new SigSpecToJavaScriptGenerator(codeGeneratorSettings); var file = codeGenerator.GenerateFile(document); Console.WriteLine("Generated SigSpec JavaScript code:\n\n"); Console.WriteLine(file); Console.ReadKey(); }
/// <summary> /// Generates the document. /// </summary> /// <returns>The JSON.</returns> public async Task <SigSpecDocument> GenerateDocumentAsync() { var generator = new SigSpecGenerator(_settings); return(await generator.GenerateForHubsAsync(_settings.Hubs, _settings.Template)); }