Пример #1
0
        private int GetReplyUrlPort(bool onPremise, InteractiveParameters interactiveParameters)
        {
            int portStart = onPremise ? AdfsPortStart : AadPortStart;
            int portEnd   = onPremise ? AdfsPortEnd : AadPortEnd;

            int         port     = portStart;
            TcpListener listener = null;

            do
            {
                try
                {
                    listener = new TcpListener(IPAddress.Loopback, port);
                    listener.Start();
                    listener.Stop();
                    return(port);
                }
                catch (Exception ex)
                {
                    interactiveParameters.PromptAction(string.Format("Port {0} is taken with exception '{1}'; trying to connect to the next port.", port, ex.Message));
                    listener?.Stop();
                }
            }while (++port < portEnd);

            throw new Exception("Cannot find an open port.");
        }
Пример #2
0
        private Uri GetReplyUrl(bool onPremise, InteractiveParameters interactiveParameters)
        {
            var port = GetReplyUrlPort(onPremise, interactiveParameters);

            return(new Uri($"http://localhost:{port}"));
        }