public void canLoadAdminConfigFromYAML() { var sample = @"Elevated: - Id: 00000000000000000 Permission: 3 - Id: 11111111111111111 Permission: 6"; var actual = AdminConfig.FromYAML(sample); Assert.Equal("00000000000000000", actual.Elevated[0].Id); Assert.Equal(PermissionLevel.GameMaster, actual.Elevated[0].Permission); }
public ActionResult Edit_Config(AdminConfig ob) { ModelState.Remove("ID"); if (ModelState.IsValid) { AdminConfigBL.Update(ob); return(RedirectToAction("Configrations")); } else { return(View()); } }
public ValidateConfigFile(DatabaseConfigValidator databaseConfigValidator, DatabaseConfig databaseConfig, Auth0ConfigValidator auth0ConfigValidator, Auth0Config auth0Config, EmailConfigValidator emailConfigValidat, EmailConfig emailConfig, AdminConfigValidator adminConfigValidator, AdminConfig adminConfig, BillingConfigValidator configValidator, IBillingConfig config) { this.databaseConfigValidator = databaseConfigValidator; this.databaseConfig = databaseConfig; this.auth0ConfigValidator = auth0ConfigValidator; this.auth0Config = auth0Config; this.emailConfigValidator = emailConfigValidat; this.emailConfig = emailConfig; this.adminConfigValidator = adminConfigValidator; this.adminConfig = adminConfig; this.billingConfigValidator = configValidator; this.billingConfig = config; }
public BaseMainConfigAdmin() { // // TODO: Add constructor logic here // if (c.Sections["CWSAdminConfig"] != null) { _b = c.Sections["CWSAdminConfig"] as AdminConfig; } if (c.Sections["buybackConfig"] != null) { _a = c.Sections["buybackConfig"] as BuyBack; } }
private void BuildMainFormAndCustomForm <TModel>(AdminConfig <TModel> adminConfig, bool hasConfiguration, Type modelType) where TModel : class { BuildForm(adminConfig, hasConfiguration, modelType); foreach (var customForm in adminConfig.ModelConfig.CustomForms.Values) { if (customForm.SubmitActionExpression == null) { throw new InvalidOperationException($"SubmitActionExpression is required while adding a custom form"); } //hasConfiguration must be always true, since custom forms must have configuration and it must be configured! BuildForm(customForm.FormConfig, true, customForm.ModelType); } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { // Geographic Entities ContinentConfig.SetEntityBuilder(modelBuilder.Entity <Continent>()); CountryConfig.SetEntityBuilder(modelBuilder.Entity <Country>()); RegionConfig.SetEntityBuilder(modelBuilder.Entity <Region>()); // Administrative Entities AdminConfig.SetEntityBuilder(modelBuilder.Entity <Admin>()); EventConfig.SetEntityBuilder(modelBuilder.Entity <Event>()); // Measures Entities SanitaryMeasureConfig.SetEntityBuilder(modelBuilder.Entity <SanitaryMeasure>()); ContainmentMeasureConfig.SetEntityBuilder(modelBuilder.Entity <ContainmentMeasure>()); CmByCountry.SetEntityBuilder(modelBuilder.Entity <CountryContainmentMeasures>()); SmByCountry.SetEntityBuilder(modelBuilder.Entity <CountrySanitaryMeasures>()); // Hospital Entities HospitalConfig.SetEntityBuilder(modelBuilder.Entity <Hospital>()); HEmployeeConfig.SetEntityBuilder(modelBuilder.Entity <HospitalEmployee>()); MedicationConfig.SetEntityBuilder(modelBuilder.Entity <Medication>()); // Person Entities PatientConfig.SetEntityBuilder(modelBuilder.Entity <Patient>()); P_MedicationConfig.SetEntityBuilder(modelBuilder.Entity <PatientMedications>()); Pt_PathologyConfig.SetEntityBuilder(modelBuilder.Entity <PatientPathologies>()); PersonConfig.SetEntityBuilder(modelBuilder.Entity <ContactedPerson>()); Ps_PathologyConfig.SetEntityBuilder(modelBuilder.Entity <PersonPathologies>()); ContactsByPatientConfig.SetEntityBuilder(modelBuilder.Entity <PersonsContactedByPatient>()); // Not related Entities PathologiesConfig.SetEntityBuilder(modelBuilder.Entity <Pathology>()); Pharm_CompanyConfig.SetEntityBuilder(modelBuilder.Entity <PharmaceuticalCompany>()); StatusConfig.SetEntityBuilder(modelBuilder.Entity <PatientStatus>()); // Views and Stored Procedures modelBuilder.Entity <PatientView>().HasNoKey().ToView(null); modelBuilder.Entity <ExportPatient>().HasNoKey().ToView(null); modelBuilder.Entity <CasesView>().HasNoKey().ToView(null); modelBuilder.Entity <ReportView>().HasNoKey().ToView(null); modelBuilder.Entity <MeasureView>().HasNoKey().ToView(null); modelBuilder.Entity <MedicationView>().HasNoKey().ToView(null); modelBuilder.Entity <PatientMedicationView>().HasNoKey().ToView(null); modelBuilder.Entity <PathologyView>().HasNoKey().ToView(null); modelBuilder.Entity <ContactView>().HasNoKey().ToView(null); }
public KeyVaultAdminService(IOptionsSnapshot <AzureAdOptions> azureAdOptions, IOptionsSnapshot <AdminConfig> adminConfig, IOptionsSnapshot <Resources> resources, IGraphHttpService graphHttpService, IHttpContextAccessor contextAccessor) { var principal = contextAccessor.HttpContext.User; userId = principal.FindFirst("oid").Value; tenantId = Guid.Parse(principal.FindFirst("tid").Value); clientId = Guid.Parse(azureAdOptions.Value.ClientId); adalContext = new AuthenticationContext($"{azureAdOptions.Value.AADInstance}{azureAdOptions.Value.TenantId}", new ADALSessionCache(userId, contextAccessor)); resourceGroup = adminConfig.Value.ResourceGroup; kvManagmentClient = new KeyVaultManagementClient(new KeyVaultCredential(GetAppToken)); kvManagmentClient.SubscriptionId = adminConfig.Value.SubscriptionId; kvClient = new KeyVaultClient(new KeyVaultCredential(GetAppTokenForKv)); this.azureAdOptions = azureAdOptions.Value; this.adminConfig = adminConfig.Value; this.graphHttpService = graphHttpService; this.resources = resources.Value; }
/// <summary> /// Saves the AppConfig to "c:\ProgramData\..." /// </summary> protected static void SaveAppConfig() { try { Messenger.AddInfo(Messages.MSG_SAVING_KSPMA_SETTINGS); string path = KSPPathHelper.GetPath(KSPPaths.AppConfig); if (path != string.Empty && Directory.Exists(Path.GetDirectoryName(path))) { AdminConfig.Save(path); } else { Messenger.AddError(Messages.MSG_KSPMA_SETTINGS_PATH_INVALID); } } catch (Exception ex) { Messenger.AddError(Messages.MSG_ERROR_DURING_SAVING_KSPMA_SETTINGS, ex); ShowAdminRightsDlg(ex); } }
private void AddLookUpField <TModel>(AdminConfig <TModel> adminConfig, string lookupKey, LambdaExpression lookupExpression, LambdaExpression lookupKeyExpression, LambdaExpression lookupDisplayExpression) where TModel : class { List <LookUpField> MasterDataDelegate() { var lookUpFields = new List <LookUpField>(); var entityLookupExprDelegate = lookupExpression.Compile(); var entityLookupExprKeyDelegate = lookupKeyExpression.Compile(); var displayExprDelegate = lookupDisplayExpression.Compile(); var keyFieldName = ReflectionExtensions.GetMemberName(lookupKeyExpression); var serviceProvider = _serviceProvider.GetService <IHttpContextAccessor>().HttpContext.RequestServices; var items = entityLookupExprDelegate.DynamicInvoke(new object[] { serviceProvider }) as IList; foreach (var item in items) { var keyValue = entityLookupExprKeyDelegate.DynamicInvoke(new object[] { item }); var displayName = displayExprDelegate.DynamicInvoke(new object[] { item }) as string; lookUpFields.Add(new LookUpField() { Key = new Dictionary <string, object>() { { keyFieldName, keyValue } }, DisplayName = displayName }); } return(lookUpFields); } //adminConfig.LookUps.Add(relatedFiled.FieldOption.LookupModelType.Name, MasterDataDelegate); adminConfig.LookUps.Add(lookupKey, MasterDataDelegate); }
public AccountController(IOptions <AdminConfig> options) { adminConfig = options.Value; }
private static void Seed( AppDbContext context, AdminConfig adminConfig, ILogger <AppDbContext> logger, UserManager <User> userManager, RoleManager <IdentityRole <int> > rolesManager ) { try { /* init app */ var roles = Enum.GetNames(typeof(UserRoles)); var dbRoles = context.Roles.ToList(); if (roles.Length > dbRoles.Count) { var rolesToAdd = roles .Where(x => dbRoles.All(dbr => dbr.Name != x)); foreach (var role in rolesToAdd) { rolesManager.CreateAsync(new IdentityRole <int>(role)).Wait(); } } context.SaveChanges(); /* init project data */ /* admin */ var mainAdmin = new User(adminConfig.Mail) { Nick = adminConfig.Nick, Photo = adminConfig.Photo }; var createResult = userManager.CreateAsync(user: mainAdmin).GetAwaiter().GetResult(); context.SaveChanges(); var addPasswordResult = userManager.AddPasswordAsync(mainAdmin, adminConfig.Password).GetAwaiter().GetResult(); var addRoleResult = userManager.AddToRoleAsync(mainAdmin, UserRoles.Admin.ToString()).GetAwaiter().GetResult(); context.SaveChanges(); /* subjects */ var reactSubject = new Subject("React.js"); context.Add(reactSubject); context.SaveChanges(); using var stream = typeof(AppDbInitialize).Assembly.GetManifestResourceStream("Infrastructure.lessons.json"); using var reader = new StreamReader(stream !); var text = reader.ReadToEnd(); var objs = JsonConvert.DeserializeObject <LessonDetailedView[]>(text); var lessons = objs.Select(x => new Lesson(x.Name, x.IsPractice, reactSubject, x.Index, x.Description, x.Content)); context.Lessons.AddRange(lessons); context.SaveChanges(); } catch (Exception err) { logger.LogCritical(err.Message); throw; } }
private void LoadMasterData <TModel>(AdminConfig <TModel> adminConfig) where TModel : class { //Loading Master Data var relatedFileds = adminConfig.ModelConfig.FormConfig.AllFields .Where(f => f.FieldOption.RelationType == RelationType.ManyToMany || f.FieldOption.RelationType == RelationType.ManyToOne) .ToList(); var relatedFieldsInGrid = adminConfig.ModelConfig.GridConfig.AllFields .Where(f => f.FieldOption.LookupExpression != null).ToList(); var matrixFields = adminConfig.ModelConfig.FormConfig.AllFields .Where(f => f.FieldOption.FieldType == FieldType.CheckBoxMatrix) .ToList(); foreach (var field in relatedFieldsInGrid) { if (relatedFileds.All(f => f.FieldName != field.FieldName)) { relatedFileds.Add(field); } } if (adminConfig.ChildConfigs != null) { foreach (var childConfig in adminConfig.ChildConfigs) { var childConfigReleatedFields = childConfig.ModelConfig.FormConfig.AllFields .Where(f => f.FieldOption.RelationType == RelationType.ManyToMany || f.FieldOption.RelationType == RelationType.ManyToOne) .ToList(); relatedFileds.AddRange(childConfigReleatedFields); } } if (AdminType == AdminType.Entity) { foreach (var relatedField in relatedFileds) { var relatedModelType = relatedField.FieldOption.LookupModelType; var entityClrType = GetEntityClrTypeFor(relatedModelType); Func <List <LookUpField> > masterDataDelegate = () => CallGenericMethod <List <LookUpField> >(nameof(GetLookUpDataFromEntity), new Type[] { relatedModelType, entityClrType }, new object[] { relatedField.FieldOption.LookupDisplayExpression }); adminConfig.LookUps.Add(relatedField.FieldName, masterDataDelegate); } } else if (AdminType == AdminType.Custom) { foreach (var relatedFiled in relatedFileds) { if (relatedFiled.FieldOption.LookupFilterExpression != null) { continue; } AddLookUpField(adminConfig, relatedFiled.FieldName, relatedFiled.FieldOption.LookupExpression, relatedFiled.FieldOption.LookupKeyExpression, relatedFiled.FieldOption.LookupDisplayExpression); } foreach (var matrixField in matrixFields) { if (matrixField.FieldOption.CheckBoxMatrix == null) { continue; } var checkBoxMatrix = matrixField.FieldOption.CheckBoxMatrix; AddLookUpField(adminConfig, checkBoxMatrix.RowType.Name, checkBoxMatrix.RowLookupExpression, checkBoxMatrix.RowLookupKeyExpression, checkBoxMatrix.RowLookupDisplayExpression); AddLookUpField(adminConfig, checkBoxMatrix.ColumnType.Name, checkBoxMatrix.ColLookupExpression, checkBoxMatrix.ColLookupKeyExpression, checkBoxMatrix.ColLookupDisplayExpression); } } }
public void Build <TModel>(AdminConfig <TModel> adminConfig, bool hasConfiguration = false) where TModel : class { var modelType = typeof(TModel); switch (AdminType) { //TODO: Validate adminConfig for entity type case AdminType.Entity when AdminConfigs.ContainsKey(modelType): throw new InvalidOperationException($"The ModelType {modelType} has already been registered for this admin site, duplicate site registrations are not allowed"); case AdminType.Entity when Mapper == null: throw new InvalidOperationException($"AutoMapper configuration is required when creating admin site using AdminType: {AdminType}"); case AdminType.Entity: { if (_typeMaps == null) { _typeMaps = Mapper.ConfigurationProvider.GetAllTypeMaps().ToList(); } var entityClrType = GetEntityClrTypeFor(modelType); if (entityClrType == null) { throw new InvalidOperationException($"The entity type for the ModelType: {modelType} cannot be found in MapperConfiguration, please AutoMapper configuration for ModelType and ModelType"); } var entityType = _dbContext.Model.FindEntityType(entityClrType); if (entityType == null) { throw new InvalidOperationException($"The entity type for the ModelType: {modelType} cannot be found on this context {_dbContext}"); } adminConfig.EntityConfig = new EntityConfig(_dbContextType, entityType); BuildMainFormAndCustomForm(adminConfig, hasConfiguration, modelType); if (adminConfig.ChildConfigs != null && adminConfig.ChildConfigs.Count > 0) { foreach (var childConfig in adminConfig.ChildConfigs) { var childModelType = childConfig.Field.FieldClrType; var childEntityClrType = GetEntityClrTypeFor(childModelType); if (childEntityClrType == null) { throw new InvalidOperationException($"The entity type for the ModelType: {childModelType} cannot be found in MapperConfiguration, please check MapperConfiguration"); } var childEntityType = _dbContext.Model.FindEntityType(entityClrType); if (childEntityType == null) { throw new InvalidOperationException($"The entity type for the ModelType: {modelType} cannot be found on this context {_dbContext}"); } childConfig.EntityConfig = new EntityConfig(_dbContextType, childEntityType); BuildForm(childConfig, hasConfiguration, childModelType); } } break; } case AdminType.Custom when adminConfig.AdminServiceType == null: throw new InvalidOperationException($"AdminService is required when creating admin site with AdminType: {AdminType}"); case AdminType.Custom when(adminConfig.ModelConfig.KeyField.FieldExpression == null && adminConfig.AdminConfigType == AdminConfigType.GridAndForm): throw new InvalidOperationException($"KeyField is required when creating admin site with AdminType: {AdminType}"); case AdminType.Custom: { //TODO: Validate adminConfig for custom type BuildMainFormAndCustomForm(adminConfig, hasConfiguration, modelType); if (adminConfig.ChildConfigs != null && adminConfig.ChildConfigs.Count > 0) { foreach (var childConfig in adminConfig.ChildConfigs) { var childModelType = childConfig.Field.FieldClrType; BuildForm(childConfig, hasConfiguration, childModelType); } } break; } } LoadMasterData(adminConfig); AdminConfigs.Add(modelType, adminConfig); }
/// <summary> /// Shows a modal dialog box for editing extension properties. /// </summary> public virtual void ShowProperties(AdminConfig adminConfig) { }