public FilteredEndpointInfoSource(
            ServerEndpointInfoSource serverEndpointInfoSource,
            IOptions <DiagnosticPortOptions> portOptions,
            ILogger <ClientEndpointInfoSource> clientSourceLogger)
        {
            _portOptions = portOptions.Value;

            DiagnosticPortConnectionMode connectionMode = _portOptions.GetConnectionMode();

            switch (connectionMode)
            {
            case DiagnosticPortConnectionMode.Connect:
                _source = new ClientEndpointInfoSource(clientSourceLogger);
                break;

            case DiagnosticPortConnectionMode.Listen:
                _source = serverEndpointInfoSource;
                break;

            default:
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorMessage_UnhandledConnectionMode, connectionMode));
            }

            // Filter out the current process based on the connection mode.
            if (RuntimeInfo.IsDiagnosticsEnabled)
            {
                int pid = Process.GetCurrentProcess().Id;

                // Regardless of connection mode, can use the runtime instance cookie to filter self out.
                try
                {
                    var  client = new DiagnosticsClient(pid);
                    Guid runtimeInstanceCookie = client.GetProcessInfo().RuntimeInstanceCookie;
                    if (Guid.Empty != runtimeInstanceCookie)
                    {
                        _runtimeInstanceCookieToFilterOut = runtimeInstanceCookie;
                    }
                }
                catch (Exception)
                {
                }

                // If connecting to runtime instances, filter self out. In listening mode, it's likely
                // that multiple processes have the same PID in multi-container scenarios.
                if (DiagnosticPortConnectionMode.Connect == connectionMode)
                {
                    _processIdToFilterOut = pid;
                }
            }
        }
        public FilteredEndpointInfoSource(IOptions <DiagnosticPortOptions> portOptions)
        {
            _portOptions = portOptions.Value;
            switch (_portOptions.ConnectionMode)
            {
            case DiagnosticPortConnectionMode.Connect:
                _source = new ClientEndpointInfoSource();
                break;

            case DiagnosticPortConnectionMode.Listen:
                _source = new ServerEndpointInfoSource(_portOptions.EndpointName);
                break;

            default:
                throw new InvalidOperationException($"Unhandled connection mode: {_portOptions.ConnectionMode}");
            }

            // Filter out the current process based on the connection mode.
            if (RuntimeInfo.IsDiagnosticsEnabled)
            {
                int pid = Process.GetCurrentProcess().Id;

                // Regardless of connection mode, can use the runtime instance cookie to filter self out.
                try
                {
                    var  client = new DiagnosticsClient(pid);
                    Guid runtimeInstanceCookie = client.GetProcessInfo().RuntimeInstanceCookie;
                    if (Guid.Empty != runtimeInstanceCookie)
                    {
                        _runtimeInstanceCookieToFilterOut = runtimeInstanceCookie;
                    }
                }
                catch (Exception)
                {
                }

                // If connecting to runtime instances, filter self out. In listening mode, it's likely
                // that multiple processes have the same PID in multi-container scenarios.
                if (DiagnosticPortConnectionMode.Connect == portOptions.Value.ConnectionMode)
                {
                    _processIdToFilterOut = pid;
                }
            }
        }