コード例 #1
0
        protected virtual async Task HandleRemotePeerAsync(RemoteTcpPeer remoteTcpPeer, CancellationToken cancellationToken)
        {
            try
            {
                await this.ReceiveFromRemotePeerAsync(remoteTcpPeer, cancellationToken).ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                if (!cancellationToken.IsCancellationRequested)
                {
                    remoteTcpPeer.ConnectionCloseReason = ConnectionCloseReason.Timeout;
                    return;
                }
                else
                {
                    remoteTcpPeer.ConnectionCloseReason = ConnectionCloseReason.LocalShutdown;
                    return;
                }
            }
            catch (Exception ex)
            {
                var unhandledErrorEventArgs = new UnhandledErrorEventArgs(new ErrorData(ex));

                this.OnUnhandledError(unhandledErrorEventArgs);
            }

            var connectionClosedEventArgs = new ConnectionClosedEventArgs(new ConnectionClosedData(remoteTcpPeer, remoteTcpPeer.ConnectionCloseReason));

            this.OnConnectionClosed(remoteTcpPeer, connectionClosedEventArgs);
        }
コード例 #2
0
ファイル: Configuration.cs プロジェクト: Takym/ExapisSOP
        internal async Task <bool> OnUnhandledErrorAsync(Exception e, IContext context)
        {
            var args = new UnhandledErrorEventArgs(e, context);

            this.UnhandledError?.Invoke(this, args);
            return(await Task.FromResult(args.Abort));
        }
コード例 #3
0
        protected virtual void OnConnectionEstablished(ConnectionEstablishedEventArgs e)
        {
            try
            {
                this.ConnectionEstablished?.Invoke(this, e);
            }
            catch (Exception ex)
            {
                var unhandledErrorEventArgs = new UnhandledErrorEventArgs(new ErrorData(ex));

                this.OnUnhandledError(unhandledErrorEventArgs);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Takym/ExapisSOP
        private static void Config_UnhandledError(object?sender, UnhandledErrorEventArgs e)
        {
            var path = e.Context.GetLoggingSystem()?.SaveErrorReport(e.Context, e.Exception, new HResultDetailProvider());

            if (e.Context.Paths is IPathList paths)
            {
                ErrorReportBuilder.SaveERBC(paths);
            }
            var logger = e.Context.LogFile?.GetConsoleLogger();

            logger?.UnhandledException(e.Exception);
            logger?.Info("The error report file is saved to: " + path);
            e.Abort = true;
        }
コード例 #5
0
        protected virtual void OnConnectionClosed(RemoteTcpPeer remoteTcpPeer, ConnectionClosedEventArgs e)
        {
            try
            {
                remoteTcpPeer.OnConnectionClosed(e);
                this.ConnectionClosed?.Invoke(this, e);
            }
            catch (Exception ex)
            {
                var unhandledErrorEventArgs = new UnhandledErrorEventArgs(new ErrorData(ex));

                this.OnUnhandledError(unhandledErrorEventArgs);
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: chugh97/ErrorControlSystem
 /// <summary>
 /// Show unhandled exception message customized mode.
 /// </summary>
 /// <param name="sender">Raw exception object</param>
 /// <param name="e">Compiled error object</param>
 public static void AlertUnhandledErrors(object sender, UnhandledErrorEventArgs e)
 {
     MessageBox.Show(e.ErrorObject.Message);
 }
コード例 #7
0
 /// <summary>
 /// Show unhandled exception message customized mode.
 /// </summary>
 /// <param name="sender">Raw exception object</param>
 /// <param name="e">Compiled error object</param>
 public static void AlertUnhandledErrors(object sender, UnhandledErrorEventArgs e)
 {
     MessageBox.Show(e.ErrorObject.Message);
 }
コード例 #8
0
 protected virtual void OnUnhandledError(UnhandledErrorEventArgs e)
 {
     this.UnhandledErrorOccured?.Invoke(this, e);
 }
コード例 #9
0
        // exploiting "async void" simplifies everything
        protected virtual async void HandleNewTcpClientAsync(TcpClient tcpClient, CancellationToken token)
        {
            using (tcpClient)
                using (var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(token))
                {
                    var sendQueue = this.CreateSendQueueActionBlock(linkedCts.Token);

                    RemoteTcpPeer remoteTcpPeer;
                    SslStream     sslStream = null;

                    try
                    {
                        if (this.Config.UseSsl && this.Config.X509Certificate != null)
                        {
                            sslStream = this.CreateSslStream(tcpClient);

                            await this.AuthenticateSslStream(tcpClient, sslStream, linkedCts.Token)
                            .ConfigureAwait(false);

                            remoteTcpPeer = this.CreateRemoteTcpPeer(tcpClient, sslStream, sendQueue, linkedCts);
                        }
                        else
                        {
                            remoteTcpPeer = this.CreateRemoteTcpPeer(tcpClient, sendQueue, linkedCts);
                        }
                    }
                    catch (AuthenticationException ex)
                    {
                        var serverErrorEventArgs = new TcpServerErrorEventArgs(new ErrorData(ex));
                        this.OnServerErrorOccured(serverErrorEventArgs);

                        sendQueue.Complete();
                        sslStream?.Dispose();

                        return;
                    }
                    catch (Exception)
                    {
                        sendQueue.Complete();
                        return;
                    }

                    using (remoteTcpPeer)
                    {
                        var connectionEstablishedEventArgs = new ConnectionEstablishedEventArgs(new ConnectionEstablishedData(remoteTcpPeer));
                        this.OnConnectionEstablished(connectionEstablishedEventArgs);

                        try
                        {
                            await this.HandleRemotePeerAsync(remoteTcpPeer, linkedCts.Token).ConfigureAwait(false);
                        }
                        catch (Exception ex)
                        {
                            var unhandledErrorEventArgs = new UnhandledErrorEventArgs(new ErrorData(ex));

                            this.OnUnhandledError(unhandledErrorEventArgs);
                        }
                        finally
                        {
                            sendQueue.Complete();
                            sslStream?.Dispose();
                        }
                    }
                }
        }