Browse Source

Merge branch 'dev' into maliming/FodyConfigureAwait

pull/2645/head
Halil İbrahim Kalkan 7 years ago
committed by GitHub
parent
commit
3b369df403
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs
  2. 14
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ModuleInfo.cs
  3. 9
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs
  4. 6
      framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs
  5. 2
      framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingHelper.cs
  6. 34
      framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingJsFuncHelper.cs
  7. 1
      modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json
  8. 1
      modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json
  9. 1
      modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hant.json
  10. 19
      modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs
  11. 4
      modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs
  12. 21
      modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs
  13. 10
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs
  14. 22
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs
  15. 5
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs
  16. 6
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs
  17. 6
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs
  18. 11
      modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs
  19. 1
      samples/BasicConsoleApplication/AbpConsoleDemo/AbpConsoleDemo.csproj
  20. 32
      samples/BasicConsoleApplication/AbpConsoleDemo/AppHostedService.cs
  21. 29
      samples/BasicConsoleApplication/AbpConsoleDemo/Program.cs
  22. 34
      samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs
  23. 41
      samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.DbMigrator/Program.cs
  24. 26
      samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs
  25. 25
      samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs
  26. 34
      samples/BookStore-Modular/application/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs
  27. 41
      samples/BookStore-Modular/application/src/Acme.BookStore.DbMigrator/Program.cs
  28. 26
      samples/BookStore-Modular/application/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs
  29. 25
      samples/BookStore-Modular/application/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs
  30. 26
      samples/BookStore-Modular/modules/book-management/test/Acme.BookStore.BookManagement.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs
  31. 25
      samples/BookStore-Modular/modules/book-management/test/Acme.BookStore.BookManagement.HttpApi.Client.ConsoleTestApp/Program.cs
  32. 34
      samples/BookStore/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs
  33. 41
      samples/BookStore/src/Acme.BookStore.DbMigrator/Program.cs
  34. 26
      samples/BookStore/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs
  35. 25
      samples/BookStore/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs
  36. 34
      samples/DashboardDemo/src/DashboardDemo.DbMigrator/DbMigratorHostedService.cs
  37. 41
      samples/DashboardDemo/src/DashboardDemo.DbMigrator/Program.cs
  38. 26
      samples/DashboardDemo/test/DashboardDemo.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs
  39. 25
      samples/DashboardDemo/test/DashboardDemo.HttpApi.Client.ConsoleTestApp/Program.cs
  40. 33
      samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemoHostedService.cs
  41. 55
      samples/MicroserviceDemo/applications/ConsoleClientDemo/Program.cs
  42. 34
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/DbMigratorHostedService.cs
  43. 41
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/Program.cs
  44. 26
      templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs
  45. 25
      templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs
  46. 26
      templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs
  47. 27
      templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs

5
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs

@ -175,7 +175,10 @@ namespace Volo.Abp.AspNetCore.Mvc
parameterDescription.RouteInfo?.IsOptional ?? false, parameterDescription.RouteInfo?.IsOptional ?? false,
parameterDescription.RouteInfo?.DefaultValue, parameterDescription.RouteInfo?.DefaultValue,
parameterDescription.RouteInfo?.Constraints?.Select(c => c.GetType().Name).ToArray(), parameterDescription.RouteInfo?.Constraints?.Select(c => c.GetType().Name).ToArray(),
parameterDescription.Source.Id parameterDescription.Source.Id,
parameterDescription.ModelMetadata.ContainerType != null
? parameterDescription.ParameterDescriptor.Name
: string.Empty
) )
); );
} }

14
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ModuleInfo.cs

@ -7,5 +7,19 @@
public string Namespace { get; set; } public string Namespace { get; set; }
public string DocumentUrl { get; set; } public string DocumentUrl { get; set; }
public string DisplayName { get; set; }
public string ShortDescription { get; set; }
public bool IsPro { get; set; }
public bool EfCoreSupport { get; set; }
public bool MongoDBSupport { get; set; }
public bool AngularUi { get; set; }
public bool MvcUi { get; set; }
} }
} }

9
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs

@ -1,4 +1,4 @@
using System; using System;
namespace Volo.Abp.Http.Modeling namespace Volo.Abp.Http.Modeling
{ {
@ -19,12 +19,14 @@ namespace Volo.Abp.Http.Modeling
public string BindingSourceId { get; set; } public string BindingSourceId { get; set; }
public string DescriptorName { get; set; }
private ParameterApiDescriptionModel() private ParameterApiDescriptionModel()
{ {
} }
public static ParameterApiDescriptionModel Create(string name, string nameOnMethod, Type type, bool isOptional = false, object defaultValue = null, string[] constraintTypes = null, string bindingSourceId = null) public static ParameterApiDescriptionModel Create(string name, string nameOnMethod, Type type, bool isOptional = false, object defaultValue = null, string[] constraintTypes = null, string bindingSourceId = null, string descriptorName = null)
{ {
return new ParameterApiDescriptionModel return new ParameterApiDescriptionModel
{ {
@ -34,7 +36,8 @@ namespace Volo.Abp.Http.Modeling
IsOptional = isOptional, IsOptional = isOptional,
DefaultValue = defaultValue, DefaultValue = defaultValue,
ConstraintTypes = constraintTypes, ConstraintTypes = constraintTypes,
BindingSourceId = bindingSourceId BindingSourceId = bindingSourceId,
DescriptorName = descriptorName
}; };
} }
} }

