public async Task <DuplexStreamingResult <byte[], byte[]> > Connect()
        {
            var streamingContext = GetDuplexStreamingContext <byte[], byte[]>();

            var group = StreamingHubHandlerRepository.GetGroupRepository(Context.MethodHandler);

            this.Group = new HubGroupRepository(this.Context, group);
            try
            {
                await OnConnecting();
                await HandleMessageAsync();
            }
            catch (OperationCanceledException)
            {
                // NOTE: If DuplexStreaming is disconnected by the client, OperationCanceledException will be thrown.
                //       However, such behavior is expected. the exception can be ignored.
            }
            catch (IOException ex) when(ex.InnerException is ConnectionAbortedException)
            {
                // NOTE: If DuplexStreaming is disconnected by the client, IOException will be thrown.
                //       However, such behavior is expected. the exception can be ignored.
            }
            finally
            {
                Context.CompleteStreamingHub();
                await OnDisconnected();

                await this.Group.DisposeAsync();
            }

            return(streamingContext.Result());
        }
Exemple #2
0
        public async Task <DuplexStreamingResult <byte[], byte[]> > Connect()
        {
            var streamingContext = GetDuplexStreamingContext <byte[], byte[]>();

            Context.AsyncWriterLock = new AsyncLock();

            var group = StreamingHubHandlerRepository.GetGroupRepository(Context.MethodHandler);

            this.Group = new HubGroupRepository(this.Context, group);
            try
            {
                await OnConnecting();
                await HandleMessageAsync();
            }
            finally
            {
                await OnDisconnected();

                await this.Group.DisposeAsync();
            }

            return(streamingContext.Result());
        }