<commit_before>﻿using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Routing;
using System.IO;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using Microsoft.AspNet.Http;

namespace JsonRpc.Router
{
	internal class RpcRouter : IRouter
	{
		private RpcRouterConfiguration Configuration { get; }
		public RpcRouter(RpcRouterConfiguration configuration)
		{
			if (configuration == null)
			{
				throw new ArgumentNullException(nameof(configuration));
			}
			this.Configuration = configuration;
		}

		public VirtualPathData GetVirtualPath(VirtualPathContext context)
		{
			// We return null here because we're not responsible for generating the url, the route is.
			return null;
		}

		public async Task RouteAsync(RouteContext context)
		{
			string section;
			if (!this.IsCorrectRoute(context, out section))
			{
				return;
			}
			RpcRequest request;
			bool isRpc = this.TryGetRpcRequest(context, out request);
			if (!isRpc)
			{
				return;
			}

			// Replacing the route data allows any code running here to dirty the route values or data-tokens
			// without affecting something upstream.
			RouteData oldRouteData = context.RouteData;
			RouteData newRouteData = new RouteData(oldRouteData);

			try
			{
				context.RouteData = newRouteData;

				await InvokeRequest(context, request, section);
				context.IsHandled = true;
			}
			finally
			{
				if (!context.IsHandled)
				{
					context.RouteData = oldRouteData;
				}
			}
		}

		private bool TryGetRpcRequest(RouteContext context, out RpcRequest rpcRequest)
		{
			rpcRequest = null;

			Stream contentStream = context.HttpContext.Request.Body;

			if (contentStream == null)
			{
				return false;
			}
			using (StreamReader streamReader = new StreamReader(contentStream))
			{
				string jsonString = streamReader.ReadToEnd();
				if (string.IsNullOrWhiteSpace(jsonString))
				{
					return false;
				}
				try
				{
					rpcRequest = JsonConvert.DeserializeObject<RpcRequest>(jsonString);
					if (rpcRequest == null)
					{
						return false;
					}
				}
				catch (Exception)
				{
					return false;<commit_msg>Removing unused code from MVC<commit_after>﻿using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Routing;
using System.IO;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using Microsoft.AspNet.Http;

namespace JsonRpc.Router
{
	internal class RpcRouter : IRouter
	{
		private RpcRouterConfiguration Configuration { get; }
		public RpcRouter(RpcRouterConfiguration configuration)
		{
			if (configuration == null)
			{
				throw new ArgumentNullException(nameof(configuration));
			}
			this.Configuration = configuration;
		}

		public VirtualPathData GetVirtualPath(VirtualPathContext context)
		{
			// We return null here because we're not responsible for generating the url, the route is.
			return null;
		}

		public async Task RouteAsync(RouteContext context)
		{
			string section;
			if (!this.IsCorrectRoute(context, out section))
			{
				return;
			}
			RpcRequest request;
			bool isRpc = this.TryGetRpcRequest(context, out request);
			if (!isRpc)
			{
				return;
			}

			await InvokeRequest(context, request, section);
			context.IsHandled = true;
		}

		private bool TryGetRpcRequest(RouteContext context, out RpcRequest rpcRequest)
		{
			rpcRequest = null;

			Stream contentStream = context.HttpContext.Request.Body;

			if (contentStream == null)
			{
				return false;
			}
			using (StreamReader streamReader = new StreamReader(contentStream))
			{
				string jsonString = streamReader.ReadToEnd();
				if (string.IsNullOrWhiteSpace(jsonString))
				{
					return false;
				}
				try
				{
					rpcRequest = JsonConvert.DeserializeObject<RpcRequest>(jsonString);
					if (rpcRequest == null)
					{
						return false;
					}
				}
				catch (Exception)
				{
					return false;
{'fraction_non_alphanumeric': 0.085155058464667, 'fraction_numerical': 0.0, 'mean_word_length': 3.4163860830527497, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3844650', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1148, 'n_words': 296}