<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Fortune_Teller_Service.Common.Services;
using Pivotal.Extensions.Configuration;
using Pivotal.Discovery.Client;
using Steeltoe.CloudFoundry.Connector.Redis;
using Steeltoe.Security.DataProtection;
using Microsoft.AspNetCore.DataProtection;

namespace Fortune_Teller_UI
{
    public class Startup
    {
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                // Lab07 Start
                .AddConfigServer(env)
                // Lab07 End
                .AddEnvironmentVariables();
            Configuration = builder.Build();
            Environment = env;
        }

        public IConfigurationRoot Configuration { get; }
        public IHostingEnvironment Environment { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {

            // Lab09 Start
            if (Environment.IsProduction())
            {
                // Use Redis cache on CloudFoundry to DataProtection Keys
                services.AddRedisConnectionMultiplexer(Configuration);
                services.AddDataProtection()
                    .PersistKeysToRedis()
                    .SetApplicationName("fortuneui");
            } else
            {
                services.AddDistributedMemoryCache();
            }
            // Lab09 End
       
            // Lab06 Start
            services.AddSingleton<IFortuneService, FortuneServiceClient>();
            // Lab06 End

            // Lab07 Start
            services.Configure<FortuneServiceConfig>(Configuration.GetSection("fortuneService"));
            // Lab07 End

            // Lab08 Start
            services.AddDiscoveryClient(Configuration);
            // Lab08 End

            // Add framework services.

            // Lab09 Start<commit_msg>Fix lab09 startup code<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Fortune_Teller_Service.Common.Services;
using Pivotal.Extensions.Configuration;
using Pivotal.Discovery.Client;
using Steeltoe.CloudFoundry.Connector.Redis;
using Steeltoe.Security.DataProtection;
using Microsoft.AspNetCore.DataProtection;

namespace Fortune_Teller_UI
{
    public class Startup
    {
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                // Lab07 Start
                .AddConfigServer(env)
                // Lab07 End
                .AddEnvironmentVariables();
            Configuration = builder.Build();
            Environment = env;
        }

        public IConfigurationRoot Configuration { get; }
        public IHostingEnvironment Environment { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {

            // Lab09 Start
            if (!Environment.IsDevelopment())
            {
                // Use Redis cache on CloudFoundry to DataProtection Keys
                services.AddRedisConnectionMultiplexer(Configuration);
                services.AddDataProtection()
                    .PersistKeysToRedis()
                    .SetApplicationName("fortuneui");
            } 
            // Lab09 End
       
            // Lab06 Start
            services.AddSingleton<IFortuneService, FortuneServiceClient>();
            // Lab06 End

            // Lab07 Start
            services.Configure<FortuneServiceConfig>(Configuration.GetSection("fortuneService"));
            // Lab07 End

            // Lab08 Start
            services.AddDiscoveryClient(Configuration);
            // Lab08 End

            // Add framework services.

            // Lab09 Start
{'fraction_non_alphanumeric': 0.07692307692307693, 'fraction_numerical': 0.009537632179141614, 'mean_word_length': 2.112258064516129, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '815530', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1123, 'n_words': 260}