<commit_before>﻿using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Foundation.Api.Middlewares.SignalR.Contracts;

namespace Foundation.Api.Middlewares.SignalR
{
    public class MessagesHub : Hub
    {
        public override async Task OnConnected()
        {
            try
            {
                IOwinContext context = new OwinContext(Context.Request.Environment);

                Core.Contracts.IDependencyResolver dependencyResolver = context.Get<Core.Contracts.IDependencyResolver>("DependencyResolver");

                await dependencyResolver.Resolve<IMessagesHubEvents>().OnConnected(this);
            }
            finally
            {
                await base.OnConnected();
            }
        }

        public override async Task OnDisconnected(bool stopCalled)
        {
            try
            {
                IOwinContext context = new OwinContext(Context.Request.Environment);

                Core.Contracts.IDependencyResolver dependencyResolver = context.Get<Core.Contracts.IDependencyResolver>("DependencyResolver");

                await dependencyResolver.Resolve<IMessagesHubEvents>().OnDisconnected(this, stopCalled);
            }
            finally
            {
                await base.OnDisconnected(stopCalled);
            }
        }

        public override async Task OnReconnected()
        {
            try
            {
                IOwinContext context = new OwinContext(Context.Request.Environment);

                Core.Contracts.IDependencyResolver dependencyResolver = context.Get<Core.Contracts.IDependencyResolver>("DependencyResolver");

                await dependencyResolver.Resolve<IMessagesHubEvents>().OnReconnected(this);
            }
            finally
            {
                await base.OnReconnected();
            }
        }
    }
}<commit_msg>Catch ObjectDisposedException in signalr hub's OnDisconnected method due https://github.com/SignalR/SignalR/issues/2972<commit_after>﻿using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Foundation.Api.Middlewares.SignalR.Contracts;
using System;

namespace Foundation.Api.Middlewares.SignalR
{
    public class MessagesHub : Hub
    {
        public override async Task OnConnected()
        {
            try
            {
                IOwinContext context = new OwinContext(Context.Request.Environment);

                Core.Contracts.IDependencyResolver dependencyResolver = context.Get<Core.Contracts.IDependencyResolver>("DependencyResolver");

                await dependencyResolver.Resolve<IMessagesHubEvents>().OnConnected(this);
            }
            finally
            {
                await base.OnConnected();
            }
        }

        public override async Task OnDisconnected(bool stopCalled)
        {
            try
            {
                IOwinContext context = new OwinContext(Context.Request.Environment);

                Core.Contracts.IDependencyResolver dependencyResolver = context.Get<Core.Contracts.IDependencyResolver>("DependencyResolver");

                await dependencyResolver.Resolve<IMessagesHubEvents>().OnDisconnected(this, stopCalled);
            }
            catch (ObjectDisposedException ex) { /* https://github.com/SignalR/SignalR/issues/2972 */ }
            finally
            {
                await base.OnDisconnected(stopCalled);
            }
        }

        public override async Task OnReconnected()
        {
            try
            {
                IOwinContext context = new OwinContext(Context.Request.Environment);

                Core.Contracts.IDependencyResolver dependencyResolver = context.Get<Core.Contracts.IDependencyResolver>("DependencyResolver");

                await dependencyResolver.Resolve<IMessagesHubEvents>().OnReconnected(this);
            }
            finally
            {
                await base.OnReconnected();
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07969924812030076, 'fraction_numerical': 0.0020050125313283208, 'mean_word_length': 2.00300978179082, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '3750924', 'n_tokens_mistral': 979, 'n_tokens_neox': 956, 'n_words': 154}