From b98ef483645e6e57d404ab457dd12234045eebaf Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 17 Jan 2019 16:41:23 +0300 Subject: [PATCH] Created a console test app. --- samples/MicroserviceDemo/MicroserviceDemo.sln | 10 ++++ .../authserver/AuthServer.Host/Startup.cs | 11 ---- .../ConsoleClientDemo/ClientDemoService.cs | 35 ++++++++++++ .../ConsoleClientDemo.csproj | 30 ++++++++++ .../ConsoleClientDemoModule.cs | 17 ++++++ .../ConsoleClientDemo/Program.cs | 55 +++++++++++++++++++ .../ConsoleClientDemo/appsettings.json | 18 ++++++ .../identity/IdentityService.Host/Startup.cs | 13 +---- 8 files changed, 166 insertions(+), 23 deletions(-) create mode 100644 samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ClientDemoService.cs create mode 100644 samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemo.csproj create mode 100644 samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemoModule.cs create mode 100644 samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/Program.cs create mode 100644 samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/appsettings.json diff --git a/samples/MicroserviceDemo/MicroserviceDemo.sln b/samples/MicroserviceDemo/MicroserviceDemo.sln index 4d660d2113..a7eea46620 100644 --- a/samples/MicroserviceDemo/MicroserviceDemo.sln +++ b/samples/MicroserviceDemo/MicroserviceDemo.sln @@ -15,6 +15,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "authserver", "authserver", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthServer.Host", "applications\authserver\AuthServer.Host\AuthServer.Host.csproj", "{E015158C-BCDB-4890-8B3B-1CEE1FC817CC}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "consoleclient", "consoleclient", "{72DA455F-4BD5-401D-8B2B-EE20F0C8D1AE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleClientDemo", "applications\consoleclient\ConsoleClientDemo\ConsoleClientDemo.csproj", "{06383443-5840-4C95-A038-A4B9E9211202}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,6 +33,10 @@ Global {E015158C-BCDB-4890-8B3B-1CEE1FC817CC}.Debug|Any CPU.Build.0 = Debug|Any CPU {E015158C-BCDB-4890-8B3B-1CEE1FC817CC}.Release|Any CPU.ActiveCfg = Release|Any CPU {E015158C-BCDB-4890-8B3B-1CEE1FC817CC}.Release|Any CPU.Build.0 = Release|Any CPU + {06383443-5840-4C95-A038-A4B9E9211202}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06383443-5840-4C95-A038-A4B9E9211202}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06383443-5840-4C95-A038-A4B9E9211202}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06383443-5840-4C95-A038-A4B9E9211202}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -38,6 +46,8 @@ Global {DBED3AEE-9861-48B3-9F8C-49D2779CDBB8} = {146D0838-B1E3-44C2-BD81-BED2153C02CE} {C53F39BA-7409-4957-8FF8-C04D7377CA62} = {8F6834D7-E6FA-4A04-83BB-955F68EA0A0A} {E015158C-BCDB-4890-8B3B-1CEE1FC817CC} = {C53F39BA-7409-4957-8FF8-C04D7377CA62} + {72DA455F-4BD5-401D-8B2B-EE20F0C8D1AE} = {8F6834D7-E6FA-4A04-83BB-955F68EA0A0A} + {06383443-5840-4C95-A038-A4B9E9211202} = {72DA455F-4BD5-401D-8B2B-EE20F0C8D1AE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {37474F0D-2E52-4D2F-B39B-7FE3FF31B4EC} diff --git a/samples/MicroserviceDemo/applications/authserver/AuthServer.Host/Startup.cs b/samples/MicroserviceDemo/applications/authserver/AuthServer.Host/Startup.cs index a80027ad0d..f9d963021c 100644 --- a/samples/MicroserviceDemo/applications/authserver/AuthServer.Host/Startup.cs +++ b/samples/MicroserviceDemo/applications/authserver/AuthServer.Host/Startup.cs @@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Serilog; using Volo.Abp; namespace AuthServer.Host @@ -22,16 +21,6 @@ namespace AuthServer.Host public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - //TODO: Need to this? - loggerFactory - .AddConsole() - .AddDebug() - .AddSerilog(new LoggerConfiguration() - .Enrich.FromLogContext() - .WriteTo.File("Logs/logs.txt") - .CreateLogger() - ); - app.InitializeApplication(); } } diff --git a/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ClientDemoService.cs b/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ClientDemoService.cs new file mode 100644 index 0000000000..a488d17635 --- /dev/null +++ b/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ClientDemoService.cs @@ -0,0 +1,35 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Identity; + +namespace ConsoleClientDemo +{ + public class ClientDemoService : ITransientDependency + { + private readonly IIdentityUserAppService _userAppService; + + public ClientDemoService(IIdentityUserAppService userAppService) + { + _userAppService = userAppService; + } + + public async Task RunAsync() + { + await TestIdentityService(); + } + + private async Task TestIdentityService() + { + var output = await _userAppService.GetListAsync(new GetIdentityUsersInput()); + + Console.WriteLine("*** IdentityService ***"); + Console.WriteLine("Total user count: " + output.TotalCount); + + foreach (var user in output.Items) + { + Console.WriteLine($"- UserName={user.UserName}, Email={user.Email}, Name={user.Name}, Surname={user.Surname}"); + } + } + } +} \ No newline at end of file diff --git a/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemo.csproj b/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemo.csproj new file mode 100644 index 0000000000..b440dd8c0c --- /dev/null +++ b/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemo.csproj @@ -0,0 +1,30 @@ + + + + Exe + netcoreapp2.2 + + + + + + + + + + + + + + + + + + + + PreserveNewest + Always + + + + diff --git a/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemoModule.cs b/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemoModule.cs new file mode 100644 index 0000000000..10bc6e9d4a --- /dev/null +++ b/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/ConsoleClientDemoModule.cs @@ -0,0 +1,17 @@ +using Volo.Abp.Autofac; +using Volo.Abp.Http.Client.IdentityModel; +using Volo.Abp.Identity; +using Volo.Abp.Modularity; + +namespace ConsoleClientDemo +{ + [DependsOn( + typeof(AbpAutofacModule), + typeof(AbpHttpClientIdentityModelModule), + typeof(AbpIdentityHttpApiClientModule) + )] + public class ConsoleClientDemoModule : AbpModule + { + + } +} diff --git a/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/Program.cs b/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/Program.cs new file mode 100644 index 0000000000..9626e874a1 --- /dev/null +++ b/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/Program.cs @@ -0,0 +1,55 @@ +using Serilog; +using Serilog.Events; +using System; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.Threading; + +namespace ConsoleClientDemo +{ + internal class Program + { + private static void Main(string[] args) + { + InitializeSerilog(); + + Log.Information("Starting ConsoleClientDemo..."); + + try + { + using (var application = AbpApplicationFactory.Create(options => + { + options.Services.AddLogging(loggingBuilder => + { + loggingBuilder.AddSerilog(dispose: true); + }); + })) + { + application.Initialize(); + + var demo = application.ServiceProvider.GetRequiredService(); + AsyncHelper.RunSync(() => demo.RunAsync()); + + Console.WriteLine("Press ENTER to stop application..."); + Console.ReadLine(); + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + Log.Error(ex.StackTrace); + throw; + } + } + + private static void InitializeSerilog() + { + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Debug() + .MinimumLevel.Override("Microsoft", LogEventLevel.Information) + .Enrich.FromLogContext() + .WriteTo.File("Logs/logs.txt") + .CreateLogger(); + } + } +} diff --git a/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/appsettings.json b/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/appsettings.json new file mode 100644 index 0000000000..c95b0318a8 --- /dev/null +++ b/samples/MicroserviceDemo/applications/consoleclient/ConsoleClientDemo/appsettings.json @@ -0,0 +1,18 @@ +{ + "RemoteServices": { + "Default": { + "BaseUrl": "http://localhost:63568/" + } + }, + "IdentityClients": { + "Default": { + "GrantType": "password", + "ClientId": "console-client-demo", + "ClientSecret": "1q2w3e*", + "UserName": "admin", + "UserPassword": "1q2w3E*", + "Authority": "http://localhost:64999", + "Scope": "IdentityService" + } + } +} \ No newline at end of file diff --git a/samples/MicroserviceDemo/microservices/identity/IdentityService.Host/Startup.cs b/samples/MicroserviceDemo/microservices/identity/IdentityService.Host/Startup.cs index 679d812bd7..f472affe55 100644 --- a/samples/MicroserviceDemo/microservices/identity/IdentityService.Host/Startup.cs +++ b/samples/MicroserviceDemo/microservices/identity/IdentityService.Host/Startup.cs @@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Serilog; using Volo.Abp; namespace IdentityService.Host @@ -23,17 +22,7 @@ namespace IdentityService.Host public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - //TODO: Need to this? - loggerFactory - .AddConsole() - .AddDebug() - .AddSerilog(new LoggerConfiguration() - .Enrich.FromLogContext() - .WriteTo.File("Logs/logs.txt") - .CreateLogger() - ); - - app.InitializeApplication(); + app.InitializeApplication(); } } }