<commit_before>﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using JabbR.Client.Models;
using SignalR.Client.Hubs;

namespace JabbR.Client
{
    public class JabbRClient
    {
        private readonly IHubProxy _chat;
        private readonly HubConnection _connection;
        private readonly string _url;
        private int _initialized;

        public JabbRClient(string url)
        {
            _url = url;
            _connection = new HubConnection(url);
            _chat = _connection.CreateProxy("JabbR.Chat");
        }

        public event Action<Message, string> MessageReceived;
        public event Action<IEnumerable<string>> LoggedOut;
        public event Action<User, string> UserJoined;
        public event Action<User, string> UserLeft;
        public event Action<string> Kicked;
        public event Action<string, string, string> PrivateMessage;
        public event Action<User, string> UserTyping;

        // Global
        public event Action<string, int> RoomCountChanged;
        public event Action<User> UserActivityChanged;
        public event Action<IEnumerable<User>> UsersInactive;

        public ICredentials Credentials
        {
            get
            {
                return _connection.Credentials;
            }
            set
            {
                _connection.Credentials = value;
            }
        }

        public event Action Disconnected
        {
            add
            {
                _connection.Closed += value;
            }
            remove
            {
                _connection.Closed -= value;
            }
        }

        public Task<LogOnInfo> Connect(string userId)
        {
            _chat["id"] = userId;

            return DoConnect(() => _connection.Start()
                                              .Then(() => _chat.Invoke<bool>("Join"))
                                              .FastUnwrap());
        }

        public Task<LogOnInfo> Connect(string name, string password)
        {
            return DoConnect(() => _connection.Start()
                                              .Then(() =>
                                              {
                                                  return _chat.Invoke<bool>("Join").Then(success =>
                                                  {
                                                      if (!success)
                                                      {
                                                          return SendCommand("nick {0} {1}", name, password);
                                                      }
                                                      return TaskAsyncHelper.Empty;
                                                  }).FastUnwrap();

                                              }).FastUnwrap());
        }
<commit_msg>Fail if the userid passed is invalid.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using JabbR.Client.Models;
using SignalR.Client.Hubs;

namespace JabbR.Client
{
    public class JabbRClient
    {
        private readonly IHubProxy _chat;
        private readonly HubConnection _connection;
        private readonly string _url;
        private int _initialized;

        public JabbRClient(string url)
        {
            _url = url;
            _connection = new HubConnection(url);
            _chat = _connection.CreateProxy("JabbR.Chat");
        }

        public event Action<Message, string> MessageReceived;
        public event Action<IEnumerable<string>> LoggedOut;
        public event Action<User, string> UserJoined;
        public event Action<User, string> UserLeft;
        public event Action<string> Kicked;
        public event Action<string, string, string> PrivateMessage;
        public event Action<User, string> UserTyping;

        // Global
        public event Action<string, int> RoomCountChanged;
        public event Action<User> UserActivityChanged;
        public event Action<IEnumerable<User>> UsersInactive;

        public ICredentials Credentials
        {
            get
            {
                return _connection.Credentials;
            }
            set
            {
                _connection.Credentials = value;
            }
        }

        public event Action Disconnected
        {
            add
            {
                _connection.Closed += value;
            }
            remove
            {
                _connection.Closed -= value;
            }
        }

        public Task<LogOnInfo> Connect(string userId)
        {
            _chat["id"] = userId;

            return DoConnect(() => _connection.Start()
                                              .Then(() => _chat.Invoke<bool>("Join")
                                                               .Then(success =>
                                                               {
                                                                   if (!success)
                                                                   {
                                                                       throw new InvalidOperationException("Unknown user id.");
                                                                   }
                                                                   return TaskAsyncHelper.Empty;
                                                               }).FastUnwrap()).FastUnwrap());
        }

        public Task<LogOnInfo> Connect(string name, string password)
        {
            return DoConnect(() => _connection.Start()
                                              .Then(() =>
                                              {
                                                  return _chat.Invoke<bool>("Join").Then(success =>
                                                  {
                                                      if (!success)
                                                      {
                                                          return SendCommand("nick {0} {1}", name, password);
                                                      }
                                                      return TaskAsyncHelper.Empty;
                                                  }).FastUnwrap();

                                              }).FastUnwrap());
        }

{'fraction_non_alphanumeric': 0.0708673547989524, 'fraction_numerical': 0.0006162378678169774, 'mean_word_length': 0.9542444310656231, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 68, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4482399', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1209, 'n_words': 310}