Example #1
0
        public SetupServiceSettings Resolve()
        {
            string hostname = "";

            // Ask user to pick up IP address from the list of available IP Addresses
            var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
            var ipAddresses       = (
                from netInterface
                in networkInterfaces
                where netInterface.OperationalStatus == OperationalStatus.Up
                from ip in netInterface.GetIPProperties().UnicastAddresses
                where ip.Address.AddressFamily == AddressFamily.InterNetwork
                select ip.Address.ToString()).ToList();
            var ipAddressChoiceSb = new StringBuilder();
            var validOptions      = new List <string>();

            for (var i = 1; i <= ipAddresses.Count; i++)
            {
                ipAddressChoiceSb.AppendLine($"[{i}] {ipAddresses[i - 1]}");
                validOptions.Add(i.ToString());
            }

            if (ipAddresses.Count > 1)
            {
                var answer = _userInteraction.AskQuestion(
                    String.Format(
                        Resources.IpAddressChoice,
                        ipAddressChoiceSb,
                        $"1 - {ipAddresses.Count}"),
                    validOptions.ToArray(),
                    "1");

                if (!int.TryParse(answer, out var intAnswer))
                {
                    throw new InvalidDataException("Invalid IP address option was provided.");
                }

                hostname = ipAddresses[intAnswer - 1];
            }
            else
            {
                hostname = ipAddresses[0];
            }

            // IP or Hostname has been selected
            return(new SetupServiceSettings().SetHostname(hostname));
        }
Example #2
0
        public override void Validate(X509Certificate2 certificate)
        {
            // Check that there is a certificate.
            if (certificate == null)
            {
                throw new ArgumentNullException(nameof(certificate));
            }

            if (!_acceptedCertificateThumbprints.Contains(certificate.Thumbprint))
            {
                var answer = _userInteraction.AskQuestion(
                    FormatConfirmationMessage(certificate),
                    new[] { "Y", "N", "y", "n" },
                    "N");

                if (string.Compare(answer, "N", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    throw new SecurityTokenValidationException("Certificate was not accepted by the user");
                }
                _acceptedCertificateThumbprints.Add(certificate.Thumbprint);
            }
        }