Ejemplo n.º 1
0
 public UmbracoConfig(IApplicationEnvironment appEnv)
 {
     var cfg = new ConfigurationBuilder()
         .SetBasePath(appEnv.ApplicationBasePath)
         .AddJsonFile("umbraco.json");
     _config = cfg.Build();
 }
Ejemplo n.º 2
0
 public Startup(IHostingEnvironment environment)
 {
     Configuration = new ConfigurationBuilder(".")
         .AddJsonFile("config.json")
         .AddEnvironmentVariables()
         .Build();
 }
Ejemplo n.º 3
0
 public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
 {
     var configuration =
         new ConfigurationBuilder(appEnv.ApplicationBasePath).AddJsonFile("config.json", false)
             .AddEnvironmentVariables();
     this.Configuration = configuration.Build();
 }
Ejemplo n.º 4
0
 public Startup(IApplicationEnvironment appEnv)
 {
     var configBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath);
     configBuilder.AddUserSecrets();
     configBuilder.AddEnvironmentVariables();
     _configuration = configBuilder.Build();
 }
Ejemplo n.º 5
0
 public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
 {
     var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
         .AddJsonFile("config.json")
         .AddEnvironmentVariables();
     Configuration = builder.Build();
 }
Ejemplo n.º 6
0
        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .Enrich.WithMachineName()
                .Enrich.FromLogContext()
                .WriteTo.Console()
                .WriteTo.Seq("http://localhost:5341")
                .CreateLogger();

            Log.Information("Starting up");

            Metrics.Collector = new CollectorConfiguration()
                .Batch.AtInterval(TimeSpan.FromSeconds(5))
                .Tag.With("host", Environment.GetEnvironmentVariable("COMPUTERNAME"))
                .WriteTo.InfluxDB("http://192.168.99.100:8086", "data")
                .CreateCollector();

            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
Ejemplo n.º 7
0
 public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
 {
     var configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath);
     configurationBuilder.AddEnvironmentVariables("BinaryMash.ReleaseManager:");
     configurationBuilder.AddJsonFile("Config.json");
     _configuration = configurationBuilder.Build();
 }
Ejemplo n.º 8
0
        public void Main(string[] args)
        {
            // Allow the location of the ini file to be specified via a --config command line arg
            var tempBuilder = new ConfigurationBuilder().AddCommandLine(args);
            var tempConfig = tempBuilder.Build();
            var configFilePath = tempConfig[ConfigFileKey] ?? HostingIniFile;

            var appBasePath = _serviceProvider.GetRequiredService<IApplicationEnvironment>().ApplicationBasePath;
            var builder = new ConfigurationBuilder(appBasePath);
            builder.AddIniFile(configFilePath, optional: true);
            builder.AddEnvironmentVariables();
            builder.AddCommandLine(args);
            var config = builder.Build();

            var host = new WebHostBuilder(_serviceProvider, config).Build();
            using (host.Start())
            {
                Console.WriteLine("Started");
                var appShutdownService = host.ApplicationServices.GetRequiredService<IApplicationShutdown>();
                Console.CancelKeyPress += (sender, eventArgs) =>
                {
                    appShutdownService.RequestShutdown();
                    // Don't terminate the process immediately, wait for the Main thread to exit gracefully.
                    eventArgs.Cancel = true;
                };
                appShutdownService.ShutdownRequested.WaitHandle.WaitOne();
            }
        }
Ejemplo n.º 9
0
        public int Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            builder.Add(new JsonConfigurationSource("config.json"));
            var config = builder.Build();
            var webjobsConnectionString = config["Data:AzureWebJobsStorage:ConnectionString"];
            var dbConnectionString = config["Data:DefaultConnection:ConnectionString"];

            if (string.IsNullOrWhiteSpace(webjobsConnectionString))
            {
                Console.WriteLine("The configuration value for Azure Web Jobs Connection String is missing.");
                return 10;
            }

            if (string.IsNullOrWhiteSpace(dbConnectionString))
            {
                Console.WriteLine("The configuration value for Database Connection String is missing.");
                return 10;
            }

            var jobHostConfig = new JobHostConfiguration(webjobsConnectionString);
            var host = new JobHost(jobHostConfig);

            host.RunAndBlock();
            return 0;
        }
