<commit_before>﻿using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.OptionsModel;
using Microsoft.Extensions.DependencyInjection;

namespace Mindscape.Raygun4Net.AspNet5
{
  public interface IRaygunSettingsProvider
  {
    RaygunSettings GetRaygunSettings(RaygunSettings baseSettings);
  }

  public class RaygunSettingsProvider : IRaygunSettingsProvider
  {
    private readonly Func<RaygunSettings, RaygunSettings> _customConfig;

    public RaygunSettingsProvider(Func<RaygunSettings, RaygunSettings> customConfig)
    {
      this._customConfig = customConfig;
    }


    public RaygunSettings GetRaygunSettings(RaygunSettings baseSettings)
    {
      if(_customConfig != null)
      {
        return _customConfig(baseSettings);
      }
      return baseSettings;
    }
  }

  public class RaygunAspNetMiddleware
  {
    private readonly RequestDelegate _next;
    private readonly RaygunSettings _settings;

    public RaygunAspNetMiddleware(RequestDelegate next, IOptions<RaygunSettings> settings, IRaygunSettingsProvider customConfig)
    {
      _next = next;

      if(customConfig != null)
      {
        _settings = customConfig.GetRaygunSettings(settings.Value ?? new RaygunSettings());  
      }
      else
      {
        _settings = settings.Value ?? new RaygunSettings();
      }
    }
    public async Task Invoke(HttpContext httpContext)
    {
      try
      {
        await _next.Invoke(httpContext);
      }
      catch(Exception e)
      {
        var client = new RaygunAspNet5Client(_settings);
        await client.SendInBackground(e);
      }
    }
  }

  public static class IApplicationBuilderExtensions
  {
    public static IApplicationBuilder UseRaygun(this IApplicationBuilder app)
    {<commit_msg>Set the current HTTP Context on errors in the middleware<commit_after>﻿using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.OptionsModel;
using Microsoft.Extensions.DependencyInjection;

namespace Mindscape.Raygun4Net.AspNet5
{
  public interface IRaygunSettingsProvider
  {
    RaygunSettings GetRaygunSettings(RaygunSettings baseSettings);
  }

  public class RaygunSettingsProvider : IRaygunSettingsProvider
  {
    private readonly Func<RaygunSettings, RaygunSettings> _customConfig;

    public RaygunSettingsProvider(Func<RaygunSettings, RaygunSettings> customConfig)
    {
      this._customConfig = customConfig;
    }


    public RaygunSettings GetRaygunSettings(RaygunSettings baseSettings)
    {
      if(_customConfig != null)
      {
        return _customConfig(baseSettings);
      }
      return baseSettings;
    }
  }

  public class RaygunAspNetMiddleware
  {
    private readonly RequestDelegate _next;
    private readonly RaygunSettings _settings;

    public RaygunAspNetMiddleware(RequestDelegate next, IOptions<RaygunSettings> settings, IRaygunSettingsProvider customConfig)
    {
      _next = next;

      if(customConfig != null)
      {
        _settings = customConfig.GetRaygunSettings(settings.Value ?? new RaygunSettings());  
      }
      else
      {
        _settings = settings.Value ?? new RaygunSettings();
      }
    }
    public async Task Invoke(HttpContext httpContext)
    {
      try
      {
        await _next.Invoke(httpContext);
      }
      catch(Exception e)
      {
        var client = new RaygunAspNet5Client(_settings);
        client.RaygunCurrentRequest(httpContext);
        await client.SendInBackground(e);
        throw;
      }
    }
  }

  public static class IApplicationBuilderExtensions
  {
    public static IApplicationBuilder UseRaygun(this IApplicationBuilder app)
    {
{'fraction_non_alphanumeric': 0.06776556776556776, 'fraction_numerical': 0.0015698587127158557, 'mean_word_length': 3.3892078071182548, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3829799', 'n_tokens_mistral': 1011, 'n_tokens_neox': 1016, 'n_words': 219}