Esempio n. 1
0
 public override void OnResume()
 {
     Log.Info("Starting mouse move stream");
     _mouseMoveStream?.Dispose();
     _mouseMoveStream = this.GetAgent().FullDesktopClient.SendMouseMove();
     base.OnResume();
 }
Esempio n. 2
0
 public void Dispose()
 {
     try
     {
         _semaphoreSlim.Dispose();
         channel?.ShutdownAsync();
         stream?.Dispose();
     }
     catch (Exception e)
     {
         OnError?.Invoke(this, $"Error during dispose: {e.Message}");
     }
 }
Esempio n. 3
0
        public async Task DisconnectAsync(bool gracefulDisconnect)
        {
            IsConnected = false;
            IsShutdown  = true;

            // we complete but no need to await the jobs
            _sendAnnouncementJobs.Complete();
            _sendBlockJobs.Complete();
            _sendTransactionJobs.Complete();

            _announcementStreamCall?.Dispose();
            _transactionStreamCall?.Dispose();
            _blockStreamCall?.Dispose();

            // send disconnect message if the peer is still connected and the connection
            // is stable.
            if (gracefulDisconnect && (_channel.State == ChannelState.Idle || _channel.State == ChannelState.Ready))
            {
                GrpcRequest request = new GrpcRequest {
                    ErrorMessage = "Error while sending disconnect."
                };

                try
                {
                    Metadata metadata = new Metadata {
                        { GrpcConstants.SessionIdMetadataKey, OutboundSessionId }
                    };

                    await RequestAsync(
                        () => _client.DisconnectAsync(new DisconnectReason
                    {
                        Why = DisconnectReason.Types.Reason.Shutdown
                    }, metadata), request);
                }
                catch (NetworkException)
                {
                    // swallow the exception, we don't care because we're disconnecting.
                }
            }

            try
            {
                await _channel.ShutdownAsync();
            }
            catch (InvalidOperationException)
            {
                // if channel already shutdown
            }
        }