Ejemplo n.º 10
0
 public Startup(IHostingEnvironment env, IApplicationEnvironment app)
 {
     Configuration = new ConfigurationBuilder(app.ApplicationBasePath)
     .AddJsonFile("settings.json")
     .AddEnvironmentVariables()
     .Build();
 }
Ejemplo n.º 11
0
        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            Env = env;
            Env.Initialize(appEnv.ApplicationBasePath, "Development");
            Env.Initialize(appEnv.ApplicationBasePath, "Production");
            Env.Initialize(appEnv.ApplicationBasePath, "Staging");

#if DEBUG
            Env.EnvironmentName = "Development";
#else

            if (appEnv.ApplicationBasePath.ToLower().Contains("staging"))
            {
                Env.EnvironmentName = "Staging";
            }
            else
            {
                Env.EnvironmentName = "Production";
            }
#endif 
            // Setup configuration sources.
            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .AddEnvironmentVariables();
            Configuration = builder.Build();
        }
Ejemplo n.º 12
0
 public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
 {
     var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
         .AddJsonFile("config.json")
         .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);
     Configuration = builder.Build();
 }
Ejemplo n.º 13
0
        public int Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            builder.Add(new JsonConfigurationProvider("config.json"));
            var config = builder.Build();
            var webjobsConnectionString = config["Data:AzureWebJobsStorage:ConnectionString"];
            var dbConnectionString = config["Data:DefaultConnection:ConnectionString"];
            if (string.IsNullOrWhiteSpace(webjobsConnectionString))
            {
                Console.WriteLine("The configuration value for Azure Web Jobs Connection String is missing.");
                return 10;
            }

            if (string.IsNullOrWhiteSpace(dbConnectionString))
            {
                Console.WriteLine("The configuration value for Database Connection String is missing.");
                return 10;
            }

            var jobHostConfig = new JobHostConfiguration(config["Data:AzureWebJobsStorage:ConnectionString"]);
            var host = new JobHost(jobHostConfig);
            var methodInfo = typeof(Functions).GetMethods().First();

            host.Call(methodInfo);
            return 0;
        }
Ejemplo n.º 14
0
        // This method gets called by a runtime.
        // Use this method to add services to the container
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();


            var path = _app.ApplicationBasePath;
            var config = new ConfigurationBuilder()
            .AddJsonFile($"{path}/config.json")
            .Build();

            string typeName = config.Get<string>("RepositoryType");
            services.AddSingleton(typeof(IBoilerRepository), Type.GetType(typeName));

            object repoInstance = Activator.CreateInstance(Type.GetType(typeName));
            IBoilerRepository repo = repoInstance as IBoilerRepository;
            services.AddInstance(typeof(IBoilerRepository), repo);
            TimerAdapter timer = new TimerAdapter(0, 500);
            BoilerStatusRepository db = new BoilerStatusRepository();
            services.AddInstance(typeof(BoilerMonitor), new BoilerMonitor(repo, timer, db));




            services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            });


            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();

            return services.BuildServiceProvider();
        }
Ejemplo n.º 15
0
 public Startup(IApplicationEnvironment environment)
 {
     Configuration =
         new ConfigurationBuilder(environment.ApplicationBasePath)
             .AddJsonFile("config.json")
             .Build();
 }
Ejemplo n.º 16
0
 public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
 {
     // Setup configuration sources.
     Configuration = new ConfigurationBuilder(appEnv.ApplicationBasePath)
         .AddJsonFile("config.json")
         .AddEnvironmentVariables().Build();
 }