6
framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs

@ -96,7 +96,11 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
AddAjaxCallParameters(script, action); AddAjaxCallParameters(script, action);
script.AppendLine(" }, ajaxParams));;"); var ajaxParamsIsFromForm = action.Parameters.Any(x => x.BindingSourceId == ParameterBindingSources.Form);
script.AppendLine(ajaxParamsIsFromForm
? " }, $.extend(true, {}, ajaxParams, { contentType: 'application/x-www-form-urlencoded; charset=UTF-8' })));"
: " }, ajaxParams));");
script.AppendLine(" };"); script.AppendLine(" };");
} }

2
framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingHelper.cs

@ -66,7 +66,7 @@ namespace Volo.Abp.Http.ProxyScripting.Generators
return null; return null;
} }
return ProxyScriptingJsFuncHelper.CreateJsObjectLiteral(parameters, indent); return ProxyScriptingJsFuncHelper.CreateJsFormPostData(parameters, indent);
} }
private static string ReplacePathVariables(string url, IList<ParameterApiDescriptionModel> actionParameters) private static string ReplacePathVariables(string url, IList<ParameterApiDescriptionModel> actionParameters)

34
framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingJsFuncHelper.cs

@ -111,8 +111,8 @@ namespace Volo.Abp.Http.ProxyScripting.Generators
public static string GetParamNameInJsFunc(ParameterApiDescriptionModel parameterInfo) public static string GetParamNameInJsFunc(ParameterApiDescriptionModel parameterInfo)
{ {
return parameterInfo.Name == parameterInfo.NameOnMethod return parameterInfo.Name == parameterInfo.NameOnMethod
? NormalizeJsVariableName(parameterInfo.Name.ToCamelCase(), ".") ? NormalizeJsVariableName(parameterInfo.Name.ToCamelCase(), ".")
: NormalizeJsVariableName(parameterInfo.NameOnMethod.ToCamelCase()) + "." + NormalizeJsVariableName(parameterInfo.Name.ToCamelCase(), "."); : NormalizeJsVariableName(parameterInfo.NameOnMethod.ToCamelCase()) + "." + NormalizeJsVariableName(parameterInfo.Name.ToCamelCase(), ".");
} }
public static string CreateJsObjectLiteral(ParameterApiDescriptionModel[] parameters, int indent = 0) public static string CreateJsObjectLiteral(ParameterApiDescriptionModel[] parameters, int indent = 0)
@ -131,9 +131,37 @@ namespace Volo.Abp.Http.ProxyScripting.Generators
return sb.ToString(); return sb.ToString();
} }
public static string GetFormPostParamNameInJsFunc(ParameterApiDescriptionModel parameterInfo)
{
return parameterInfo.Name == parameterInfo.NameOnMethod
? NormalizeJsVariableName((parameterInfo.DescriptorName + parameterInfo.Name).ToCamelCase(), ".")
: NormalizeJsVariableName(parameterInfo.NameOnMethod.ToCamelCase()) + "." + NormalizeJsVariableName((parameterInfo.DescriptorName + parameterInfo.Name).ToCamelCase(), ".");
}
public static string CreateJsFormPostData(ParameterApiDescriptionModel[] parameters, int indent)
{
var sb = new StringBuilder();
for (var i = 0; i < parameters.Length; i++)
{
var and = i < parameters.Length - 1 ? " + '&' + " : string.Empty;
var parameterName = parameters[i].DescriptorName.IsNullOrWhiteSpace()
? parameters[i].Name
: $"{parameters[i].DescriptorName}.{parameters[i].Name}";
sb.Append($"'{parameterName}=' + {GetFormPostParamNameInJsFunc(parameters[i])}{and}");
}
return sb.ToString();
}
public static string GenerateJsFuncParameterList(ActionApiDescriptionModel action, string ajaxParametersName) public static string GenerateJsFuncParameterList(ActionApiDescriptionModel action, string ajaxParametersName)
{ {
var methodParamNames = action.ParametersOnMethod.Select(p => p.Name).Distinct().ToList(); var paramsIsFromForm = action.Parameters.Any(x => x.BindingSourceId == ParameterBindingSources.Form);
var methodParamNames = paramsIsFromForm
? action.Parameters.Select(p => p.DescriptorName + p.Name).Distinct().ToList()
: action.ParametersOnMethod.Select(p => p.Name).Distinct().ToList();
methodParamNames.Add(ajaxParametersName); methodParamNames.Add(ajaxParametersName);
return methodParamNames.Select(prmName => NormalizeJsVariableName(prmName.ToCamelCase())).JoinAsString(", "); return methodParamNames.Select(prmName => NormalizeJsVariableName(prmName.ToCamelCase())).JoinAsString(", ");
} }