Esempio n. 4
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _timer?.Dispose();
                    _metricsUpdateChannel?.RequestStream.CompleteAsync().ConfigureAwait(false).GetAwaiter().GetResult();
                    _heatbeatChannel?.RequestStream.CompleteAsync().ConfigureAwait(false).GetAwaiter().GetResult();
                    _metricsUpdateChannel?.Dispose();
                    _heatbeatChannel?.Dispose();
                    _channel.ShutdownAsync().ConfigureAwait(false).GetAwaiter().GetResult();
                    _channel.Dispose();
                }

                disposedValue = true;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Send a lib announcement to the peer using the stream call.
        /// Note: this method is not thread safe.
        /// </summary>
        public async Task SendLibAnnouncementAsync(LibAnnouncement libAnnouncement)
        {
            if (_libAnnouncementStreamCall == null)
            {
                _libAnnouncementStreamCall = _client.LibAnnouncementBroadcastStream(new Metadata {
                    { GrpcConstants.SessionIdMetadataKey, OutboundSessionId }
                });
            }

            try
            {
                await _libAnnouncementStreamCall.RequestStream.WriteAsync(libAnnouncement);
            }
            catch (RpcException)
            {
                _libAnnouncementStreamCall.Dispose();
                _libAnnouncementStreamCall = null;

                throw;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Send a transaction to the peer using the stream call.
        /// Note: this method is not thread safe.
        /// </summary>
        private async Task SendTransactionAsync(Transaction transaction)
        {
            if (_transactionStreamCall == null)
            {
                _transactionStreamCall = _client.TransactionBroadcastStream(new Metadata {
                    { GrpcConstants.SessionIdMetadataKey, OutboundSessionId }
                });
            }

            try
            {
                await _transactionStreamCall.RequestStream.WriteAsync(transaction);
            }
            catch (RpcException)
            {
                _transactionStreamCall.Dispose();
                _transactionStreamCall = null;

                throw;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Send a announcement to the peer using the stream call.
        /// Note: this method is not thread safe.
        /// </summary>
        private async Task SendAnnouncementAsync(BlockAnnouncement header)
        {
            if (_announcementStreamCall == null)
            {
                _announcementStreamCall = _client.AnnouncementBroadcastStream(new Metadata {
                    { GrpcConstants.SessionIdMetadataKey, OutboundSessionId }
                });
            }

            try
            {
                await _announcementStreamCall.RequestStream.WriteAsync(header);
            }
            catch (RpcException)
            {
                _announcementStreamCall.Dispose();
                _announcementStreamCall = null;

                throw;
            }
        }
Esempio n. 8
0
        private async Task BroadcastBlockAsync(BlockWithTransactions blockWithTransactions)
        {
            if (_blockStreamCall == null)
            {
                _blockStreamCall = _client.BlockBroadcastStream(new Metadata {
                    { GrpcConstants.SessionIdMetadataKey, OutboundSessionId }
                });
            }

            try
            {
                await _blockStreamCall.RequestStream.WriteAsync(blockWithTransactions);
            }
            catch (RpcException)
            {
                _blockStreamCall.Dispose();
                _blockStreamCall = null;

                throw;
            }
        }
Esempio n. 9
0
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(Method <TRequest, TResponse> method, string host, CallOptions options)
        {
            var session = m_channel.GetSession();
            var rpc     = new RpcTunnel <TRequest, TResponse>(session, method);
            var ret     = new AsyncClientStreamingCall <TRequest, TResponse>(rpc, session, method);

            try
            {
                // Send request
                rpc.StartRequest();

                // Wait response
                return(ret);
            }
            catch (Exception)
            {
                // Failed to request: unregister rpc
                ret.Dispose();
                throw;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Send a transaction to the peer using the stream call.
        /// Note: this method is not thread safe.
        /// </summary>
        public async Task SendTransactionAsync(Transaction transaction)
        {
            if (!IsConnected)
            {
                return;
            }

            if (_transactionStreamCall == null)
            {
                _transactionStreamCall = _client.TransactionBroadcastStream();
            }

            try
            {
                await _transactionStreamCall.RequestStream.WriteAsync(transaction);
            }
            catch (RpcException e)
            {
                _transactionStreamCall.Dispose();
                _transactionStreamCall = null;

                HandleFailure(e, $"Error during transaction broadcast: {transaction.GetHash()}.");
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Send a announcement to the peer using the stream call.
        /// Note: this method is not thread safe.
        /// </summary>
        public async Task SendAnnouncementAsync(BlockAnnouncement header)
        {
            if (!IsConnected)
            {
                return;
            }

            if (_announcementStreamCall == null)
            {
                _announcementStreamCall = _client.AnnouncementBroadcastStream();
            }

            try
            {
                await _announcementStreamCall.RequestStream.WriteAsync(header);
            }
            catch (RpcException e)
            {
                _announcementStreamCall.Dispose();
                _announcementStreamCall = null;

                HandleFailure(e, $"Error during announcement broadcast: {header.BlockHash}.");
            }
        }
Esempio n. 12
0
        public async Task SendBlockAsync(BlockWithTransactions blockWithTransactions)
        {
            if (!IsConnected)
            {
                return;
            }

            if (_blockStreamCall == null)
            {
                _blockStreamCall = _client.BlockBroadcastStream();
            }

            try
            {
                await _blockStreamCall.RequestStream.WriteAsync(blockWithTransactions);
            }
            catch (RpcException e)
            {
                _blockStreamCall.Dispose();
                _blockStreamCall = null;

                HandleFailure(e, $"Error during block broadcast: {blockWithTransactions.Header.GetHash()}.");
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 指定されたメソッド呼び出しを登録します。
        /// </summary>
        /// <typeparam name="TRequest">リクエストの型</typeparam>
        /// <typeparam name="TResponse">レスポンスの型</typeparam>
        /// <param name="call">呼び出しオブジェクト</param>
        /// <param name="method">メソッド</param>
        /// <param name="host">ホスト</param>
        /// <param name="options">オプション</param>
        /// <param name="performanceListener">パフォーマンスリスナー</param>
        /// <returns>呼び出しオブジェクト</returns>
        internal static AsyncClientStreamingCall <TRequest, TResponse> Regist <TRequest, TResponse>(AsyncClientStreamingCall <TRequest, TResponse> call, Method <TRequest, TResponse> method, string host, CallOptions options, GrpcClientPerformanceListener performanceListener)
        {
            GrpcCallInvokerContext.Releaser releaser = new GrpcCallInvokerContext.Releaser(delegate()
            {
                call.Dispose();
            });

            GrpcCallState state = new GrpcCallState(method, host, options);

            AsyncClientStreamingCall <TRequest, TResponse> wrap = new AsyncClientStreamingCall <TRequest, TResponse>(
                new RequestStreamWriter <TRequest>(call.RequestStream, method, host, options, state.OnRequestStreamCompleted, performanceListener)
                , call.ResponseAsync
                , call.ResponseHeadersAsync
                , call.GetStatus
                , call.GetTrailers
                , releaser.Dispose
                );

            releaser.Target = wrap;

            GrpcCallInvokerContext.AddState(wrap, state);

            return(wrap);
        }
Esempio n. 14
0
        public override async Task DisposeAsync()
        {
            await base.DisposeAsync();

            _writer.Dispose();
        }
 public void Dispose()
 {
     m_Call.Dispose();
 }
Esempio n. 16
0
 public void Dispose()
 {
     _feedCpuInfoCall?.Dispose();
     _timer?.Dispose();
 }