Ejemplo n.º 17
0
        public Functional()
        {
            var appEnv = CallContextServiceLocator.Locator.ServiceProvider.GetService(typeof(IApplicationEnvironment)) as IApplicationEnvironment;
            Debug.Assert(appEnv != null, "appEnv != null");
            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath);
            builder.AddJsonFile("config.json");
            builder.AddJsonFile("config.private.json", true);
            var configuration = builder.Build();

            var uri = new Uri(configuration["ServerCredentialUri"]);
            var username = configuration["ServerCredentialUsername"];
            var password = configuration["ServerCredentialPassword"];

            _serverCredential = new ServerCredential(uri, username, password);

            _freeMusicTorrentFile =
                new HttpClient().GetByteArrayAsync(
                    new Uri("http://bt.etree.org/download.php/582271/hottuna2015-09-11.flac16.torrent")).Result;
            _freeMusicTorrentHash = "9ecc7229ff971d27552dd399509e188847dbbbf1";

            // Make sure there is no torrents before executing the tests
            var api = new Api(_serverCredential);
            var torrents = api.GetTorrents().Result;
            if (torrents.Any())
            {
                var result = api.Perform(Action.Removedata, torrents.Select(t => t.InfoHash)).Result;
                Assert.True(result);
            }
        }
Ejemplo n.º 18
0
        public void Main(string[] args)
        {
            _serviceCollection.AddDaniel15();
            var builder = new ConfigurationBuilder(_appEnv.ApplicationBasePath)
                // This is extremely ugly, but the paths differ in dev vs in prod.
                // Need to figure out a nicer way of doing this.
                .AddJsonFile("..\\Daniel15.Web\\config.json", optional: true)
                .AddJsonFile("../../../../../../site/approot/packages/Daniel15.Web/1.0.0/root/config.Production.json", optional: true)
                .AddEnvironmentVariables();
            _serviceCollection.AddDaniel15Config(builder.Build());
            _serviceCollection.AddOptions();
            _serviceProvider = _serviceCollection.BuildServiceProvider();

            var operation = args[0];
            switch (operation)
            {
                case "-disqus":
                    _serviceProvider.GetRequiredService<IDisqusComments>().Sync();
                    break;

                case "-social":
                    ActivatorUtilities.CreateInstance<SocialShareUpdater>(_serviceProvider).Run();
                    break;

                case "-projects":
                    ActivatorUtilities.CreateInstance<ProjectUpdater>(_serviceProvider).Run();
                    break;

                default:
                    throw new Exception("Invalid operation '" + operation + "'");
            }
        }
Ejemplo n.º 19
0
 public Startup(IHostingEnvironment env)
 {
     // Setup configuration sources.
     Configuration = new ConfigurationBuilder()
         .AddJsonFile("config.json")
         .AddEnvironmentVariables().Build();
 }
Ejemplo n.º 20
0
 public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
 {
     _basePath = appEnv.ApplicationBasePath;
     Configuration = new ConfigurationBuilder()
         .AddJsonFile(_basePath + "/App_Data/Development.json")
         .Build();
 }
Ejemplo n.º 21
0
        IEnumerable<ShellSettings> IShellSettingsManager.LoadSettings()
        {
            var shellSettings = new List<ShellSettings>();

            foreach (var tenant in _appDataFolder.ListDirectories("Sites")) {
                _logger.LogInformation("ShellSettings found in '{0}', attempting to load.", tenant.Name);

                var configurationContainer =
                    new ConfigurationBuilder()
                        .AddJsonFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "json")),
                            true)
                        .AddXmlFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "xml")),
                            true)
                        .AddYamlFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "txt")),
                            false);

                var config = configurationContainer.Build();

                var shellSetting = new ShellSettings(config);
                shellSettings.Add(shellSetting);

                _logger.LogInformation("Loaded ShellSettings for tenant '{0}'", shellSetting.Name);
            }

            return shellSettings;
        }