1
modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json

@ -11,6 +11,7 @@
"InvalidUserNameOrPassword": "Invalid username or password!", "InvalidUserNameOrPassword": "Invalid username or password!",
"LoginIsNotAllowed": "You are not allowed to login! You need to confirm your email/phone number.", "LoginIsNotAllowed": "You are not allowed to login! You need to confirm your email/phone number.",
"SelfRegistrationDisabledMessage": "Self-registration is disabled for this application. Please contact the application administrator to register a new user.", "SelfRegistrationDisabledMessage": "Self-registration is disabled for this application. Please contact the application administrator to register a new user.",
"LocalLoginDisabledMessage": "Local login is disabled for this application.",
"Login": "Login", "Login": "Login",
"Cancel": "Cancel", "Cancel": "Cancel",
"Register": "Register", "Register": "Register",

1
modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json

@ -11,6 +11,7 @@
"InvalidUserNameOrPassword": "用户名或密码错误!", "InvalidUserNameOrPassword": "用户名或密码错误!",
"LoginIsNotAllowed": "无法登录!你需要验证邮箱地址/手机号.", "LoginIsNotAllowed": "无法登录!你需要验证邮箱地址/手机号.",
"SelfRegistrationDisabledMessage": "应用程序未开放注册,请联系管理员添加新用户.", "SelfRegistrationDisabledMessage": "应用程序未开放注册,请联系管理员添加新用户.",
"LocalLoginDisabledMessage": "应用程序未开放本地账户登录.",
"Login": "登录", "Login": "登录",
"Cancel": "取消", "Cancel": "取消",
"Register": "注册", "Register": "注册",

1
modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hant.json

@ -11,6 +11,7 @@
"InvalidUserNameOrPassword": "使用者名稱或密碼錯誤!", "InvalidUserNameOrPassword": "使用者名稱或密碼錯誤!",
"LoginIsNotAllowed": "無法登入!你需要驗證電子信箱地址/手機號碼.", "LoginIsNotAllowed": "無法登入!你需要驗證電子信箱地址/手機號碼.",
"SelfRegistrationDisabledMessage": "應用程式未開放註冊,請聯絡管理員以加入新使用者.", "SelfRegistrationDisabledMessage": "應用程式未開放註冊,請聯絡管理員以加入新使用者.",
"LocalLoginDisabledMessage": "應用程序未開放本地賬戶登錄.",
"Login": "登入", "Login": "登入",
"Cancel": "取消", "Cancel": "取消",
"Register": "註冊", "Register": "註冊",

19
modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs

@ -1,4 +1,5 @@
using System.Threading.Tasks; using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Volo.Abp.Account.Settings; using Volo.Abp.Account.Settings;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
@ -9,11 +10,14 @@ namespace Volo.Abp.Account
{ {
public class AccountAppService : ApplicationService, IAccountAppService public class AccountAppService : ApplicationService, IAccountAppService
{ {
private readonly IIdentityRoleRepository _roleRepository;
protected IdentityUserManager UserManager { get; } protected IdentityUserManager UserManager { get; }
public AccountAppService( public AccountAppService(
IdentityUserManager userManager) IdentityUserManager userManager,
IIdentityRoleRepository roleRepository)
{ {
_roleRepository = roleRepository;
UserManager = userManager; UserManager = userManager;
} }
@ -25,9 +29,20 @@ namespace Volo.Abp.Account
(await UserManager.CreateAsync(user, input.Password)).CheckErrors(); (await UserManager.CreateAsync(user, input.Password)).CheckErrors();
await UserManager.SetEmailAsync(user,input.EmailAddress).ConfigureAwait(false);
await SetDefaultRolesAsync(user);
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user); return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
} }
protected virtual async Task SetDefaultRolesAsync(IdentityUser user)
{
var defaultRoles = await _roleRepository.GetDefaultOnesAsync().ConfigureAwait(false);
await UserManager.SetRolesAsync(user, defaultRoles.Select(r => r.Name)).ConfigureAwait(false);
}
protected virtual async Task CheckSelfRegistrationAsync() protected virtual async Task CheckSelfRegistrationAsync()
{ {
if (!await SettingProvider.IsTrueAsync(AccountSettingNames.IsSelfRegistrationEnabled)) if (!await SettingProvider.IsTrueAsync(AccountSettingNames.IsSelfRegistrationEnabled))

4
modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs

@ -107,8 +107,6 @@ namespace Volo.Abp.Account.Web.Pages.Account
[UnitOfWork] //TODO: Will be removed when we implement action filter [UnitOfWork] //TODO: Will be removed when we implement action filter
public override async Task<IActionResult> OnPostAsync(string action) public override async Task<IActionResult> OnPostAsync(string action)
{ {
EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin);
if (action == "Cancel") if (action == "Cancel")
{ {
var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl); var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl);
@ -122,6 +120,8 @@ namespace Volo.Abp.Account.Web.Pages.Account
return Redirect(ReturnUrl); return Redirect(ReturnUrl);
} }
await CheckLocalLoginAsync();
ValidateModel(); ValidateModel();
await ReplaceEmailToUsernameOfInputIfNeeds(); await ReplaceEmailToUsernameOfInputIfNeeds();

21
modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs

@ -1,10 +1,13 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Account.Localization;
using Volo.Abp.Account.Settings;
using Volo.Abp.Account.Web.Areas.Account.Controllers.Models; using Volo.Abp.Account.Web.Areas.Account.Controllers.Models;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.Settings;
using Volo.Abp.Validation; using Volo.Abp.Validation;
using SignInResult = Microsoft.AspNetCore.Identity.SignInResult; using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
using UserLoginInfo = Volo.Abp.Account.Web.Areas.Account.Controllers.Models.UserLoginInfo; using UserLoginInfo = Volo.Abp.Account.Web.Areas.Account.Controllers.Models.UserLoginInfo;
@ -21,17 +24,23 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
{ {
private readonly SignInManager<IdentityUser> _signInManager; private readonly SignInManager<IdentityUser> _signInManager;
private readonly IdentityUserManager _userManager; private readonly IdentityUserManager _userManager;
private readonly ISettingProvider _settingProvider;
public AccountController(SignInManager<IdentityUser> signInManager, IdentityUserManager userManager) public AccountController(SignInManager<IdentityUser> signInManager, IdentityUserManager userManager, ISettingProvider settingProvider)
{ {
LocalizationResource = typeof(AccountResource);
_signInManager = signInManager; _signInManager = signInManager;
_userManager = userManager; _userManager = userManager;
_settingProvider = settingProvider;
} }
[HttpPost] [HttpPost]
[Route("login")] [Route("login")]
public virtual async Task<AbpLoginResult> Login(UserLoginInfo login) public virtual async Task<AbpLoginResult> Login(UserLoginInfo login)
{ {
await CheckLocalLoginAsync();
ValidateLoginInfo(login); ValidateLoginInfo(login);
await ReplaceEmailToUsernameOfInputIfNeeds(login); await ReplaceEmailToUsernameOfInputIfNeeds(login);
@ -133,5 +142,13 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
throw new ArgumentNullException(nameof(login.Password)); throw new ArgumentNullException(nameof(login.Password));
} }
} }
private async Task CheckLocalLoginAsync()
{
if (!await _settingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin).ConfigureAwait(false))
{
throw new UserFriendlyException(L["LocalLoginDisabledMessage"]);
}
}
} }
} }

10
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs

@ -89,7 +89,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
[UnitOfWork] //TODO: Will be removed when we implement action filter [UnitOfWork] //TODO: Will be removed when we implement action filter
public virtual async Task<IActionResult> OnPostAsync(string action) public virtual async Task<IActionResult> OnPostAsync(string action)
{ {
EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin); await CheckLocalLoginAsync();
ValidateModel(); ValidateModel();
@ -237,6 +237,14 @@ namespace Volo.Abp.Account.Web.Pages.Account
LoginInput.UserNameOrEmailAddress = userByEmail.UserName; LoginInput.UserNameOrEmailAddress = userByEmail.UserName;
} }
protected virtual async Task CheckLocalLoginAsync()
{
if (!await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin).ConfigureAwait(false))
{
throw new UserFriendlyException(L["LocalLoginDisabledMessage"]);
}
}
public class LoginInputModel public class LoginInputModel
{ {
[Required] [Required]

22
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs

@ -1,8 +1,10 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Account.Settings; using Volo.Abp.Account.Settings;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.Settings; using Volo.Abp.Settings;
using Volo.Abp.Uow; using Volo.Abp.Uow;
@ -12,6 +14,8 @@ namespace Volo.Abp.Account.Web.Pages.Account
{ {
public class RegisterModel : AccountPageModel public class RegisterModel : AccountPageModel
{ {
private readonly IAccountAppService _accountAppService;
[BindProperty(SupportsGet = true)] [BindProperty(SupportsGet = true)]
public string ReturnUrl { get; set; } public string ReturnUrl { get; set; }
@ -21,7 +25,12 @@ namespace Volo.Abp.Account.Web.Pages.Account
[BindProperty] [BindProperty]
public PostInput Input { get; set; } public PostInput Input { get; set; }
public virtual async Task OnGet() public RegisterModel(IAccountAppService accountAppService)
{
_accountAppService = accountAppService;
}
public virtual async Task OnGetAsync()
{ {
await CheckSelfRegistrationAsync(); await CheckSelfRegistrationAsync();
} }
@ -33,9 +42,16 @@ namespace Volo.Abp.Account.Web.Pages.Account
await CheckSelfRegistrationAsync(); await CheckSelfRegistrationAsync();
var user = new IdentityUser(GuidGenerator.Create(), Input.UserName, Input.EmailAddress, CurrentTenant.Id); var registerDto = new RegisterDto
{
AppName = "MVC",
EmailAddress = Input.EmailAddress,
Password = Input.Password,
UserName = Input.UserName
};
(await UserManager.CreateAsync(user, Input.Password)).CheckErrors(); var userDto = await _accountAppService.RegisterAsync(registerDto);
var user = await UserManager.GetByIdAsync(userDto.Id);
await UserManager.SetEmailAsync(user, Input.EmailAddress); await UserManager.SetEmailAsync(user, Input.EmailAddress);

5
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs

@ -21,5 +21,10 @@ namespace Volo.Abp.Identity
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<List<IdentityRole>> GetDefaultOnesAsync(
bool includeDetails = false,
CancellationToken cancellationToken = default
);
} }
} }

6
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs

@ -42,6 +42,12 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<IdentityRole>> GetDefaultOnesAsync(
bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await DbSet.IncludeDetails(includeDetails).Where(r => r.IsDefault).ToListAsync(GetCancellationToken(cancellationToken));
}
public override IQueryable<IdentityRole> WithDetails() public override IQueryable<IdentityRole> WithDetails()
{ {
return GetQueryable().IncludeDetails(); return GetQueryable().IncludeDetails();

6
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs

@ -43,5 +43,11 @@ namespace Volo.Abp.Identity.MongoDB
.PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount) .PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<IdentityRole>> GetDefaultOnesAsync(
bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().Where(r => r.IsDefault).ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
}
} }
} }

11
modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs

@ -36,6 +36,17 @@ namespace Volo.Abp.Identity
roles.ShouldContain(r => r.Name == "supporter"); roles.ShouldContain(r => r.Name == "supporter");
} }
[Fact]
public async Task GetDefaultOnesAsync()
{
var roles = await RoleRepository.GetDefaultOnesAsync().ConfigureAwait(false);
foreach (var role in roles)
{
role.IsDefault.ShouldBe(true);
}
}
[Fact] [Fact]
public async Task GetCountAsync() public async Task GetCountAsync()
{ {

1
samples/BasicConsoleApplication/AbpConsoleDemo/AbpConsoleDemo.csproj

@ -7,6 +7,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> <ProjectReference Include="..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>

32
samples/BasicConsoleApplication/AbpConsoleDemo/AppHostedService.cs

@ -0,0 +1,32 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Volo.Abp;
namespace AbpConsoleDemo
{
public class AppHostedService : IHostedService
{
public Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<AppModule>(options =>
{
options.UseAutofac(); //Autofac integration
}))
{
application.Initialize();
//Resolve a service and use it
var helloWorldService = application.ServiceProvider.GetService<HelloWorldService>();
helloWorldService.SayHello();
application.Shutdown();
}
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

29
samples/BasicConsoleApplication/AbpConsoleDemo/Program.cs

@ -1,28 +1,21 @@
using System; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Microsoft.Extensions.Hosting;
namespace AbpConsoleDemo namespace AbpConsoleDemo
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{ {
using (var application = AbpApplicationFactory.Create<AppModule>(options => await CreateHostBuilder(args).RunConsoleAsync();
{
options.UseAutofac(); //Autofac integration
}))
{
application.Initialize();
//Resolve a service and use it
var helloWorldService =
application.ServiceProvider.GetService<HelloWorldService>();
helloWorldService.SayHello();
Console.WriteLine("Press ENTER to stop application...");
Console.ReadLine();
}
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<AppHostedService>();
});
} }
} }

34
samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs

@ -0,0 +1,34 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Acme.BookStore.Data;
using Serilog;
using Volo.Abp;
namespace Acme.BookStore.DbMigrator
{
public class DbMigratorHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<BookStoreDbMigratorModule>(options =>
{
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
application.Initialize();
await application
.ServiceProvider
.GetRequiredService<BookStoreDbMigrationService>()
.MigrateAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

41
samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.DbMigrator/Program.cs

@ -1,39 +1,15 @@
using System.IO; using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Acme.BookStore.Data; using Microsoft.Extensions.Hosting;
using Serilog; using Serilog;
using Serilog.Events; using Serilog.Events;
using Volo.Abp;
using Volo.Abp.Threading;
namespace Acme.BookStore.DbMigrator namespace Acme.BookStore.DbMigrator
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{
ConfigureLogging();
using (var application = AbpApplicationFactory.Create<BookStoreDbMigratorModule>(options =>
{
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
application.Initialize();
AsyncHelper.RunSync(
() => application
.ServiceProvider
.GetRequiredService<BookStoreDbMigrationService>()
.MigrateAsync()
);
application.Shutdown();
}
}
private static void ConfigureLogging()
{ {
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information() .MinimumLevel.Information()
@ -48,6 +24,15 @@ namespace Acme.BookStore.DbMigrator
.WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt")) .WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt"))
.WriteTo.Console() .WriteTo.Console()
.CreateLogger(); .CreateLogger();
await CreateHostBuilder(args).RunConsoleAsync();
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<DbMigratorHostedService>();
});
} }
} }

