<commit_before>﻿#region Copyright
// // -----------------------------------------------------------------------
// // <copyright company="cdmdotnet Limited">
// // 	Copyright cdmdotnet Limited. All rights reserved.
// // </copyright>
// // -----------------------------------------------------------------------
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using cdmdotnet.Logging;
using Cqrs.Events;
using Microsoft.AspNet.SignalR;

namespace Cqrs.WebApi.SignalR.Hubs
{
	public class NotificationHub
		: Hub
		, INotificationHub
	{
		public NotificationHub(ILogger logger, ICorrelationIdHelper correlationIdHelper)
		{
			Logger = logger;
			CorrelationIdHelper = correlationIdHelper;
		}

		public NotificationHub()
		{
		}

		public ILogger Logger { get; set; }

		public ICorrelationIdHelper CorrelationIdHelper { get; set; }

		public Func<string, Guid> ConvertUserTokenToUserRsn { get; set; }

		#region Overrides of HubBase

		/// <summary>
		/// When the connection connects to this hub instance we register the connection so we can respond back to it.
		/// </summary>
		public override Task OnConnected()
		{
			return Join();
		}

		/// <summary>
		/// When the connection reconnects to this hub instance we register the connection so we can respond back to it.
		/// </summary>
		public override Task OnReconnected()
		{
			return Join();
		}

		#endregion

		protected virtual string UserToken()
		{
			string userRsn = Context.RequestCookies["X-Token"].Value;

			return userRsn.Replace(".", string.Empty);
		}

		protected virtual Task Join()
		{
			string userToken = UserToken();<commit_msg>Added support for query string token usage.<commit_after>﻿#region Copyright
// // -----------------------------------------------------------------------
// // <copyright company="cdmdotnet Limited">
// // 	Copyright cdmdotnet Limited. All rights reserved.
// // </copyright>
// // -----------------------------------------------------------------------
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using cdmdotnet.Logging;
using Cqrs.Events;
using Microsoft.AspNet.SignalR;

namespace Cqrs.WebApi.SignalR.Hubs
{
	public class NotificationHub
		: Hub
		, INotificationHub
	{
		public NotificationHub(ILogger logger, ICorrelationIdHelper correlationIdHelper)
		{
			Logger = logger;
			CorrelationIdHelper = correlationIdHelper;
		}

		public NotificationHub()
		{
		}

		public ILogger Logger { get; set; }

		public ICorrelationIdHelper CorrelationIdHelper { get; set; }

		public Func<string, Guid> ConvertUserTokenToUserRsn { get; set; }

		#region Overrides of HubBase

		/// <summary>
		/// When the connection connects to this hub instance we register the connection so we can respond back to it.
		/// </summary>
		public override Task OnConnected()
		{
			return Join();
		}

		/// <summary>
		/// When the connection reconnects to this hub instance we register the connection so we can respond back to it.
		/// </summary>
		public override Task OnReconnected()
		{
			return Join();
		}

		#endregion

		protected virtual string UserToken()
		{
			string userRsn;
			Cookie cookie;
			if (Context.RequestCookies.TryGetValue("X-Token", out cookie))
				userRsn = cookie.Value;
			else
				userRsn = Context.QueryString["X-Token"];

			return userRsn.Replace(".", string.Empty);
		}

		protected virtual Task Join()
		{
			string userToken = UserToken();
{'fraction_non_alphanumeric': 0.17681895093062605, 'fraction_numerical': 0.0, 'mean_word_length': 2.522343594836147, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '5039670', 'n_tokens_mistral': 1089, 'n_tokens_neox': 970, 'n_words': 293}