<commit_before>﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using SignalR;
using SignalR.Hosting;

namespace SignalR.Hosting.Owin.Samples
{
    public class RawConnection : PersistentConnection
    {
        private static readonly Dictionary<string, string> _users = new Dictionary<string, string>();
        private static readonly Dictionary<string, string> _clients = new Dictionary<string, string>();

        protected override Task OnConnectedAsync(IRequest request, IEnumerable<string> groups, string connectionId)
        {
            var userName = request.Cookies["user"];
            if (!String.IsNullOrEmpty(userName))
            {
                _clients[connectionId] = userName;
                _users[userName] = connectionId;
            }

            string user = GetUser(connectionId);

            return Connection.Broadcast(DateTime.Now + ": " + user + " joined");
        }

        protected override Task OnDisconnectAsync(string connectionId)
        {
            _users.Remove(connectionId);
            return Connection.Broadcast(DateTime.Now + ": " + GetUser(connectionId) + " disconnected");
        }

        protected override Task OnReceivedAsync(string connectionId, string data)
        {
            var serializer = new JavaScriptSerializer();
            var message = serializer.Deserialize<Message>(data);

            switch (message.Type)
            {
                case MessageType.Broadcast:
                    Connection.Broadcast(new
                    {
                        type = MessageType.Broadcast,
                        from = GetUser(connectionId),
                        data = message.Value
                    });
                    break;
                case MessageType.Send:
                    Send(new
                    {
                        type = MessageType.Send,
                        from = GetUser(connectionId),
                        data = message.Value
                    });
                    break;<commit_msg>Make owin raw sample same as asp.net.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using SignalR;
using SignalR.Hosting;

namespace SignalR.Hosting.Owin.Samples
{
    public class RawConnection : PersistentConnection
    {
        private static readonly Dictionary<string, string> _users = new Dictionary<string, string>();
        private static readonly Dictionary<string, string> _clients = new Dictionary<string, string>();

        protected override Task OnConnectedAsync(IRequest request, IEnumerable<string> groups, string connectionId)
        {
            var userName = request.Cookies["user"];
            if (!String.IsNullOrEmpty(userName))
            {
                _clients[connectionId] = userName;
                _users[userName] = connectionId;
            }

            string user = GetUser(connectionId);

            return AddToGroup(connectionId, "foo").ContinueWith(_ =>
                   Connection.Broadcast(DateTime.Now + ": " + user + " joined")).Unwrap();
        }

        protected override Task OnDisconnectAsync(string connectionId)
        {
            _users.Remove(connectionId);
            return Connection.Broadcast(DateTime.Now + ": " + GetUser(connectionId) + " disconnected");
        }

        protected override Task OnReceivedAsync(string connectionId, string data)
        {
            var serializer = new JavaScriptSerializer();
            var message = serializer.Deserialize<Message>(data);

            switch (message.Type)
            {
                case MessageType.Broadcast:
                    Connection.Broadcast(new
                    {
                        type = MessageType.Broadcast,
                        from = GetUser(connectionId),
                        data = message.Value
                    });
                    break;
                case MessageType.Send:
                    Send(new
                    {
                        type = MessageType.Send,
                        from = GetUser(connectionId),
                        data = message.Value
                    });
                    break;
{'fraction_non_alphanumeric': 0.08230356726509676, 'fraction_numerical': 0.0, 'mean_word_length': 1.6896551724137931, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 16, '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': '668966', 'n_tokens_mistral': 1000, 'n_tokens_neox': 942, 'n_words': 221}