<commit_before>﻿using Bit.Model;
using Bit.Model.Events;
using Bit.ViewModel.Contracts;
using Microsoft.AspNet.SignalR.Client;
using Prism.Events;
using Prism.Services;
using System;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Essentials;

namespace Bit.ViewModel.Implementations
{
    public class SignalrMessageReceiver : Bindable, IMessageReceiver, IDisposable
    {
        public virtual SignalRHttpClient SignalRHttpClient { get; set; }

        public virtual IEventAggregator EventAggregator { get; set; }

        public virtual IDeviceService DeviceService { get; set; }

        public virtual bool IsConnected { get; set; }

        public virtual IClientAppProfile ClientAppProfile { get; set; }

        /// <summary>
        /// <see cref="IMessageReceiver.ShouldBeConnected"/>
        /// </summary>
        public virtual bool ShouldBeConnected { get; set; }

        HubConnection _hubConnection;
        IDisposable _listener;
        bool _continueWork = true;
        DefaultServerSentEventsTransport _serverSentEventsTransport;

        public virtual async Task Start(CancellationToken cancellationToken)
        {
            ShouldBeConnected = true;

            if (_hubConnection == null)
            {
                _hubConnection = new HubConnection($"{ClientAppProfile.HostUri}{ClientAppProfile.SignalrEndpint}")
                {
                    TransportConnectTimeout = TimeSpan.FromSeconds(3)
                };

                IHubProxy hubProxy = _hubConnection.CreateHubProxy("MessagesHub");

                _listener = hubProxy.On<string, string>("OnMessageReceived", (key, dataAsJson) =>
                {
                    MessageReceivedEvent @event = new MessageReceivedEvent
                    {
                        Key = key,
                        Body = dataAsJson
                    };

                    EventAggregator.GetEvent<MessageReceivedEvent>().Publish(@event);
                });

                _hubConnection.ConnectionSlow += OnConnectionSlow;
                _hubConnection.Reconnected += OnReconnected;
                _hubConnection.Closed += OnClosed;
                _hubConnection.Reconnected += OnReconnected;
                _hubConnection.Reconnecting += OnReconnecting;
                _hubConnection.StateChanged += OnStateChanged;

                DeviceService.StartTimer(TimeSpan.FromSeconds(5), OnSchedule);

                Connectivity.ConnectivityChanged += OnConnectivityChanged;
            }
<commit_msg>Removed extra code from signalr message receiver of cs client<commit_after>﻿using Bit.Model;
using Bit.Model.Events;
using Bit.ViewModel.Contracts;
using Microsoft.AspNet.SignalR.Client;
using Prism.Events;
using Prism.Services;
using System;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Essentials;

namespace Bit.ViewModel.Implementations
{
    public class SignalrMessageReceiver : Bindable, IMessageReceiver, IDisposable
    {
        public virtual SignalRHttpClient SignalRHttpClient { get; set; }

        public virtual IEventAggregator EventAggregator { get; set; }

        public virtual IDeviceService DeviceService { get; set; }

        public virtual bool IsConnected { get; set; }

        public virtual IClientAppProfile ClientAppProfile { get; set; }

        /// <summary>
        /// <see cref="IMessageReceiver.ShouldBeConnected"/>
        /// </summary>
        public virtual bool ShouldBeConnected { get; set; }

        HubConnection _hubConnection;
        IDisposable _listener;
        bool _continueWork = true;
        DefaultServerSentEventsTransport _serverSentEventsTransport;

        public virtual async Task Start(CancellationToken cancellationToken)
        {
            ShouldBeConnected = true;

            if (_hubConnection == null)
            {
                _hubConnection = new HubConnection($"{ClientAppProfile.HostUri}{ClientAppProfile.SignalrEndpint}")
                {
                    TransportConnectTimeout = TimeSpan.FromSeconds(3)
                };

                IHubProxy hubProxy = _hubConnection.CreateHubProxy("MessagesHub");

                _listener = hubProxy.On<string, string>("OnMessageReceived", (key, dataAsJson) =>
                {
                    MessageReceivedEvent @event = new MessageReceivedEvent
                    {
                        Key = key,
                        Body = dataAsJson
                    };

                    EventAggregator.GetEvent<MessageReceivedEvent>().Publish(@event);
                });

                _hubConnection.ConnectionSlow += OnConnectionSlow;
                _hubConnection.Reconnected += OnReconnected;
                _hubConnection.Closed += OnClosed;
                _hubConnection.Reconnecting += OnReconnecting;
                _hubConnection.StateChanged += OnStateChanged;

                DeviceService.StartTimer(TimeSpan.FromSeconds(5), OnSchedule);

                Connectivity.ConnectivityChanged += OnConnectivityChanged;
            }

{'fraction_non_alphanumeric': 0.07605466428995841, 'fraction_numerical': 0.0007922360863537334, 'mean_word_length': 2.200253485424588, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '1224665', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1180, 'n_words': 259}