<commit_before>﻿// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

using Microsoft.AspNet;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.ConfigurationModel;
using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.DependencyInjection.Fallback;
using Microsoft.AspNet.DependencyInjection.NestedProviders;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.InMemory;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using MusicStore.Models;
using MusicStore.Web.Models;
using System;
using System.Collections.Generic;

public class Startup
{
    public void Configuration(IBuilder app)
    {
        CreateAdminUser();

        app.UseErrorPage(ErrorPageOptions.ShowAll);

        app.UseFileServer();

        var serviceProvider = MvcServices.GetDefaultServices().BuildServiceProvider(app.ServiceProvider);

        var routes = new RouteCollection()
        {
            DefaultHandler = new MvcApplication(serviceProvider),
        };

        routes.MapRoute(
            "{controller}/{action}",
            new { controller = "Home", action = "Index" });

        routes.MapRoute(
            "{controller}",
            new { controller = "Home" });

        app.UseRouter(routes);

        SampleData.InitializeMusicStoreDatabase();
    }

    //Bug: We need EF to integrate with SQL server. Until then we will use in memory store
    //private async void CreateAdminUser()
    //{
    //    string _username = ConfigurationManager.AppSettings["DefaultAdminUsername"];
    //    string _password = ConfigurationManager.AppSettings["DefaultAdminPassword"];
    //    string _role = "Administrator";

    //    var context = new ApplicationDbContext();
    //    var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
    //    var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));

    //    var role = new IdentityRole(_role);
    //    var result = await roleManager.RoleExistsAsync(_role);
    //    if (result == false)
    //    {
    //        await roleManager.CreateAsync(role);
    //    }

    //    var user = await userManager.FindByNameAsync(_username);
    //    if (user == null)
    //    {
    //        user = new ApplicationUser { UserName = _username };
    //        await userManager.CreateAsync(user, _password);
    //        await userManager.AddToRoleAsync(user.Id, _role);
    //    }
    //}

    private async void CreateAdminUser()
    {
        //How to read from local appSettings? 
        var configuration = new Configuration();
        string _username = "Administrator"; // configuration.Get("DefaultAdminUsername");
        string _password = "<PASSWORD>"; // configuration.Get("DefaultAdminPassword");
        string _role = "Administrator";

        var userManager = new UserManager<ApplicationUser, string>(new InMemoryUserStore<ApplicationUser>());
        var roleManager = new RoleManager<InMemoryRole>(new InMemoryRoleStore<InMemoryRole>());

        var role = new InMemoryRole(_role);
        var result = await roleManager.RoleExists(_role);
        if (result == false)
        {
            await roleManager.Create(role);
        }

        var user = await userManager.FindByName(_username);
        if (user == null)
        {
            user = new ApplicationUser { UserName = _username };
            await userManager.Create(user, _password);
            await userManager.AddToRole(user.Id, _role);
        }
    }
}<commit_msg>Fix build issues in Startup.cs<commit_after>﻿// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

using Microsoft.AspNet;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.ConfigurationModel;
using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.DependencyInjection.Fallback;
using Microsoft.AspNet.DependencyInjection.NestedProviders;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.InMemory;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using MusicStore.Models;
using MusicStore.Web.Models;
using System;
using System.Collections.Generic;

public class Startup
{
    public void Configuration(IBuilder app)
    {
        CreateAdminUser();

        app.UseErrorPage(ErrorPageOptions.ShowAll);

        app.UseFileServer();

        var serviceProvider = MvcServices.GetDefaultServices().BuildServiceProvider(app.ServiceProvider);

        var routes = new RouteCollection()
        {
            DefaultHandler = new MvcApplication(serviceProvider),
        };

        routes.MapRoute(
            "{controller}/{action}",
            new { controller = "Home", action = "Index" });

        routes.MapRoute(
            "{controller}",
            new { controller = "Home" });

        app.UseRouter(routes);

        SampleData.InitializeMusicStoreDatabase();
    }

    //Bug: We need EF to integrate with SQL server. Until then we will use in memory store
    //private async void CreateAdminUser()
    //{
    //    string _username = ConfigurationManager.AppSettings["DefaultAdminUsername"];
    //    string _password = ConfigurationManager.AppSettings["DefaultAdminPassword"];
    //    string _role = "Administrator";

    //    var context = new ApplicationDbContext();
    //    var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
    //    var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));

    //    var role = new IdentityRole(_role);
    //    var result = await roleManager.RoleExistsAsync(_role);
    //    if (result == false)
    //    {
    //        await roleManager.CreateAsync(role);
    //    }

    //    var user = await userManager.FindByNameAsync(_username);
    //    if (user == null)
    //    {
    //        user = new ApplicationUser { UserName = _username };
    //        await userManager.CreateAsync(user, _password);
    //        await userManager.AddToRoleAsync(user.Id, _role);
    //    }
    //}

    private async void CreateAdminUser()
    {
        //How to read from local appSettings? 
        var configuration = new Configuration();
        string _username = "Administrator"; // configuration.Get("DefaultAdminUsername");
        string _password = "<PASSWORD>"; // configuration.Get("DefaultAdminPassword");
        string _role = "Administrator";

        var userManager = new UserManager<ApplicationUser>(new InMemoryUserStore<ApplicationUser>());
        var roleManager = new RoleManager<InMemoryRole>(new InMemoryRoleStore<InMemoryRole>());

        var role = new InMemoryRole(_role);
        var result = await roleManager.RoleExistsAsync(_role);
        if (result == false)
        {
            await roleManager.CreateAsync(role);
        }

        var user = await userManager.FindByNameAsync(_username);
        if (user == null)
        {
            user = new ApplicationUser { UserName = _username };
            await userManager.CreateAsync(user, _password);
            await userManager.AddToRoleAsync(user.Id, _role);
        }
    }
}
{'fraction_non_alphanumeric': 0.10547945205479452, 'fraction_numerical': 0.0, 'mean_word_length': 2.83254593175853, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '88214', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1871, 'n_words': 453}