예제 #1
0
 public void UpdateSetting(ConfigurableSettings setting, string value)
 {
     if (_settingValues.ContainsKey(setting))
     {
         _settingValues[setting] = value;
     }
 }
예제 #2
0
        public override void Execute()
        {
            string[] inputValues = _input.Split(' ');
            if (inputValues.Length < 3)
            {
                Console.WriteLine("Not enough values provided for setting", Color.Red);
                Console.WriteLine("update <code> <desiredValue>");
                return;
            }
            if (!Int32.TryParse(inputValues[1], out _code))
            {
                Console.WriteLine("Code parameter must be a numerical value", Color.Red);
                return;
            }
            ConfigurableSettings setting = (ConfigurableSettings)_code;

            if (setting == ConfigurableSettings.RainyThreshold ||
                (setting == ConfigurableSettings.SunnyThreshold))
            {
                int thresholdVal = ValidateThresholdValue(inputValues[2]);
                ApplicationSettings.GetInstance().UpdateSetting(setting, thresholdVal.ToString());
                Console.WriteLine($"\t{setting} updated");
                return;
            }
            ApplicationSettings.GetInstance().UpdateSetting(setting, inputValues[2]);
            Console.WriteLine($"\t{setting} updated");
        }
	/// <summary>
	/// Initializes a new instance of the <see cref="AudioController"/> class.
	/// </summary>
	/// <param name="background">Background.</param>
	/// <param name="sound">Sound.</param>
	/// <param name="soundEffectsMuted">If set to <c>true</c> sound effects muted.</param>
	/// <param name="backgroundSoundMuted">If set to <c>true</c> background sounds muted.</param>
	/// <param name="configSettings">Config settings.</param>
	public AudioController(BackgroundSound background, SoundEffects sound, bool soundEffectsMuted, bool backgroundSoundMuted, ConfigurableSettings configSettings)
	{
		configurableSettings = configSettings;
		backgroundSound = background;
		soundEffects = sound;
		SoundEffectsMuted = soundEffectsMuted;
		BackgroundSoundMuted = backgroundSoundMuted;
		if(!BackgroundSoundMuted) backgroundSound.PlayOnStart = true;
	}
예제 #4
0
        public void InitializeEnvironment()
        {
            // settings are hardcoded
#if DEBUG
            {
                var settings = new HardcodedSettings();
                m_Container.RegisterInstanceAs <IEnvironmentSettings>(settings);
            }
#endif

            // enables the user to configure the settings via xml
#if RELEASE
            {
                var settings = new ConfigurableSettings();
                m_Container.RegisterInstanceAs <IEnvironmentSettings>(settings);
            }
#endif
        }
예제 #5
0
        public sealed override async Task <int> ExecuteAsync(CommandContext context, TSettings commandSettings)
        {
            // Set verbose tracing
            if (commandSettings.LogLevel != LogLevel.Information)
            {
                ServiceCollection.Configure <LoggerFilterOptions>(options => options.MinLevel = commandSettings.LogLevel);
            }

            // File logging
            if (!string.IsNullOrEmpty(commandSettings.LogFile))
            {
                // Add the log provider (adding it to the service collection will get picked up by the logger factory)
                ServiceCollection.AddSingleton <ILoggerProvider, FileLoggerProvider>();
                ServiceCollection.Configure <FileLoggerOptions>(options =>
                {
                    options.FileName     = commandSettings.LogFile;
                    options.LogDirectory = string.Empty;
                });
            }

            // Build a temporary service provider so we can log
            // Make sure to place it in it's own scope so transient services get correctly disposed
            IServiceProvider services     = ServiceCollection.BuildServiceProvider();
            ClassCatalog     classCatalog = services.GetService <ClassCatalog>();

            using (IServiceScope serviceScope = services.CreateScope())
            {
                // Log pending messages
                ILogger logger = serviceScope.ServiceProvider.GetRequiredService <ILogger <Bootstrapper> >();
                logger.LogInformation($"Statiq version {Engine.Version}");
                classCatalog?.LogDebugMessages(logger);

                // Attach
                if (commandSettings.Attach)
                {
                    logger.LogInformation($"Waiting for a debugger to attach to process {Process.GetCurrentProcess().Id} (or press a key to continue)...");
                    while (!Debugger.IsAttached && !Console.KeyAvailable)
                    {
                        Thread.Sleep(100);
                    }
                    if (Console.KeyAvailable)
                    {
                        Console.ReadKey(true);
                        logger.LogInformation("Key pressed, continuing execution");
                    }
                    else
                    {
                        logger.LogInformation("Debugger attached, continuing execution");
                    }
                }
            }

            // Add settings
            if (commandSettings.Settings?.Length > 0)
            {
                foreach (KeyValuePair <string, string> setting in SettingsParser.Parse(commandSettings.Settings))
                {
                    ConfigurationSettings[setting.Key] = setting.Value;
                }
            }

            // Configure settings after other configuration so they can use the values
            ConfigurableSettings configurableSettings = new ConfigurableSettings(ConfigurationSettings);

            Configurators.Configure(configurableSettings);

            return(await ExecuteCommandAsync(context, commandSettings));
        }
