public object GenerateSettingsObjectForInspector(ISolutionProjectModel solutionProject = null, params object[] objectsToMerge) { var propertiesForInspector = new CustomClass("Properties", objectsToMerge); var settingsProviderClasses = CheckoutAndBuild2Package.GetExportedValues <ISettingsProviderClass>(); foreach (ISettingsProviderClass settingsProviderClass in settingsProviderClasses) { var res = GetSettingsFromProvider(settingsProviderClass.GetType(), solutionProject); IEnumerable <PropertyInfo> settableProperties; if (solutionProject != null) { settableProperties = res.GetSettableProperties(SettingsAvailability.ProjectSpecific, SettingsAvailability.GlobalWithProjectSpecificOverride); } else { settableProperties = res.GetSettableProperties(SettingsAvailability.Global, SettingsAvailability.GlobalWithProjectSpecificOverride); } foreach (var propertyInfo in settableProperties) { SettingsKey settingsKey = SettingsExtensions.GetSettingsKey(propertyInfo, res, solutionProject); var value = Get(settingsKey, propertyInfo.PropertyType, propertyInfo.GetValue(res)); propertiesForInspector.AddProperty(propertyInfo, value, o => Set(o.GetType(), settingsKey, o)); } } return(propertiesForInspector); }
public ISettingsProviderClass GetSettingsFromProvider(Type settingsProviderType, ISolutionProjectModel solutionProject = null) { var res = ReflectionHelper.CreateInstance(settingsProviderType) as ISettingsProviderClass; foreach (PropertyInfo propertyInfo in res.GetSettableProperties()) { var settingsPropertyAttribute = CoreExtensions.GetAttributes <SettingsPropertyAttribute>(propertyInfo, false).First(); SettingsKey settingsKey = SettingsExtensions.GetSettingsKey(propertyInfo, res); object defaultValue = null; DefaultValueAttribute defaultValueAttribute = CoreExtensions.GetAttributes <DefaultValueAttribute>(propertyInfo, false).FirstOrDefault(); if (defaultValueAttribute != null) { defaultValue = defaultValueAttribute.Value; } var loadedValue = Get(settingsKey, propertyInfo.PropertyType, defaultValue ?? propertyInfo.GetValue(res)); if (solutionProject != null && settingsPropertyAttribute.Availability == SettingsAvailability.ProjectSpecific || settingsPropertyAttribute.Availability == SettingsAvailability.GlobalWithProjectSpecificOverride) { settingsKey = SettingsExtensions.GetSettingsKey(propertyInfo, res, solutionProject); loadedValue = Get(settingsKey, propertyInfo.PropertyType, loadedValue); } propertyInfo.SetValue(res, loadedValue); } return(res); }
public void LoadConfig() { var configFile = SettingsExtensions.ReadFromJsonFile <Config>(Path.Combine(CONFIG_PATH, Name + ".json")); this.Name = configFile.Name; this.AimbotConfig = configFile.AimbotConfig; }
public SnowCapXSettings(IEnumerable <ISettingsProvider> provider, ILogger <SnowCapXSettings>?logger) { if (provider is null) { throw new ArgumentNullException(nameof(provider)); } _provider = new ChainedSettingsProvider(provider); _logger = logger; _bindings = new Dictionary <string, object>(); _provider.SettingChanged += Provider_SettingChanged; void Provider_SettingChanged(object sender, SettingsChangedEventArgs e) { var splited = e.Key.Split(SeperatonToken); if (_bindings.TryGetValue(splited[0], out object binding)) { var propInfo = binding.GetType().GetProperty(splited[1]); if (!(propInfo is null)) { var converted = SettingsExtensions.TryConvert(e.Value, propInfo.PropertyType); if (!(converted is null)) { propInfo.SetValue(binding, converted); } } } _logger.LogInformation($"Setting changed from provider, Path: {e.Key}; Value:{e.Value}"); } }
//------------------------------------------------------ //--Plugin Execution //------------------------------------------------------ public override void Log(IDictionary <string, object> moduleLog) { moduleLog["Application:Settings"] = Context.AllPluginTypes .Where(t => t.IsConcreteTypeDerivedFrom <IAppSettings>()) .Select(t => new { SettingsClass = t.AssemblyQualifiedName, SectionPath = SettingsExtensions.GetSectionPath(t) }); }
private static async Task Main() { await Task.Delay(5_000); var environment = Environment.GetEnvironmentVariable("BOTS_ENVIRONMENT") ?? "Development"; var data = await SettingsExtensions.LoadDataAsync(environment == "Development").ConfigureAwait(false); data.Restaurants = new List <Restaurant>(); await foreach (var restaurant in SettingsExtensions.YieldRestaurantsAsync(environment == "Development")) { data.Restaurants.Add(restaurant); } var languageModels = SettingsExtensions.YieldLanguagesAsync(); var languageDictionary = new Dictionary <string, LocalizationModel>(); await foreach (var(name, model) in languageModels) { languageDictionary[name] = model; } var googleCredential = await GoogleExtensions.AuthorizeAsync(data.GoogleCredentials).ConfigureAwait(false); var googleInitializer = new BaseClientService.Initializer { ApplicationName = "Telegram Bot", HttpClientInitializer = googleCredential }; await new HostBuilder() .UseEnvironment(environment) .ConfigureServices(serviceCollection => { serviceCollection.AddGeneralServices(data); serviceCollection.AddBotServices(data.Bot.Token); serviceCollection.AddDistributionBot(); serviceCollection.AddGuestsBot(); serviceCollection.AddReviewBot(); serviceCollection.AddStatsBot(); serviceCollection.AddMailBot(); serviceCollection.AddGoogleServices(googleInitializer); serviceCollection.AddLocalizationServices(languageDictionary); serviceCollection.AddHealthChecks(); serviceCollection.AddHostedService <RestartNotificationService>(); }) .ConfigureLogging(LoggingExtensions.Configure) .RunConsoleAsync().ConfigureAwait(false); }
// Register each application setting so a factory method is invoked when injected // into a dependent component. The factory method delegates to Microsoft's base // implementation. public override void ScanPlugins(ITypeCatalog catalog) { catalog.AsDescriptor( t => t.IsConcreteTypeDerivedFrom <IAppSettings>(), st => ServiceDescriptor.Singleton(st, sp => { Type optionsType = typeof(IOptions <>).MakeGenericType(st); dynamic options = sp.GetRequiredService(optionsType); object appSettings = options.Value; SettingsExtensions.ValidateSettings(Context.Logger, appSettings); return(appSettings); })); }
//------------------------------------------------------ //--Plugin Initialization //------------------------------------------------------ public override void RegisterServices(IServiceCollection services) { IEnumerable <Type> appSettingTypes = Context.AllPluginTypes .Where(t => t.IsConcreteTypeDerivedFrom <IAppSettings>()); foreach (Type appSettingType in appSettingTypes) { string sectionPath = SettingsExtensions.GetSectionPath(appSettingType); if (string.IsNullOrWhiteSpace(sectionPath)) { Context.BootstrapLogger.Add(LogLevel.Warning, $"The section path for setting type: {appSettingType.AssemblyQualifiedName} could " + $"not be determined. Make sure the attribute: {typeof(ConfigurationSectionAttribute)} is specified."); continue; } // This is a non-generic version that is automatically called and adds the // configuration-setting to the container. Eliminates having to manually make // call for each setting. services.Configure(appSettingType, Context.Configuration.GetSection(sectionPath)); } }
protected override void Load(ContainerBuilder builder) { builder.RegisterInstance(SettingsExtensions.GetSettings <CredentialsSettings>()) .SingleInstance(); }
public bool SaveConfig() { return(SettingsExtensions.WriteToJsonFile <Config>(Path.Combine(CONFIG_PATH, Name + ".json"), this)); }