<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.ApplicationInsights;
using System.Security.Claims;
using TeamStore.Factories;
using TeamStore.ViewModels;
using TeamStore.Keeper.Interfaces;

namespace TeamStore.Controllers
{
    [Authorize]
    public class HomeController : Controller
    {
        private IProjectsService _projectsService { get; set; }

        private readonly IAssetService _assetService;

        public HomeController(IProjectsService projectsService, IAssetService assetService)
        {
            _projectsService = projectsService ?? throw new ArgumentNullException(nameof(projectsService));
            _assetService = assetService ?? throw new ArgumentNullException(nameof(assetService));
        }

        public async Task<IActionResult> Index()
        {
            var homeViewModel = new HomeViewModel();

            // CR 12/12/2017 This ViewModel returns a database Project. 
            // It should go through a factory for mapping purposes 
            homeViewModel.Projects = await _projectsService.GetProjects();

            return View(homeViewModel);
        }

        [HttpGet]
        public async Task<IActionResult> GetAssetResults(string searchToken)
        {
            if (String.IsNullOrEmpty(searchToken))
            {
                return BadRequest();
            }

            string accessIpAddress = HttpContext?.Connection?.RemoteIpAddress?.ToString();
            if (string.IsNullOrWhiteSpace(accessIpAddress)) return BadRequest();

            try
            {
                var assets = await _assetService.GetAssetResultsAsync(searchToken);
                return new OkObjectResult(AssetFactory.ConvertAssetSearch(assets));
            }
            catch (Exception ex)
            {
                // LOG through SERVICE TODO
                var t = new TelemetryClient();
                t.TrackException(ex);
                return BadRequest();<commit_msg>HomeController cleanup<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.ApplicationInsights;
using System.Security.Claims;
using TeamStore.Factories;
using TeamStore.ViewModels;
using TeamStore.Keeper.Interfaces;

namespace TeamStore.Controllers
{
    [Authorize]
    public class HomeController : Controller
    {
        private readonly IProjectsService _projectsService;
        private readonly IAssetService _assetService;

        public HomeController(IProjectsService projectsService, IAssetService assetService)
        {
            _projectsService = projectsService ?? throw new ArgumentNullException(nameof(projectsService));
            _assetService = assetService ?? throw new ArgumentNullException(nameof(assetService));
        }

        [HttpGet]
        public async Task<IActionResult> Index()
        {
            var homeViewModel = new HomeViewModel();

            // CR 12/12/2017 This ViewModel returns a database Project. 
            // It should go through a factory for mapping purposes 
            homeViewModel.Projects = await _projectsService.GetProjects();

            return View(homeViewModel);
        }

        [HttpGet]
        public async Task<IActionResult> GetAssetResults(string searchToken)
        {
            if (String.IsNullOrWhiteSpace(searchToken))
            {
                return BadRequest();
            }

            string accessIpAddress = HttpContext?.Connection?.RemoteIpAddress?.ToString();
            if (string.IsNullOrWhiteSpace(accessIpAddress))
            {
                return BadRequest();
            }

            try
            {
                var assets = await _assetService.GetAssetResultsAsync(searchToken);
                return new OkObjectResult(AssetFactory.ConvertAssetSearch(assets));
            }
            catch (Exception ex)
            {
                // LOG through SERVICE TODO
                var t = new TelemetryClient();
                t.TrackException(ex);
                return BadRequest();
{'fraction_non_alphanumeric': 0.07200740912248206, 'fraction_numerical': 0.0037045612410280156, 'mean_word_length': 2.382928739232576, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4733542', 'n_tokens_mistral': 1028, 'n_tokens_neox': 995, 'n_words': 248}