protected internal override async Task PopulateResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var deletedUserLoginIds = new HashSet <string>(StringComparer.OrdinalIgnoreCase); await this.PopulateResultAsync( this.DatabaseContext.ChangeTracker, result.Items, new[] { typeof(UserLoginEntity) }.ToHashSet(), entry => { if (entry.State == EntityState.Deleted && entry.Entity is UserLoginEntity userLogin) { deletedUserLoginIds.Add(userLogin.UserId); } return(false); } ); var parent = result.Items[typeof(UserLoginEntity)]; await this.PopulateResultAsync( this.DatabaseContext.ChangeTracker, parent.Relations, new[] { typeof(UserEntity) }.ToHashSet() ); await this.PopulateRelationDeletesAsync <UserEntity>(await this.DatabaseContext.Users.Where(user => deletedUserLoginIds.Contains(user.Id)).CountAsync(), parent.Relations); }
protected internal override async Task InitializeResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var item = await this.CreateResultItemAsync(await this.DatabaseContext.IdentityProviders.CountAsync()); result.Items.Add(typeof(IdentityProviderEntity), item); }
protected internal virtual async Task AddErrorAsync(string message, IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } await Task.CompletedTask; result.Errors.Add(message); this.Logger.LogErrorIfEnabled(message); }
protected internal override async Task InitializeResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var item = await this.CreateResultItemAsync(await this.DatabaseContext.RelyingParties.CountAsync()); item.Relations.Add(typeof(WsFederationClaimMap), await this.CreateResultItemAsync(await this.DatabaseContext.ClaimMapping().CountAsync())); result.Items.Add(typeof(RelyingPartyEntity), item); }
protected internal override async Task InitializeResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var item = await this.CreateResultItemAsync(await this.DatabaseContext.ApiScopes.CountAsync()); item.Relations.Add(typeof(ApiScopeClaim), await this.CreateResultItemAsync(await this.DatabaseContext.ApiScopeClaims().CountAsync())); item.Relations.Add(typeof(ApiScopeProperty), await this.CreateResultItemAsync(await this.DatabaseContext.ApiScopeProperties().CountAsync())); result.Items.Add(typeof(ApiScopeEntity), item); }
protected internal override async Task InitializeResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var item = await this.CreateResultItemAsync(await this.DatabaseContext.Users.CountAsync()); item.Relations.Add(typeof(IdentityUserClaim <string>), await this.CreateResultItemAsync(await this.DatabaseContext.UserClaims.CountAsync())); item.Relations.Add(typeof(IdentityUserLogin <string>), await this.CreateResultItemAsync(await this.DatabaseContext.UserLogins.CountAsync())); item.Relations.Add(typeof(IdentityUserRole <string>), await this.CreateResultItemAsync(await this.DatabaseContext.UserRoles.CountAsync())); item.Relations.Add(typeof(IdentityUserToken <string>), await this.CreateResultItemAsync(await this.DatabaseContext.UserTokens.CountAsync())); result.Items.Add(typeof(UserEntity), item); }
protected internal override async Task InitializeResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var item = await this.CreateResultItemAsync(await this.DatabaseContext.ServiceProviders.CountAsync()); item.Relations.Add(typeof(AssertionConsumerService), await this.CreateResultItemAsync(await this.DatabaseContext.AssertionConsumerServices().CountAsync())); item.Relations.Add(typeof(SamlClaimMap), await this.CreateResultItemAsync(await this.DatabaseContext.ClaimsMapping().CountAsync())); item.Relations.Add(typeof(SigningCertificate), await this.CreateResultItemAsync(await this.DatabaseContext.SigningCertificates().CountAsync())); item.Relations.Add(typeof(SingleLogoutService), await this.CreateResultItemAsync(await this.DatabaseContext.SingleLogoutServices().CountAsync())); result.Items.Add(typeof(ServiceProviderEntity), item); }
protected internal override async Task PopulateResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var deletedServiceProviderIds = new HashSet <int>(); await this.PopulateResultAsync( this.DatabaseContext.ChangeTracker(), result.Items, new[] { typeof(ServiceProviderEntity) }.ToHashSet(), entry => { if (entry.State == EntityState.Deleted && entry.Entity is ServiceProviderEntity serviceProvider) { deletedServiceProviderIds.Add(serviceProvider.Id); } return(false); } ); var parent = result.Items[typeof(ServiceProviderEntity)]; await this.PopulateResultAsync( this.DatabaseContext.ChangeTracker(), parent.Relations, new[] { typeof(AssertionConsumerService), typeof(SamlClaimMap), typeof(SigningCertificate), typeof(SingleLogoutService) }.ToHashSet() ); await this.PopulateRelationDeletesAsync <AssertionConsumerService>(await this.DatabaseContext.AssertionConsumerServices().Where(assertionConsumerService => deletedServiceProviderIds.Contains(assertionConsumerService.ServiceProvider.Id)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <SamlClaimMap>(await this.DatabaseContext.ClaimsMapping().Where(samlClaimMap => deletedServiceProviderIds.Contains(samlClaimMap.ServiceProvider.Id)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <SigningCertificate>(await this.DatabaseContext.SigningCertificates().Where(signingCertificate => deletedServiceProviderIds.Contains(signingCertificate.ServiceProvider.Id)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <SingleLogoutService>(await this.DatabaseContext.SingleLogoutServices().Where(singleLogoutService => deletedServiceProviderIds.Contains(singleLogoutService.ServiceProvider.Id)).CountAsync(), parent.Relations); }
protected internal override async Task InitializeResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var item = await this.CreateResultItemAsync(await this.DatabaseContext.Clients.CountAsync()); item.Relations.Add(typeof(ClientCorsOrigin), await this.CreateResultItemAsync(await this.DatabaseContext.ClientCorsOrigins.CountAsync())); item.Relations.Add(typeof(ClientClaim), await this.CreateResultItemAsync(await this.DatabaseContext.ClientClaims().CountAsync())); item.Relations.Add(typeof(ClientGrantType), await this.CreateResultItemAsync(await this.DatabaseContext.ClientGrantTypes().CountAsync())); item.Relations.Add(typeof(ClientIdPRestriction), await this.CreateResultItemAsync(await this.DatabaseContext.ClientIdentityProviderRestrictions().CountAsync())); item.Relations.Add(typeof(ClientPostLogoutRedirectUri), await this.CreateResultItemAsync(await this.DatabaseContext.ClientPostLogoutRedirectUris().CountAsync())); item.Relations.Add(typeof(ClientProperty), await this.CreateResultItemAsync(await this.DatabaseContext.ClientProperties().CountAsync())); item.Relations.Add(typeof(ClientRedirectUri), await this.CreateResultItemAsync(await this.DatabaseContext.ClientRedirectUris().CountAsync())); item.Relations.Add(typeof(ClientScope), await this.CreateResultItemAsync(await this.DatabaseContext.ClientScopes().CountAsync())); item.Relations.Add(typeof(ClientSecret), await this.CreateResultItemAsync(await this.DatabaseContext.ClientSecrets().CountAsync())); result.Items.Add(typeof(ClientEntity), item); }
protected internal override async Task PopulateResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var deletedApiResourceIds = new HashSet <int>(); await this.PopulateResultAsync( this.DatabaseContext.ChangeTracker(), result.Items, new[] { typeof(ApiResourceEntity) }.ToHashSet(), entry => { if (entry.State == EntityState.Deleted && entry.Entity is ApiResourceEntity apiResource) { deletedApiResourceIds.Add(apiResource.Id); } return(false); } ); var parent = result.Items[typeof(ApiResourceEntity)]; await this.PopulateResultAsync( this.DatabaseContext.ChangeTracker(), parent.Relations, new[] { typeof(ApiResourceClaim), typeof(ApiResourceProperty), typeof(ApiResourceScope), typeof(ApiResourceSecret) }.ToHashSet() ); await this.PopulateRelationDeletesAsync <ApiResourceClaim>(await this.DatabaseContext.ApiResourceClaims().Where(apiResourceClaim => deletedApiResourceIds.Contains(apiResourceClaim.ApiResourceId)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <ApiResourceProperty>(await this.DatabaseContext.ApiResourceProperties().Where(apiResourceProperty => deletedApiResourceIds.Contains(apiResourceProperty.ApiResourceId)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <ApiResourceScope>(await this.DatabaseContext.ApiResourceScopes().Where(apiResourceScope => deletedApiResourceIds.Contains(apiResourceScope.ApiResourceId)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <ApiResourceSecret>(await this.DatabaseContext.ApiResourceSecrets().Where(apiResourceSecret => deletedApiResourceIds.Contains(apiResourceSecret.ApiResourceId)).CountAsync(), parent.Relations); }
protected internal override async Task PopulateResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var deletedRelyingPartiesIds = new HashSet <int>(); await this.PopulateResultAsync( this.DatabaseContext.ChangeTracker(), result.Items, new[] { typeof(RelyingPartyEntity) }.ToHashSet(), entry => { if (entry.State == EntityState.Deleted && entry.Entity is RelyingPartyEntity relyingParty) { deletedRelyingPartiesIds.Add(relyingParty.Id); } return(false); } ); var parent = result.Items[typeof(RelyingPartyEntity)]; await this.PopulateResultAsync( this.DatabaseContext.ChangeTracker(), parent.Relations, new[] { typeof(WsFederationClaimMap) }.ToHashSet() ); await this.PopulateRelationDeletesAsync <WsFederationClaimMap>(await this.DatabaseContext.ClaimMapping().Where(wsFederationClaimMap => deletedRelyingPartiesIds.Contains(wsFederationClaimMap.RelyingParty.Id)).CountAsync(), parent.Relations); }
protected internal override async Task PopulateResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var deletedIdentityProviderIds = new HashSet <int>(); await this.PopulateResultAsync( this.DatabaseContext.ChangeTracker(), result.Items, new[] { typeof(IdentityProviderEntity) }.ToHashSet(), entry => { if (entry.State == EntityState.Deleted && entry.Entity is IdentityProviderEntity identityProvider) { deletedIdentityProviderIds.Add(identityProvider.Id); } return(false); } ); }
protected internal virtual async Task FilterOutDuplicateModelsAsync(IList <TModel> models, string propertyName, Func <TModel, string> propertySelector, IDataImportResult result) { if (models == null) { throw new ArgumentNullException(nameof(models)); } if (propertyName == null) { throw new ArgumentNullException(nameof(propertyName)); } if (propertySelector == null) { throw new ArgumentNullException(nameof(propertySelector)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } var errorFormat = $"{propertyName} {{0}} has {{1}} duplicate{{2}}."; var copies = models.ToArray(); models.Clear(); foreach (var group in copies.GroupBy(propertySelector, StringComparer.OrdinalIgnoreCase)) { if (group.Count() > 1) { await this.AddErrorAsync(string.Format(null, errorFormat, group.Key.ToStringRepresentation(), group.Count() - 1, group.Count() > 2 ? "s" : null), result); } else { models.Add(group.First()); } } }
protected internal virtual async Task FilterOutDuplicateModelsAsync(IList <TModel> models, IDataImportResult result) { await this.FilterOutDuplicateModelsAsync(models, this.ModelIdentifierFullName, this.ModelIdentifierSelector, result); }
protected internal virtual async Task ValidateModelsAsync(IConfiguration configuration, IDataImportResult result) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } var userLoginImporter = this.Importers.OfType <UserLoginImporter>().FirstOrDefault(); var userImporter = this.Importers.OfType <UserImporter>().FirstOrDefault(); if (userLoginImporter == null) { return; } if (userImporter == null) { return; } var userLoginModels = await userLoginImporter.GetModelsAsync(configuration); if (!userLoginModels.Any()) { return; } var userModels = await userImporter.GetModelsAsync(configuration); if (!userModels.Any()) { return; } var conflictingIdentifiers = userLoginModels.Select(userLogin => userLogin.Id).Intersect(userModels.Select(userModel => userModel.Id), StringComparer.OrdinalIgnoreCase).Where(item => item != null).Distinct(StringComparer.OrdinalIgnoreCase).ToArray(); if (!conflictingIdentifiers.Any()) { return; } result.Errors.Add($"The {userLoginImporter.ConfigurationKey}-section and the {userImporter.ConfigurationKey}-section have conflicting user-ids: {string.Join(", ", conflictingIdentifiers.Select(item => item.ToStringRepresentation()))}"); }
protected internal abstract Task PopulateResultAsync(IDataImportResult result);
protected internal abstract Task InitializeResultAsync(IDataImportResult result);
protected internal virtual async Task FilterOutInvalidModelsAsync(IList <TModel> models, string propertyName, Func <TModel, string> propertySelector, IDataImportResult result, bool allowNull = false, bool allowEmpty = false, bool allowWhitespacesOnly = false) { if (models == null) { throw new ArgumentNullException(nameof(models)); } if (propertyName == null) { throw new ArgumentNullException(nameof(propertyName)); } if (propertySelector == null) { throw new ArgumentNullException(nameof(propertySelector)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } var errorFormat = $"{propertyName} {{0}} can not be {{1}}."; var copies = models.ToArray(); models.Clear(); foreach (var model in copies) { var propertyValue = propertySelector(model); if (propertyValue == null) { if (!allowNull) { await this.AddErrorAsync($"{this.ModelIdentifierFullName} can not be null.", result); continue; } } else if (propertyValue.Length == 0) { if (!allowEmpty) { await this.AddErrorAsync(string.Format(null, errorFormat, propertyValue.ToStringRepresentation(), "empty"), result); continue; } } else if (propertyValue.Trim().Length == 0) { if (!allowWhitespacesOnly) { await this.AddErrorAsync(string.Format(null, errorFormat, propertyValue.ToStringRepresentation(), "whitespaces only"), result); continue; } } models.Add(model); } }
protected internal override async Task FilterOutInvalidModelsAsync(IList <UserModel> models, IDataImportResult result) { if (models == null) { throw new ArgumentNullException(nameof(models)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } await base.FilterOutInvalidModelsAsync(models, result); var copies = models.ToArray(); models.Clear(); foreach (var user in copies) { var userLogins = await this.Facade.GetUserLoginsAsync(user.Id); if (userLogins.Any()) { await this.AddErrorAsync($"{typeof(UserModel).Name}.{nameof(UserModel.Id)} \"{user.Id}\" has external logins.", result); continue; } var validationResult = await this.Facade.ValidateUserAsync(user); if (validationResult.Succeeded) { models.Add(user); } else { await this.AddErrorAsync(validationResult, result); } } }
protected internal override async Task FilterOutInvalidModelsAsync(IList <UserLoginModel> models, IDataImportResult result) { if (models == null) { throw new ArgumentNullException(nameof(models)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } await base.FilterOutInvalidModelsAsync(models, result); await base.FilterOutInvalidModelsAsync(models, $"{typeof(UserLoginModel).Name}.{nameof(UserLoginModel.Provider)}", model => model.Provider, result); await base.FilterOutInvalidModelsAsync(models, $"{typeof(UserLoginModel).Name}.{nameof(UserLoginModel.UserIdentifier)}", model => model.UserIdentifier, result); var copies = models.ToArray(); models.Clear(); foreach (var userLogin in copies) { var user = await this.Facade.Users.FirstOrDefaultAsync(item => item.Id == userLogin.Id); if (user?.PasswordHash != null) { await this.AddErrorAsync($"{typeof(UserLoginModel).Name}.{nameof(UserLoginModel.Id)} \"{userLogin.Id}\" exists as a user with a password.", result); } else { models.Add(userLogin); } } }
protected internal virtual async Task FilterOutInvalidModelsAsync(IList <TModel> models, IDataImportResult result) { await this.FilterOutInvalidModelsAsync(models, this.ModelIdentifierFullName, this.ModelIdentifierSelector, result, this.AllowNullModelIdentifier, this.AllowEmptyModelIdentifier, this.AllowWhitespacesOnlyModelIdentifier); }
protected internal override async Task PopulateResultAsync(IDataImportResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var deletedClientIds = new HashSet <int>(); await this.PopulateResultAsync( this.DatabaseContext.ChangeTracker(), result.Items, new[] { typeof(ClientEntity) }.ToHashSet(), entry => { if (entry.State == EntityState.Deleted && entry.Entity is ClientEntity client) { deletedClientIds.Add(client.Id); } return(false); } ); var parent = result.Items[typeof(ClientEntity)]; await this.PopulateResultAsync( this.DatabaseContext.ChangeTracker(), parent.Relations, new[] { typeof(ClientCorsOrigin), typeof(ClientClaim), typeof(ClientGrantType), typeof(ClientIdPRestriction), typeof(ClientPostLogoutRedirectUri), typeof(ClientProperty), typeof(ClientRedirectUri), typeof(ClientScope), typeof(ClientSecret) }.ToHashSet() ); await this.PopulateRelationDeletesAsync <ClientCorsOrigin>(await this.DatabaseContext.ClientCorsOrigins.Where(clientCorsOrigin => deletedClientIds.Contains(clientCorsOrigin.ClientId)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <ClientClaim>(await this.DatabaseContext.ClientClaims().Where(clientClaim => deletedClientIds.Contains(clientClaim.ClientId)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <ClientGrantType>(await this.DatabaseContext.ClientGrantTypes().Where(clientGrantType => deletedClientIds.Contains(clientGrantType.ClientId)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <ClientIdPRestriction>(await this.DatabaseContext.ClientIdentityProviderRestrictions().Where(clientIdentityProviderRestriction => deletedClientIds.Contains(clientIdentityProviderRestriction.ClientId)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <ClientPostLogoutRedirectUri>(await this.DatabaseContext.ClientPostLogoutRedirectUris().Where(clientPostLogoutRedirectUri => deletedClientIds.Contains(clientPostLogoutRedirectUri.ClientId)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <ClientProperty>(await this.DatabaseContext.ClientProperties().Where(clientProperty => deletedClientIds.Contains(clientProperty.ClientId)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <ClientRedirectUri>(await this.DatabaseContext.ClientRedirectUris().Where(clientRedirectUri => deletedClientIds.Contains(clientRedirectUri.ClientId)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <ClientScope>(await this.DatabaseContext.ClientScopes().Where(clientScope => deletedClientIds.Contains(clientScope.ClientId)).CountAsync(), parent.Relations); await this.PopulateRelationDeletesAsync <ClientSecret>(await this.DatabaseContext.ClientSecrets().Where(clientSecret => deletedClientIds.Contains(clientSecret.ClientId)).CountAsync(), parent.Relations); }
protected internal override async Task FilterOutInvalidModelsAsync(IList <ClientModel> models, IDataImportResult result) { if (models == null) { throw new ArgumentNullException(nameof(models)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } await base.FilterOutInvalidModelsAsync(models, result); var copies = models.ToArray(); models.Clear(); foreach (var client in copies) { var context = new ClientConfigurationValidationContext(client); await this.ClientValidator.ValidateAsync(context); if (!context.IsValid) { await this.AddErrorAsync($"Client \"{client.ClientId}\": {context.ErrorMessage}", result); continue; } models.Add(client); } }
protected internal override async Task ImportAsync(IList <UserLoginModel> models, ImportOptions options, IDataImportResult result) { if (models == null) { throw new ArgumentNullException(nameof(models)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } await this.InitializeResultAsync(result); await this.FilterOutInvalidModelsAsync(models, result); await this.FilterOutDuplicateModelsAsync(models, result); foreach (var import in models) { var saveResult = await this.Facade.SaveUserLoginAsync(import); if (!saveResult.Succeeded) { await this.AddErrorAsync(saveResult, result); } } if (options.DeleteAllOthers) { var userLoginsToDelete = new List <UserLoginEntity>(); foreach (var userLogin in this.DatabaseContext.UserLogins) { var keep = models.Any(import => import.Id.Equals(userLogin.UserId, StringComparison.OrdinalIgnoreCase) && import.Provider.Equals(userLogin.LoginProvider, StringComparison.OrdinalIgnoreCase) && import.UserIdentifier.Equals(userLogin.ProviderKey, StringComparison.OrdinalIgnoreCase)); if (!keep) { userLoginsToDelete.Add(userLogin); } } var involvedUserIds = userLoginsToDelete.Select(userLogin => userLogin.UserId).ToHashSet(StringComparer.OrdinalIgnoreCase); this.DatabaseContext.UserLogins.RemoveRange(userLoginsToDelete); var userLoginUserIds = this.DatabaseContext.UserLogins.Select(userLogin => userLogin.UserId).ToHashSet(StringComparer.OrdinalIgnoreCase); var userToDeleteIds = involvedUserIds.Where(userId => !userLoginUserIds.Contains(userId)).ToHashSet(StringComparer.OrdinalIgnoreCase); var userToKeepIds = involvedUserIds.Where(userId => userLoginUserIds.Contains(userId)).ToHashSet(StringComparer.OrdinalIgnoreCase); this.DatabaseContext.UserClaims.RemoveRange(this.DatabaseContext.UserClaims.Where(userClaim => userToKeepIds.Contains(userClaim.UserId))); this.DatabaseContext.Users.RemoveRange(this.DatabaseContext.Users.Where(user => userToDeleteIds.Contains(user.Id))); foreach (var user in this.DatabaseContext.Users.Where(user => userToKeepIds.Contains(user.Id))) { user.SecurityStamp = Guid.NewGuid().ToString(); } } await this.PopulateResultAsync(result); }
public override async Task ImportAsync(IConfiguration configuration, ImportOptions options, IDataImportResult result) { await this.ValidateModelsAsync(configuration, result); await base.ImportAsync(configuration, options, result); }
protected internal abstract Task ImportAsync(IList <TModel> models, ImportOptions options, IDataImportResult result);
protected internal override async Task ImportAsync(IList <UserModel> models, ImportOptions options, IDataImportResult result) { if (models == null) { throw new ArgumentNullException(nameof(models)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } await this.InitializeResultAsync(result); await this.FilterOutInvalidModelsAsync(models, result); await this.FilterOutDuplicateModelsAsync(models, result); foreach (var import in models) { var saveResult = await this.Facade.SaveUserAsync(import); if (!saveResult.Succeeded) { await this.AddErrorAsync(saveResult, result); } } if (options.DeleteAllOthers) { var importIdentifiers = models.Select(import => import.Id).ToHashSet(StringComparer.OrdinalIgnoreCase); foreach (var user in this.Facade.Users.Where(user => !importIdentifiers.Contains(user.Id) && user.PasswordHash != null)) { var deleteResult = await this.Facade.DeleteUserAsync(user); if (!deleteResult.Succeeded) { await this.AddErrorAsync(deleteResult, result); } } } await this.PopulateResultAsync(result); }
public virtual async Task ImportAsync(IConfiguration configuration, ImportOptions options, IDataImportResult result) { var models = await this.GetModelsAsync(configuration); await this.ImportAsync(models, options, result); }
protected internal override async Task FilterOutDuplicateModelsAsync(IList <UserLoginModel> models, IDataImportResult result) { if (models == null) { throw new ArgumentNullException(nameof(models)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } await base.FilterOutDuplicateModelsAsync(models, result); var errorFormat = $"{typeof(UserLoginModel).Name}.{nameof(UserLoginModel.Provider)}+{nameof(UserLoginModel.UserIdentifier)} {{0}} has {{1}} duplicate{{2}}."; var copies = models.ToArray(); models.Clear(); foreach (var group in copies.GroupBy(model => (model.Provider.ToUpperInvariant(), model.UserIdentifier.ToUpperInvariant()))) { if (group.Count() > 1) { await this.AddErrorAsync(string.Format(null, errorFormat, group.Key, group.Count() - 1, group.Count() > 2 ? "s" : null), result); } else { models.Add(group.First()); } } }
protected internal virtual async Task AddErrorAsync(IdentityResult identityResult, IDataImportResult result) { if (identityResult == null) { throw new ArgumentNullException(nameof(identityResult)); } if (result == null) { throw new ArgumentNullException(nameof(result)); } await this.AddErrorAsync(await this.CreateErrorMessageAsync(identityResult), result); }