26
samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs

@ -0,0 +1,26 @@
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp
{
public class ConsoleTestAppHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>())
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
await demo.RunAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

25
samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs

@ -1,24 +1,21 @@
using System; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Microsoft.Extensions.Hosting;
using Volo.Abp.Threading;
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{ {
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>()) await CreateHostBuilder(args).RunConsoleAsync();
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
AsyncHelper.RunSync(() => demo.RunAsync());
Console.WriteLine("Press ENTER to stop application...");
Console.ReadLine();
}
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ConsoleTestAppHostedService>();
});
} }
} }

34
samples/BookStore-Modular/application/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs

@ -0,0 +1,34 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Acme.BookStore.Data;
using Serilog;
using Volo.Abp;
namespace Acme.BookStore.DbMigrator
{
public class DbMigratorHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<BookStoreDbMigratorModule>(options =>
{
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
application.Initialize();
await application
.ServiceProvider
.GetRequiredService<BookStoreDbMigrationService>()
.MigrateAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

41
samples/BookStore-Modular/application/src/Acme.BookStore.DbMigrator/Program.cs

@ -1,39 +1,15 @@
using System.IO; using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Acme.BookStore.Data; using Microsoft.Extensions.Hosting;
using Serilog; using Serilog;
using Serilog.Events; using Serilog.Events;
using Volo.Abp;
using Volo.Abp.Threading;
namespace Acme.BookStore.DbMigrator namespace Acme.BookStore.DbMigrator
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{
ConfigureLogging();
using (var application = AbpApplicationFactory.Create<BookStoreDbMigratorModule>(options =>
{
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
application.Initialize();
AsyncHelper.RunSync(
() => application
.ServiceProvider
.GetRequiredService<BookStoreDbMigrationService>()
.MigrateAsync()
);
application.Shutdown();
}
}
private static void ConfigureLogging()
{ {
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information() .MinimumLevel.Information()
@ -48,6 +24,15 @@ namespace Acme.BookStore.DbMigrator
.WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt")) .WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt"))
.WriteTo.Console() .WriteTo.Console()
.CreateLogger(); .CreateLogger();
await CreateHostBuilder(args).RunConsoleAsync();
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<DbMigratorHostedService>();
});
} }
} }

26
samples/BookStore-Modular/application/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs

@ -0,0 +1,26 @@
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp
{
public class ConsoleTestAppHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>())
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
await demo.RunAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

25
samples/BookStore-Modular/application/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs

@ -1,24 +1,21 @@
using System; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Microsoft.Extensions.Hosting;
using Volo.Abp.Threading;
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{ {
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>()) await CreateHostBuilder(args).RunConsoleAsync();
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
AsyncHelper.RunSync(() => demo.RunAsync());
Console.WriteLine("Press ENTER to stop application...");
Console.ReadLine();
}
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ConsoleTestAppHostedService>();
});
} }
} }

26
samples/BookStore-Modular/modules/book-management/test/Acme.BookStore.BookManagement.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs

@ -0,0 +1,26 @@
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace Acme.BookStore.BookManagement
{
public class ConsoleTestAppHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<BookManagementConsoleApiClientModule>())
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
await demo.RunAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

25
samples/BookStore-Modular/modules/book-management/test/Acme.BookStore.BookManagement.HttpApi.Client.ConsoleTestApp/Program.cs

@ -1,24 +1,21 @@
using System; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Microsoft.Extensions.Hosting;
using Volo.Abp.Threading;
namespace Acme.BookStore.BookManagement namespace Acme.BookStore.BookManagement
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{ {
using (var application = AbpApplicationFactory.Create<BookManagementConsoleApiClientModule>()) await CreateHostBuilder(args).RunConsoleAsync();
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
AsyncHelper.RunSync(() => demo.RunAsync());
Console.WriteLine("Press ENTER to stop application...");
Console.ReadLine();
}
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ConsoleTestAppHostedService>();
});
} }
} }

34
samples/BookStore/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs

