<commit_before>﻿using System;
using System.Threading.Tasks;

using Microsoft.AspNet.SignalR.Client;

using Newtonsoft.Json;

using Parser.LogFileReader.Contracts;

namespace Parser.SignalRUtilizationStrategy
{
    public class SignalRCommandUtilizationStrategy : ICommandUtilizationStrategy
    {
        private readonly IHubProxy logFileParserHubProxy;
        private string assignedId;

        public SignalRCommandUtilizationStrategy()
        {
            this.logFileParserHubProxy = this.CreateProxy("http://localhost:52589").Result;
        }

        public void UtilizeCommand(ICommand command)
        {
            var serializedCommand = JsonConvert.SerializeObject(command);

            this.logFileParserHubProxy.Invoke("SendCommand", this.assignedId, serializedCommand);
        }

        private async Task<IHubProxy> CreateProxy(string url)
        {
            var connection = new HubConnection(url);
            //connection.TraceWriter = Console.Out;

            var logFileParserHubProxy = connection.CreateHubProxy("LogFileParserHub");

            logFileParserHubProxy.On<string>("ReceiveStatus", (status) =>
            {
                Console.WriteLine(status);
            });

            logFileParserHubProxy.On<string>("UpdateUserId", this.OnUpdateUserId);

            await connection.Start();
            await logFileParserHubProxy.Invoke("GetUserId");

            return logFileParserHubProxy;
        }

        private void OnUpdateUserId(string userId)<commit_msg>added IJsonConvertProvider param to SignalRCommandUtilizationStrategy ctor<commit_after>﻿using System;
using System.Threading.Tasks;

using Microsoft.AspNet.SignalR.Client;

using Bytes2you.Validation;

using Newtonsoft.Json;

using Parser.LogFileReader.Contracts;
using Parser.SignalRUtilizationStrategy.Contracts;

namespace Parser.SignalRUtilizationStrategy
{
    public class SignalRCommandUtilizationStrategy : ICommandUtilizationStrategy
    {
        private readonly IJsonConvertProvider jsonConvertProvider;

        private readonly IHubProxy logFileParserHubProxy;
        private string assignedId;

        public SignalRCommandUtilizationStrategy(IJsonConvertProvider jsonConvertProvider)
        {
            Guard.WhenArgument(jsonConvertProvider, nameof(IJsonConvertProvider)).IsNull().Throw();

            this.jsonConvertProvider = jsonConvertProvider;

            this.logFileParserHubProxy = this.CreateProxy("http://localhost:52589").Result;
        }

        public void UtilizeCommand(ICommand command)
        {
            var serializedCommand = this.jsonConvertProvider.SerializeObject(command);

            this.logFileParserHubProxy.Invoke("SendCommand", this.assignedId, serializedCommand);
        }

        private async Task<IHubProxy> CreateProxy(string url)
        {
            var connection = new HubConnection(url);
            //connection.TraceWriter = Console.Out;

            var logFileParserHubProxy = connection.CreateHubProxy("LogFileParserHub");

            logFileParserHubProxy.On<string>("ReceiveStatus", (status) =>
            {
                Console.WriteLine(status);
            });

            logFileParserHubProxy.On<string>("UpdateUserId", this.OnUpdateUserId);

            await connection.Start();
            await logFileParserHubProxy.Invoke("GetUserId");

            return logFileParserHubProxy;
        }

        private void OnUpdateUserId(string userId)
{'fraction_non_alphanumeric': 0.07845975680370584, 'fraction_numerical': 0.0031847133757961785, 'mean_word_length': 2.989607390300231, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4048146', 'n_tokens_mistral': 857, 'n_tokens_neox': 844, 'n_words': 149}