Ejemplo n.º 22
0
        public void Configure(IApplicationBuilder app)
        {
            ServiceProvider = app.ApplicationServices;

            var applicationEnvironment = app.ApplicationServices.GetRequiredService<IApplicationEnvironment>();
            var configurationFile = Path.Combine(applicationEnvironment.ApplicationBasePath, applicationEnvironment.ApplicationName) + ".json";

            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddJsonFile(configurationFile);

            Configuration = configurationBuilder.Build();

            ConfigureLogging(app);

            // Add site logging.
            app.Use(async (request, next) => {
                var accessLine = "<Unknown>";

                try {
                    var remoteAddress = "";
                    var connectionFeature = request.GetFeature<IHttpConnectionFeature>();

                    if (connectionFeature != null) {
                        remoteAddress = connectionFeature.RemoteIpAddress.ToString();
                    }

                    if (string.IsNullOrWhiteSpace(remoteAddress)) {
                        remoteAddress = request.Request.Headers["HTTP_X_FORWARDED_FOR"];
                    }

                    if (string.IsNullOrWhiteSpace(remoteAddress)) {
                        remoteAddress = request.Request.Headers["REMOTE_ADDR"];
                    }

                    accessLine = string.Format(
                        "{0} {1} {2} {3}{4}{5}",
                        remoteAddress,
                        request.Request.Method,
                        request.Request.Protocol,
                        request.Request.Path,
                        request.Request.QueryString.HasValue ? "?" : "",
                        request.Request.QueryString);

                    var isHtml = Path.GetExtension(request.Request.Path).Equals(".html");

                    if (isHtml) {
                        HtmlAccessLog.LogInformation(accessLine);
                    }

                    AccessLog.LogInformation(accessLine);

                    await next();
                } catch (Exception e) {
                    var message = string.Format("Exception processing request {0}", accessLine);
                    ApplicationLog.LogError(message, e);
                }
            });

            ConfigureFileServer(app);
        }
Ejemplo n.º 23
0
 private static IConfigurationBuilder CreateBuilder(IApplicationEnvironment appEnv)
 {
     IConfigurationBuilder configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
         .AddJsonFile("Config.json")
         .AddJsonFile("..\\Config.Bus.json");
     return configurationBuilder;
 }
Ejemplo n.º 24
0
 public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
 {
     // Setup configuration sources.
     var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
         .AddEnvironmentVariables();
     Configuration = builder.Build();
 }
Ejemplo n.º 25
0
        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            // Setup configuration sources.

            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            if (env.IsDevelopment())
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();

                // todo: use Configuration with config.json instead of hardcoded URLs
                AppSettings["WeatherApiDomain"] = "http://localhost:60583";
            }
            else
            {
                AppSettings["WeatherApiDomain"] = "http://nws-wapi-staging.azurewebsites.net:80";
            }

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
Ejemplo n.º 26
0
        public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            // Setup configuration sources.
            var builder = new ConfigurationBuilder()
                .SetBasePath(appEnv.ApplicationBasePath)
                .AddJsonFile("appsettings.json")
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            //appEnv.
            //env.EnvironmentName = "Development";

            if (env.IsEnvironment("Development"))
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();
            }

            // this file name is ignored by gitignore
            // so you can create it and use on your local dev machine
            // remember last config source added wins if it has the same settings
            builder.AddJsonFile("appsettings.local.overrides.json", optional: true);

            // most common use of environment variables would be in azure hosting
            // since it is added last anything in env vars would trump the same setting in previous config sources
            // so no risk of messing up settings if deploying a new version to azure
            builder.AddEnvironmentVariables();
            Configuration = builder.Build();

            //env.MapPath
        }
        public ActivityApiControllerTest()
        {
            if (_serviceProvider == null)
            {
                var services = new ServiceCollection();

                // Add Configuration to the Container
                var builder = new ConfigurationBuilder()
                    .SetBasePath(Directory.GetCurrentDirectory())
                    .AddEnvironmentVariables();
                IConfiguration configuration = builder.Build();
                services.AddSingleton(x => configuration);

                // Add EF (Full DB, not In-Memory)
                services.AddEntityFramework()
                    .AddInMemoryDatabase()
                    .AddDbContext<AllReadyContext>(options => options.UseInMemoryDatabase());

                // Setup hosting environment
                IHostingEnvironment hostingEnvironment = new HostingEnvironment();
                hostingEnvironment.EnvironmentName = "Development";
                services.AddSingleton(x => hostingEnvironment);
                _serviceProvider = services.BuildServiceProvider();
            }
        }