@ -0,0 +1,34 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Acme.BookStore.Data;
using Serilog;
using Volo.Abp;
namespace Acme.BookStore.DbMigrator
{
public class DbMigratorHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<BookStoreDbMigratorModule>(options =>
{
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
application.Initialize();
await application
.ServiceProvider
.GetRequiredService<BookStoreDbMigrationService>()
.MigrateAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

41
samples/BookStore/src/Acme.BookStore.DbMigrator/Program.cs

@ -1,39 +1,15 @@
using System.IO; using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Acme.BookStore.Data; using Microsoft.Extensions.Hosting;
using Serilog; using Serilog;
using Serilog.Events; using Serilog.Events;
using Volo.Abp;
using Volo.Abp.Threading;
namespace Acme.BookStore.DbMigrator namespace Acme.BookStore.DbMigrator
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{
ConfigureLogging();
using (var application = AbpApplicationFactory.Create<BookStoreDbMigratorModule>(options =>
{
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
application.Initialize();
AsyncHelper.RunSync(
() => application
.ServiceProvider
.GetRequiredService<BookStoreDbMigrationService>()
.MigrateAsync()
);
application.Shutdown();
}
}
private static void ConfigureLogging()
{ {
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information() .MinimumLevel.Information()
@ -48,6 +24,15 @@ namespace Acme.BookStore.DbMigrator
.WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt")) .WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt"))
.WriteTo.Console() .WriteTo.Console()
.CreateLogger(); .CreateLogger();
await CreateHostBuilder(args).RunConsoleAsync();
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<DbMigratorHostedService>();
});
} }
} }

26
samples/BookStore/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs

@ -0,0 +1,26 @@
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp
{
public class ConsoleTestAppHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>())
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
await demo.RunAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

25
samples/BookStore/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs

@ -1,24 +1,21 @@
using System; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Microsoft.Extensions.Hosting;
using Volo.Abp.Threading;
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{ {
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>()) await CreateHostBuilder(args).RunConsoleAsync();
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
AsyncHelper.RunSync(() => demo.RunAsync());
Console.WriteLine("Press ENTER to stop application...");
Console.ReadLine();
}
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ConsoleTestAppHostedService>();
});
} }
} }

34
samples/DashboardDemo/src/DashboardDemo.DbMigrator/DbMigratorHostedService.cs

@ -0,0 +1,34 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using DashboardDemo.Data;
using Serilog;
using Volo.Abp;
namespace DashboardDemo.DbMigrator
{
public class DbMigratorHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<DashboardDemoDbMigratorModule>(options =>
{
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
application.Initialize();
await application
.ServiceProvider
.GetRequiredService<DashboardDemoDbMigrationService>()
.MigrateAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

41
samples/DashboardDemo/src/DashboardDemo.DbMigrator/Program.cs

@ -1,39 +1,15 @@
using System.IO; using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using DashboardDemo.Data; using Microsoft.Extensions.Hosting;
using Serilog; using Serilog;
using Serilog.Events; using Serilog.Events;
using Volo.Abp;
using Volo.Abp.Threading;
namespace DashboardDemo.DbMigrator namespace DashboardDemo.DbMigrator
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{
ConfigureLogging();
using (var application = AbpApplicationFactory.Create<DashboardDemoDbMigratorModule>(options =>
{
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
application.Initialize();
AsyncHelper.RunSync(
() => application
.ServiceProvider
.GetRequiredService<DashboardDemoDbMigrationService>()
.MigrateAsync()
);
application.Shutdown();
}
}
private static void ConfigureLogging()
{ {
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information() .MinimumLevel.Information()
@ -48,6 +24,15 @@ namespace DashboardDemo.DbMigrator
.WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt")) .WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt"))
.WriteTo.Console() .WriteTo.Console()
.CreateLogger(); .CreateLogger();
await CreateHostBuilder(args).RunConsoleAsync();
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<DbMigratorHostedService>();
});
} }
} }

26
samples/DashboardDemo/test/DashboardDemo.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs

@ -0,0 +1,26 @@
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace DashboardDemo.HttpApi.Client.ConsoleTestApp
{
public class ConsoleTestAppHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<DashboardDemoConsoleApiClientModule>())
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
await demo.RunAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

25
samples/DashboardDemo/test/DashboardDemo.HttpApi.Client.ConsoleTestApp/Program.cs

@ -1,24 +1,21 @@
using System; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Microsoft.Extensions.Hosting;
using Volo.Abp.Threading;
namespace DashboardDemo.HttpApi.Client.ConsoleTestApp namespace DashboardDemo.HttpApi.Client.ConsoleTestApp
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{ {
using (var application = AbpApplicationFactory.Create<DashboardDemoConsoleApiClientModule>()) await CreateHostBuilder(args).RunConsoleAsync();
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
AsyncHelper.RunSync(() => demo.RunAsync());
Console.WriteLine("Press ENTER to stop application...");
Console.ReadLine();
}
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ConsoleTestAppHostedService>();
});
} }
} }

33
samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemoHostedService.cs

@ -0,0 +1,33 @@
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Serilog;
namespace ConsoleClientDemo
{
public class ConsoleClientDemoHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<ConsoleClientDemoModule>(options =>
{
options.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSerilog(dispose: true);
});
}))
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
await demo.RunAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

