Exemple #1
0
        void StopEndpoint(TcpRemoteForwardBridge tcpClientBridge)
        {
            EventTraceActivity stopActivity = BridgeEventSource.NewActivity("RemoteForwardBridgeStop", activity);

            try
            {
                BridgeEventSource.Log.RemoteForwardBridgeStopping(stopActivity, tcpClientBridge);
                tcpClientBridge.Close();
                BridgeEventSource.Log.RemoteForwardBridgeStop(stopActivity, tcpClientBridge);
            }
            catch (Exception exception)
            {
                BridgeEventSource.Log.RemoteForwardBridgeStopFailure(stopActivity, exception);
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
            }
        }
Exemple #2
0
        void StartEndpoint(RemoteForward remoteForward)
        {
            Uri hybridConnectionUri = null;
            TcpRemoteForwardBridge tcpRemoteForwardBridge = null;
            EventTraceActivity     stopActivity           = BridgeEventSource.NewActivity("RemoteForwardBridgeStart", activity);

            stopActivity.DiagnosticsActivity.Start();

            try
            {
                BridgeEventSource.Log.RemoteForwardBridgeStarting(stopActivity, this, remoteForward);

                var rcbs = remoteForward.RelayConnectionStringBuilder ?? new RelayConnectionStringBuilder(this.config.AzureRelayConnectionString);
                rcbs.EntityPath     = remoteForward.RelayName;
                hybridConnectionUri = new Uri(rcbs.Endpoint, rcbs.EntityPath);

                try
                {
                    tcpRemoteForwardBridge = new TcpRemoteForwardBridge(rcbs,
                                                                        remoteForward.Host, remoteForward.HostPort);
                    tcpRemoteForwardBridge.Online += (s, e) =>
                    {
                        NotifyOnline(hybridConnectionUri, remoteForward);
                        BridgeEventSource.Log.RemoteForwardBridgeOnline(stopActivity, hybridConnectionUri, tcpRemoteForwardBridge);
                    };
                    tcpRemoteForwardBridge.Offline += (s, e) =>
                    {
                        NotifyOffline(hybridConnectionUri, remoteForward);
                        BridgeEventSource.Log.RemoteForwardBridgeOffline(stopActivity, hybridConnectionUri, tcpRemoteForwardBridge);
                    };
                    tcpRemoteForwardBridge.Connecting += (s, e) =>
                    {
                        NotifyConnecting(hybridConnectionUri, remoteForward);
                        BridgeEventSource.Log.RemoteForwardBridgeConnecting(stopActivity, hybridConnectionUri, tcpRemoteForwardBridge);
                    };
                    tcpRemoteForwardBridge.Open().Wait();

                    this.clientBridges.Add(hybridConnectionUri.AbsoluteUri, tcpRemoteForwardBridge);

                    BridgeEventSource.Log.RemoteForwardBridgeStart(stopActivity, hybridConnectionUri.AbsoluteUri);
                }
                catch (Exception exception)
                {
                    BridgeEventSource.Log.RemoteForwardBridgeStartFailure(stopActivity, hybridConnectionUri, exception);
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }

                    try
                    {
                        if (tcpRemoteForwardBridge != null)
                        {
                            tcpRemoteForwardBridge.Dispose();
                        }
                    }
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        BridgeEventSource.Log.HandledExceptionAsWarning(this, e);
                    }

                    if (!this.config.ExitOnForwardFailure.HasValue ||
                        this.config.ExitOnForwardFailure.Value)
                    {
                        throw;
                    }
                }
            }
            finally
            {
                stopActivity.DiagnosticsActivity.Stop();
            }
        }