Exemplo n.º 1
0
        // Provides a test fixture for a real SFCC environment using local configuration
        public SFCCEnvironmentFixture()
        {
            var            services      = new ServiceCollection();
            var            dir           = Directory.GetCurrentDirectory();
            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile("testdata/appsettings.json", optional: true, reloadOnChange: false)
                                           .AddDWJsonConfiguration(Path.Combine(Directory.GetCurrentDirectory(), "testdata/dw.json"))
                                           .AddEnvironmentVariables()
                                           .Build();

            services.AddLogging(logging =>
            {
                logging.SetMinimumLevel(LogLevel.Debug);
                logging.AddConsole(options =>
                {
                    options.DisableColors = true;
                    options.IncludeScopes = true;
                });
            });

            services.Configure <SFCCEnvironment>(configuration);

            services.AddAccountManagerClients();
            services.AddSingleton <IWebDAVClient, SFCCWebDAVClient>();

            services.AddOCAPIRestClients();

            ServiceProvider = services.BuildServiceProvider();
        }
Exemplo n.º 2
0
        private static ServiceProvider ConfigureServices()
        {
            string homedir;

            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                homedir = Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
            }
            else
            {
                homedir = Environment.GetEnvironmentVariable("HOME");
            }

            // These optional CLI params are necessary for service configuration
            var project     = _optionProject.Value();
            var environment = _optionEnvironment.Value();

            var services             = new ServiceCollection();
            var configurationBuilder = new ConfigurationBuilder()
                                       .AddSecretsConfiguration()
                                       .AddDWREJsonConfiguration(Path.Combine(homedir, ".dwre.json"), project, environment);

            if (project == null && environment == null)
            {
                // only include dw.json if specific project/env is not given
                configurationBuilder.AddDWJsonConfiguration(Path.Combine(Directory.GetCurrentDirectory(), "dw.json"));
            }

            var configuration = configurationBuilder.AddJsonFile(
                Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"),
                optional: true, reloadOnChange: true)
                                .AddEnvironmentVariables("SFCC_")
                                .AddCLIConfiguration(_app)
                                .Build();

            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .MinimumLevel.Is(_optionLogLevel.HasValue() ? _optionLogLevel.ParsedValue : LogEventLevel.Warning)
                         .ReadFrom.Configuration(configuration)
                         //{SourceContext:l} if we want context
                         .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
                         .CreateLogger();

            services.AddLogging(logging => { logging.AddSerilog(); });

            services.AddSingleton <IConsoleOutput, ColorConsole>();

            services.Configure <SFCCEnvironment>(configuration);

            services.AddAccountManagerClients();
            services.AddSingleton <IWebDAVClient, SFCCWebDAVClient>();
            services.AddOCAPIRestClients();

            // Command Implementations
            services.AddSingleton <TailCommand>();
            services.AddSingleton <WebDAVCommand>();
            services.AddSingleton <SyncCommand>();
            services.AddSingleton <WatchCommand>();

            return(services.BuildServiceProvider());
        }