Exemple #1
0
        private void Connect(string address)
        {
            if (_buildClient.IsConnected)
            {
                throw new Exception("Build client is already connected server or is currently connecting.");
            }

            var match = Regex.Match(address, @"^([a-z0-9\.]*?):(\d+)$", RegexOptions.IgnoreCase);

            if (!match.Success)
            {
                throw new ArgumentException("The address in connect needs to be in a valid ip:port or dns:port format.");
            }

            var dns  = match.Groups[1].Value;
            var port = int.Parse(match.Groups[2].Value);

            if (!_buildClient.Connect(dns, port))
            {
                throw new Exception($"Could not connect to '{address}'");
            }

            if (!_buildClient.WaitForAuthorize(TimeSpan.FromSeconds(5)))
            {
                throw new Exception("Authorization timed out.");
            }
        }