Ejemplo n.º 28
0
        public void Main(string[] args)
        {
            var runtimeConfig = new ConfigurationBuilder()
                .AddCommandLine(args)
                .Build();

            var options = new Options();
            runtimeConfig.Bind(options);

            var queueConfig = new ConfigurationBuilder(".")
                .AddJsonFile("queues.json")
                .Build()
                .GetSection(options.QueueType);

            var services = BuildServiceProvider(options, queueConfig);
            var logger = services.GetRequiredService<ILogger<Program>>();
            var handlerFactory = services.GetRequiredService<IMessageHandlerFactory>();
            var queueFactory = services.GetRequiredService<IMessageQueueFactory>();

            var queue = queueFactory.Get(options.ListenTo);
            queue.Listen(msg =>
            {
                var handler = handlerFactory.GetHandler(msg.Body.GetType());
                handler.Handle(msg, queue);
            });
        }
        /// <summary>
        ///     Start service.
        /// </summary>
        public void Start() {
            if (!File.Exists("config.json")) {
                Logger.Error("Configuration file \"config.json\" was not found in the application directory!");
                return;
            }

            // configuration
            var configurationBuilder = new ConfigurationBuilder().AddJsonFile("config.json").Build();
            var configuration = new Configuration.Configuration();
            configurationBuilder.Bind(configuration);

            // do the dirty work
            foreach (var mailBox in configuration.MailBoxes) {
                var cancellationTokenSource = Scheduler.Interval(mailBox.Interval, () => {
                    var mailBoxProcessor = new MailBoxProcessor(mailBox);

                    try {
                        mailBoxProcessor.Process();
                    }
                    catch (Exception ex) {
                        Logger.Error($"Could not process the MailBox {mailBox.Identifier}!", ex);
                    }
                });

                _cancellationTokenSources.Add(cancellationTokenSource);
            }
        }
        public Startup(IApplicationEnvironment appEnv)
        {
            var configBuilder = new Microsoft.Framework.Configuration.ConfigurationBuilder(appEnv.ApplicationBasePath)
                                .AddJsonFile("config.json");

            Configuration = configBuilder.Build();
            var connString = Configuration.Get("Data:DefaultConnection:ConnectionString");
        }
Ejemplo n.º 31
0
        private void UseBinder()
        {
            var builder = new ConfigurationBuilder();
            var current = Environment.CurrentDirectory;

            builder.AddXmlFile(current + "\\ConfigurationExperiments.exe.config");
            var configuration = builder.Build();

            //var converter2 = TypeDescriptor.GetConverter(typeof (Type));
            //var converter = new TypeNameConverter();
            //var d = typeof (double);
            TypeDescriptor.AddAttributes(typeof(Type), new TypeConverterAttribute(typeof(TypeNameConverter)));
            var converter = TypeDescriptor.GetConverter(typeof(Type));
            var a         = converter.ConvertFromInvariantString("System.Double");

            var model = new Configuration();

            configuration.Bind(model);
        }
Ejemplo n.º 32
-1
        /// <summary>
        /// The application entry point (main).
        /// </summary>
        public void Main()
        {
            // Get the connection string from config.json file
            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddJsonFile("config.json");
            var configuration = configurationBuilder.Build();
            var connectionString = configuration["Data:DefaultConnection:ConnectionString"];

            // Create an instance of a SQL Server DBContext
            var options = new DbContextOptionsBuilder();
            options.UseSqlServer(connectionString);
            var context = new MyDbContext(options.Options);
              context.Database.EnsureDeleted();
              context.Database.EnsureCreated();
            // Create a graph entity
            var parent = new Parent
            {
                Data = "Yanal",
                ChildA = new ChildA { Data = "1234" }
            };

            // Add the graph entity to context
            context.Parents.Add(parent, GraphBehavior.IncludeDependents);

            // Save change to the storage
            // Bug: ChildA is not going to be saved on the database on EF7.
            // On EF6 both ChildA gets stored in database when calling context.SaveChanges().
            context.SaveChanges();
        }