public static IConfigurationBuilder AddApplicationInsightsSettings(this IConfigurationBuilder configurationSourceRoot, bool?developerMode = null, string endpointAddress = null, string instrumentationKey = null)
        {
            var  telemetryConfigurationSource = new MemoryConfigurationProvider();
            bool wasAnythingSet = false;

            if (developerMode != null)
            {
                telemetryConfigurationSource.Set(DeveloperModeForWebSites, developerMode.Value.ToString());
                wasAnythingSet = true;
            }

            if (instrumentationKey != null)
            {
                telemetryConfigurationSource.Set(InstrumentationKeyForWebSites, instrumentationKey);
                wasAnythingSet = true;
            }

            if (endpointAddress != null)
            {
                telemetryConfigurationSource.Set(EndpointAddressForWebSites, endpointAddress);
                wasAnythingSet = true;
            }

            if (wasAnythingSet)
            {
                configurationSourceRoot.Add(telemetryConfigurationSource);
            }

            return(configurationSourceRoot);
        }
Exemple #2
0
        private static void ChangeNonTypeSpecifiedConfig(IConfigurationRoot root, params KeyValuePair <string, string>[] additionalSettings)
        {
            MemoryConfigurationProvider provider = (MemoryConfigurationProvider)root.Providers.First();

            provider.Set("foo:bar", "456");
            foreach (var setting in additionalSettings)
            {
                provider.Set(setting.Key, setting.Value);
            }
            var _onReloadMethod = typeof(ConfigurationProvider).GetMethod("OnReload", BindingFlags.Instance | BindingFlags.NonPublic);

            _onReloadMethod.Invoke(provider, null);
        }
Exemple #3
0
        private BackTelemetryChannel Start(string assemblyName)
        {
            var customConfig = new MemoryConfigurationProvider();

            customConfig.Set("server.urls", this.BaseHost);
            var configBuilder = new ConfigurationBuilder();

            configBuilder.Add(customConfig);
            var config = configBuilder.Build();

            var services = new ServiceCollection();

            services.AddTransient <IApplicationEnvironment, ApplicationEnvironment>();
            var serviceProvider = services.BuildServiceProvider();

            var engine = CreateBuilder(config)
                         .UseServer("Microsoft.AspNet.Server.WebListener")
                         .UseStartup(assemblyName)
                         .UseEnvironment("Production")
                         .Build();

            this.hostingEngine = engine.Start();

            return((BackTelemetryChannel)engine.ApplicationServices.GetService <ITelemetryChannel>());
        }
        private BackTelemetryChannel Start(string assemblyName)
        {
            var customConfig = new MemoryConfigurationProvider();
            customConfig.Set("server.urls", this.BaseHost);
            var configBuilder = new ConfigurationBuilder();
            configBuilder.Add(customConfig);
            var config = configBuilder.Build();

            var engine = CreateBuilder(config)
                .UseServer("Microsoft.AspNet.Server.WebListener")
                .UseStartup(assemblyName)
                .UseEnvironment("Production")
                .Build();
            this.hostingEngine = engine.Start();

            return (BackTelemetryChannel)engine.ApplicationServices.GetService<ITelemetryChannel>();
        }
        public void Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            Console.WriteLine("Initial Config Providers: " + builder.Providers.Count());

            var defaultSettings = new MemoryConfigurationProvider();
            defaultSettings.Set("username", "Guest");
            builder.Add(defaultSettings);
            Console.WriteLine("Added Memory Provider. Providers: " + builder.Providers.Count());

            builder.AddCommandLine(args);
            Console.WriteLine("Added Command Line Provider. Providers: " + builder.Providers.Count());

            var config = builder.Build();
            string username = config["username"];

            Console.WriteLine($"Hello, {username}!");
        }
Exemple #6
0
        public void Main(string[] args)
        {
            var builder = new ConfigurationBuilder();

            Console.WriteLine("Initial Config Providers: " + builder.Providers.Count());

            var defaultSettings = new MemoryConfigurationProvider();

            defaultSettings.Set("username", "Guest");
            builder.Add(defaultSettings);
            Console.WriteLine("Added Memory Provider. Providers: " + builder.Providers.Count());

            builder.AddCommandLine(args);
            Console.WriteLine("Added Command Line Provider. Providers: " + builder.Providers.Count());

            var    config   = builder.Build();
            string username = config["username"];

            Console.WriteLine($"Hello, {username}!");
        }