55
samples/MicroserviceDemo/applications/ConsoleClientDemo/Program.cs

@ -1,48 +1,14 @@
using Serilog; using System.Threading.Tasks;
using Serilog.Events;
using System;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Microsoft.Extensions.Hosting;
using Volo.Abp.Threading; using Serilog;
using Serilog.Events;
namespace ConsoleClientDemo namespace ConsoleClientDemo
{ {
internal class Program internal class Program
{ {
private static void Main(string[] args) static async Task Main(string[] args)
{
InitializeSerilog();
Log.Information("Starting ConsoleClientDemo...");
try
{
using (var application = AbpApplicationFactory.Create<ConsoleClientDemoModule>(options =>
{
options.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddSerilog(dispose: true);
});
}))
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
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() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug() .MinimumLevel.Debug()
@ -50,6 +16,17 @@ namespace ConsoleClientDemo
.Enrich.FromLogContext() .Enrich.FromLogContext()
.WriteTo.File("Logs/logs.txt") .WriteTo.File("Logs/logs.txt")
.CreateLogger(); .CreateLogger();
Log.Information("Starting ConsoleClientDemo...");
await CreateHostBuilder(args).RunConsoleAsync();
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ConsoleClientDemoHostedService>();
});
} }
} }

34
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/DbMigratorHostedService.cs

@ -0,0 +1,34 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using MyCompanyName.MyProjectName.Data;
using Serilog;
using Volo.Abp;
namespace MyCompanyName.MyProjectName.DbMigrator
{
public class DbMigratorHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<MyProjectNameDbMigratorModule>(options =>
{
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
application.Initialize();
await application
.ServiceProvider
.GetRequiredService<MyProjectNameDbMigrationService>()
.MigrateAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

41
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/Program.cs

@ -1,39 +1,15 @@
using System.IO; using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using MyCompanyName.MyProjectName.Data; using Microsoft.Extensions.Hosting;
using Serilog; using Serilog;
using Serilog.Events; using Serilog.Events;
using Volo.Abp;
using Volo.Abp.Threading;
namespace MyCompanyName.MyProjectName.DbMigrator namespace MyCompanyName.MyProjectName.DbMigrator
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{
ConfigureLogging();
using (var application = AbpApplicationFactory.Create<MyProjectNameDbMigratorModule>(options =>
{
options.UseAutofac();
options.Services.AddLogging(c => c.AddSerilog());
}))
{
application.Initialize();
AsyncHelper.RunSync(
() => application
.ServiceProvider
.GetRequiredService<MyProjectNameDbMigrationService>()
.MigrateAsync()
);
application.Shutdown();
}
}
private static void ConfigureLogging()
{ {
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information() .MinimumLevel.Information()
@ -48,6 +24,15 @@ namespace MyCompanyName.MyProjectName.DbMigrator
.WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt")) .WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt"))
.WriteTo.Console() .WriteTo.Console()
.CreateLogger(); .CreateLogger();
await CreateHostBuilder(args).RunConsoleAsync();
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<DbMigratorHostedService>();
});
} }
} }

26
templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs

@ -0,0 +1,26 @@
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp
{
public class ConsoleTestAppHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<MyProjectNameConsoleApiClientModule>())
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
await demo.RunAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

25
templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs

@ -1,24 +1,21 @@
using System; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Microsoft.Extensions.Hosting;
using Volo.Abp.Threading;
namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{ {
using (var application = AbpApplicationFactory.Create<MyProjectNameConsoleApiClientModule>()) await CreateHostBuilder(args).RunConsoleAsync();
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
AsyncHelper.RunSync(() => demo.RunAsync());
Console.WriteLine("Press ENTER to stop application...");
Console.ReadLine();
}
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ConsoleTestAppHostedService>();
});
} }
} }

26
templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs

@ -0,0 +1,26 @@
using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp
{
public class ConsoleTestAppHostedService : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using (var application = AbpApplicationFactory.Create<MyProjectNameConsoleApiClientModule>())
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
await demo.RunAsync();
application.Shutdown();
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

27
templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs

@ -1,24 +1,21 @@
using System; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Microsoft.Extensions.Hosting;
using Volo.Abp.Threading;
namespace MyCompanyName.MyProjectName namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp
{ {
class Program class Program
{ {
static void Main(string[] args) static async Task Main(string[] args)
{ {
using (var application = AbpApplicationFactory.Create<MyProjectNameConsoleApiClientModule>()) await CreateHostBuilder(args).RunConsoleAsync();
{
application.Initialize();
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>();
AsyncHelper.RunSync(() => demo.RunAsync());
Console.WriteLine("Press ENTER to stop application...");
Console.ReadLine();
}
} }
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<ConsoleTestAppHostedService>();
});
} }
} }

Loading…
Cancel
Save