<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using WebHooks = Slack.Webhooks;

namespace Pelasoft.AspNet.Mvc.Slack
{
	/// <summary>
	/// Defines an action filter that logs thrown exceptions to a Slack channel.
	/// </summary>
	public class WebHookErrorReportFilter : IExceptionFilter, IWebHookErrorReporter
	{

		/// <summary>
		/// The slack web hook URL.
		/// </summary>
		public string WebhookUrl { get; set; }

		/// <summary>
		/// The slack channel name to which exception reports are posted.
		/// Optional; the web hook default channel will be used if not specified.
		/// </summary>
		public string ChannelName { get; set; }

		/// <summary>
		/// The username the error messages will post ask.
		/// Optional; the web hook default username will be used if not specified.
		/// </summary>
		public string UserName { get; set; }

		/// <summary>
		/// Whether or not to ignore already handled exceptions.
		/// If this is set true, the application/controller/method filter order will be significant.
		/// </summary>
		public bool IgnoreHandled { get; set; }

		/// <summary>
		/// The types of the exceptions to ignore. Use this to cut down on unecessary channel chatter.
		/// This list will be ignored if <see cref="ExceptionType"/> is specified.
		/// </summary>
		public Type[] IgnoreExceptionTypes { get; set; }

		/// <summary>
		/// The Emoji icon used for the posts.
		/// Default is :heavy_exclamation_mark:
		/// </summary>
		public string IconEmoji { get; set; }

		/// <summary>
		/// Creates a new instance of the exception filter for the specified <paramref name="webHookUrl"/>.
		/// </summary>
		/// <param name="exceptionType">The exception type to handle.</param>
		public WebHookErrorReportFilter(string webHookUrl)
		{
			WebhookUrl = webHookUrl;
		}

		public void OnException(ExceptionContext filterContext)
		{
			// auto eject if
			// ...ignoring handled exceptions
			if(IgnoreHandled && filterContext.ExceptionHandled) return;

			// ...the exception type is in the ignore list
			if(IgnoreExceptionTypes != null
				&& IgnoreExceptionTypes.Length > 0
				&& IgnoreExceptionTypes.Contains(filterContext.Exception.GetType()))
				return;

			var client = new WebHooks.SlackClient(WebhookUrl);
			var message = new WebHooks.SlackMessage();
			if(!string.IsNullOrEmpty(ChannelName))
			{
				message.Channel = ChannelName;
			}
			if(!string.IsNullOrEmpty(UserName))
			{
				message.Username = UserName;
			}

			message.IconEmoji = IconEmoji ?? WebHooks.Emoji.HeavyExclamationMark;

			message.Text = string.Format("A web application exception has occurred: {0}", filterContext.Exception.Message);

			client.Post(message);
		}


	}
}<commit_msg>Add more content to posted message.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using WebHooks = Slack.Webhooks;

namespace Pelasoft.AspNet.Mvc.Slack
{
	/// <summary>
	/// Defines an action filter that logs thrown exceptions to a Slack channel.
	/// </summary>
	public class WebHookErrorReportFilter : IExceptionFilter, IWebHookErrorReporter
	{

		/// <summary>
		/// The slack web hook URL.
		/// </summary>
		public string WebhookUrl { get; set; }

		/// <summary>
		/// The slack channel name to which exception reports are posted.
		/// Optional; the web hook default channel will be used if not specified.
		/// </summary>
		public string ChannelName { get; set; }

		/// <summary>
		/// The username the error messages will post ask.
		/// Optional; the web hook default username will be used if not specified.
		/// </summary>
		public string UserName { get; set; }

		/// <summary>
		/// Whether or not to ignore already handled exceptions.
		/// If this is set true, the application/controller/method filter order will be significant.
		/// </summary>
		public bool IgnoreHandled { get; set; }

		/// <summary>
		/// The types of the exceptions to ignore. Use this to cut down on unecessary channel chatter.
		/// This list will be ignored if <see cref="ExceptionType"/> is specified.
		/// </summary>
		public Type[] IgnoreExceptionTypes { get; set; }

		/// <summary>
		/// The Emoji icon used for the posts.
		/// Default is :heavy_exclamation_mark:
		/// </summary>
		public string IconEmoji { get; set; }

		/// <summary>
		/// Creates a new instance of the exception filter for the specified <paramref name="webHookUrl"/>.
		/// </summary>
		/// <param name="exceptionType">The exception type to handle.</param>
		public WebHookErrorReportFilter(string webHookUrl)
		{
			WebhookUrl = webHookUrl;
		}

		public void OnException(ExceptionContext filterContext)
		{
			// auto eject if
			// ...ignoring handled exceptions
			if(IgnoreHandled && filterContext.ExceptionHandled) return;

			// ...the exception type is in the ignore list
			if(IgnoreExceptionTypes != null
				&& IgnoreExceptionTypes.Length > 0
				&& IgnoreExceptionTypes.Contains(filterContext.Exception.GetType()))
				return;

			var client = new WebHooks.SlackClient(WebhookUrl);
			var message = new WebHooks.SlackMessage();
			if(!string.IsNullOrEmpty(ChannelName))
			{
				message.Channel = ChannelName;
			}
			if(!string.IsNullOrEmpty(UserName))
			{
				message.Username = UserName;
			}

			message.IconEmoji = IconEmoji ?? WebHooks.Emoji.HeavyExclamationMark;

			var ex = filterContext.Exception;
			message.Text = string.Format("A web application exception has occurred:\n   type: {0}\n   message: {1}\n   stack trace: {2}", ex.GetType(), ex.Message, ex.StackTrace);

			client.Post(message);
		}


	}
}
{'fraction_non_alphanumeric': 0.11938974631896399, 'fraction_numerical': 0.0010643959552953698, 'mean_word_length': 3.17320503330866, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, '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': '3432706', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1623, 'n_words': 534}