public static void AddRangeIfNotContains <T>(this HashSet <T> set, IEnumerable <T> range) { foreach (T item in range) { set.AddIfNotContains(item); } }
private async Task MigrateTenatsAsync() { var tenants = await _tenantRepository.GetListAsync(includeDetails : true); var migratedDatabaseSchemas = new HashSet <string>(); foreach (var tenant in tenants) { using (_currentTenant.Change(tenant.Id)) { if (tenant.ConnectionStrings.Any()) { var tenantConnectionStrings = tenant.ConnectionStrings .Select(x => x.Value) .ToList(); if (!migratedDatabaseSchemas.IsSupersetOf(tenantConnectionStrings)) { await MigrateDatabaseSchemaAsync(tenant); migratedDatabaseSchemas.AddIfNotContains(tenantConnectionStrings); } } await SeedDataAsync(tenant); } Logger.LogInformation($"Successfully completed {tenant.Name} tenant database migrations."); } }
protected virtual async Task <List <ISettingPageContributor> > GetAvailableContributorsInternalAsync() { var contributors = ServiceProvider.GetRequiredService <IOptions <SettingManagementPageOptions> >().Value.Contributors; var contributorBases = contributors.Where(x => x is SettingPageContributorBase).Cast <SettingPageContributorBase>().ToList(); var permissions = new HashSet <string>(); permissions.AddIfNotContains(contributorBases.SelectMany(x => x.GetRequiredPermissions())); var featureChecker = ServiceProvider.GetRequiredService <IFeatureChecker>(); var permissionChecker = ServiceProvider.GetRequiredService <IPermissionChecker>(); var grantResult = await permissionChecker.IsGrantedAsync(permissions.ToArray()); var availableContributors = new List <ISettingPageContributor>(); foreach (var contributor in contributorBases) { var available = true; var requiredFeatures = contributor.GetRequiredFeatures(); if (requiredFeatures.Any() && !await featureChecker.IsEnabledAsync(true, requiredFeatures.ToArray())) { available = false; } if (available) { var requiredTenantSideFeatures = contributor.GetRequiredFeatures(MultiTenancySides.Tenant); if (requiredTenantSideFeatures.Any() && !await featureChecker.IsEnabledAsync(true, requiredTenantSideFeatures.ToArray())) { available = false; } } if (available) { available = contributor.GetRequiredPermissions().All(x => grantResult.Result.ContainsKey(x) && grantResult.Result[x] == PermissionGrantResult.Granted); } if (available) { availableContributors.Add(contributor); } } var context = new SettingPageCreationContext(ServiceProvider); foreach (var contributor in contributors.Where(x => x is not SettingPageContributorBase)) { #pragma warning disable CS0618 if (await contributor.CheckPermissionsAsync(context)) #pragma warning restore CS0618 { availableContributors.Add(contributor); } } return(availableContributors); }
public async Task MigrateAsync() { try { if (!await MigrationsFolderExists()) { await AddInitialMigration(); return; } } catch (Exception e) { Logger.LogWarning("Couldn't determinate if any migrations exist : " + e.Message); } Logger.LogInformation("Started database migrations..."); await MigrateDatabaseSchemaAsync(); await SeedDataAsync(); Logger.LogInformation($"Successfully completed host database migrations."); var tenants = await _tenantRepository.GetListAsync(includeDetails : true); var migratedDatabaseSchemas = new HashSet <string>(); foreach (var tenant in tenants) { using (_currentTenant.Change(tenant.Id)) { if (tenant.ConnectionStrings.Any()) { var tenantConnectionStrings = tenant.ConnectionStrings .Select(x => x.Value) .ToList(); if (!migratedDatabaseSchemas.IsSupersetOf(tenantConnectionStrings)) { await MigrateDatabaseSchemaAsync(tenant); migratedDatabaseSchemas.AddIfNotContains(tenantConnectionStrings); } } await SeedDataAsync(tenant); } Logger.LogInformation($"Successfully completed {tenant.Name} tenant database migrations."); } Logger.LogInformation("Successfully completed all database migrations."); Logger.LogInformation("You can safely end this process..."); }
public async Task <IListResult <BookDto> > GetAllBook() { var result = await _bookRepository.GetAllListAsync(); var list = new HashSet <BookDto>(); foreach (var item in result) { list.AddIfNotContains(BookDto.MaptoDto(item)); } return(new ListResultDto <BookDto>(list.ToList())); }
public async Task MigrateAsync() { //<TEMPLATE-REMOVE IF-NOT='EFCORE'> var initialMigrationAdded = AddInitialMigrationIfNotExist(); if (initialMigrationAdded) { return; } //</TEMPLATE-REMOVE> Logger.LogInformation("Started database migrations..."); await MigrateDatabaseSchemaAsync(); await SeedDataAsync(); Logger.LogInformation($"Successfully completed host database migrations."); var tenants = await _tenantRepository.GetListAsync(includeDetails : true); var migratedDatabaseSchemas = new HashSet <string>(); foreach (var tenant in tenants) { using (_currentTenant.Change(tenant.Id)) { if (tenant.ConnectionStrings.Any()) { var tenantConnectionStrings = tenant.ConnectionStrings .Select(x => x.Value) .ToList(); if (!migratedDatabaseSchemas.IsSupersetOf(tenantConnectionStrings)) { await MigrateDatabaseSchemaAsync(tenant); migratedDatabaseSchemas.AddIfNotContains(tenantConnectionStrings); } } await SeedDataAsync(tenant); } Logger.LogInformation($"Successfully completed {tenant.Name} tenant database migrations."); } Logger.LogInformation("Successfully completed all database migrations."); Logger.LogInformation("You can safely end this process..."); }
private static void CollectNeighborTilesRecursive( Queue <Tile> tempCheckQueue, HashSet <Tile> tempAllNeighborTiles, int depthRemains) { var nextDepthRemains = depthRemains - 1; var count = tempCheckQueue.Count; for (var i = 0; i < count; i++) { var tile = tempCheckQueue.Dequeue(); if (!tempAllNeighborTiles.AddIfNotContains(tile)) { continue; } if (nextDepthRemains == 0) { continue; } foreach (var otherTile in tile.EightNeighborTiles) { if (otherTile.IsValidTile) { tempCheckQueue.Enqueue(otherTile); } } } if (nextDepthRemains == 0) { return; } CollectNeighborTilesRecursive(tempCheckQueue, tempAllNeighborTiles, nextDepthRemains); }
protected virtual SettingPageContributorBase RequiredTenantSideFeatures(params string[] features) { Check.NotNullOrEmpty(features, nameof(features)); _requiredTenantSideFeatures.AddIfNotContains(features); return(this); }
protected virtual SettingPageContributorBase RequiredPermissions(params string[] permissions) { Check.NotNullOrEmpty(permissions, nameof(permissions)); _requiredPermissions.AddIfNotContains(permissions); return(this); }
private IEnumerable <EfficiencyShift> GetOrphanedShiftsFromTransactions( [NotNull] string siteCode, [NotNull] Employee[] employees, bool isLtl, DateTime startTime, DateTime endTime, [NotNull] ICollection <EfficiencyTimeSheet> knownTimeSheets, EfficiencyTransactionType[] transactionTypes, BusinessUnitType businessUnitType, [CanBeNull] IEnumerable <string> siteEmployeeCodesFilter = null, [CanBeNull] EmployeeShiftSupevisor[] employeeShiftSupevisors = null) { var results = new List <EfficiencyShift>(); var transactionCacheRepository = _transactionCacheRepositoryFactory.GetCurrent(); var filteredSiteEmployeeCodes = siteEmployeeCodesFilter?.ToArray() ?? transactionCacheRepository.GetTransactionSiteEmployeeCodes(siteCode).ToArray(); var mappedSiteEmployeeCodes = new HashSet <string>(StringComparer.OrdinalIgnoreCase); // Mapped employees. Bucket everything by the EmployeeNumber. foreach (var employee in employees) { var siteEmployeeCodes = employee.SiteEmployees.Select(e => e.SiteEmployeeCode) .Distinct(StringComparer.OrdinalIgnoreCase).ToArray(); var employeeShiftSupevisor = employeeShiftSupevisors?.FirstOrDefault(x => x.Employee.TnaEmployeeCode.IgnoreCaseEquals(employee.TnaEmployeeCode)); foreach (var siteEmployeeCode in filteredSiteEmployeeCodes) { if (siteEmployeeCode.ExistsInArray(siteEmployeeCodes)) { mappedSiteEmployeeCodes.AddIfNotContains(siteEmployeeCode); } } if (!filteredSiteEmployeeCodes.Any(x => x.ExistsInArray(siteEmployeeCodes))) { continue; } var orphanedShifts = GetOrphanedShifts(siteCode, isLtl, siteEmployeeCodes, knownTimeSheets.Where(x => x.TnaEmployeeCode.IgnoreCaseEquals(employee.TnaEmployeeCode)), startTime, endTime, transactionTypes, businessUnitType, employee, employeeShiftSupevisor); results.AddRange(orphanedShifts.Where(x => Math.Abs((x.EndTime - x.StartTime).TotalHours) <= 24)); var orphanShiftsToSplit = orphanedShifts.Where(x => Math.Abs((x.EndTime - x.StartTime).TotalHours) > 24); AddMultiDayShifts(orphanShiftsToSplit, results, _mapper); } // Unmapped employees. Bucket everything under the SiteEmployeeCode. foreach (var siteEmployeeCode in filteredSiteEmployeeCodes) { if (mappedSiteEmployeeCodes.Contains(siteEmployeeCode)) { // Already mapped continue; } var orphanedShifts = GetOrphanedShifts(siteCode, isLtl, new[] { siteEmployeeCode }, new EfficiencyTimeSheet[0], startTime, endTime, transactionTypes, businessUnitType); results.AddRange(orphanedShifts.Where(x => Math.Abs((x.EndTime - x.StartTime).TotalHours) <= 24)); var orphanShiftsToSplit = orphanedShifts.Where(x => Math.Abs((x.EndTime - x.StartTime).TotalHours) > 24); AddMultiDayShifts(orphanShiftsToSplit, results, _mapper); } return(results); }