예제 #6
0
 public string GetSettingValue(ConfigurableSettings setting)
 {
     return(_settingValues[setting] ?? "");
 }
예제 #7
0
        /// <inheritdoc/>
        public async Task <int> RunAsync()
        {
            // Remove the synchronization context
            await default(SynchronizationContextRemover);

            // Populate the class catalog (if we haven't already)
            _classCatalog.Populate();

            // Run bootstrapper configurators first
            Configurators.Configure <IConfigurableBootstrapper>(this);
            Configurators.Configure <IBootstrapper>(this);

            // Get our initial settings for configuration
            EngineSettingsConfigurationProvider settingsProvider = new EngineSettingsConfigurationProvider();
            ConfigurableSettings configurableSettings            = new ConfigurableSettings(settingsProvider);

            Configurators.Configure(configurableSettings);

            // Run the configuration configurator and get the configuration root
            IConfigurationBuilder     configurationBuilder      = new ConfigurationBuilder().Add(settingsProvider);
            ConfigurableConfiguration configurableConfiguration = new ConfigurableConfiguration(configurationBuilder);

            Configurators.Configure(configurableConfiguration);
            IConfigurationRoot configurationRoot = configurationBuilder.Build();

            // Create the service collection
            IServiceCollection serviceCollection = CreateServiceCollection() ?? new ServiceCollection();

            serviceCollection.TryAddSingleton <IConfigurableBootstrapper>(this);
            serviceCollection.TryAddSingleton <IBootstrapper>(this);
            serviceCollection.TryAddSingleton(_classCatalog);  // The class catalog is retrieved later for deferred logging once a service provider is built
            serviceCollection.TryAddSingleton <IConfiguration>(configurationRoot);

            // Run configurators on the service collection
            ConfigurableServices configurableServices = new ConfigurableServices(serviceCollection, configurationRoot);

            Configurators.Configure(configurableServices);

            // Add simple logging to make sure it's available in commands before the engine adds in,
            // but add it after the configurators have a chance to configure logging
            serviceCollection.AddLogging();

            // Create the stand-alone command line service container and register a few types needed for the CLI
            CommandServiceTypeRegistrar registrar = new CommandServiceTypeRegistrar();

            registrar.RegisterInstance(typeof(IEngineSettingsDictionary), settingsProvider);
            registrar.RegisterInstance(typeof(IConfigurationRoot), configurationRoot);
            registrar.RegisterInstance(typeof(IServiceCollection), serviceCollection);
            registrar.RegisterInstance(typeof(IBootstrapper), this);

            // Create the command line parser and run the command
            ICommandApp app = _getCommandApp(registrar);

            app.Configure(commandConfigurator =>
            {
                commandConfigurator.ValidateExamples();
                ConfigurableCommands configurableCommands = new ConfigurableCommands(commandConfigurator);
                Configurators.Configure(configurableCommands);
            });
            int exitCode = await app.RunAsync(Arguments);

            // Dispose all instances of the console logger to flush the message queue and stop the listening thread
            ConsoleLoggerProvider.DisposeAll();

            return(exitCode);
        }