/// <summary>
        /// обработчик кнопки "проверить соединение"
        /// </summary>
        private async void Btn_checkNetwork_ClickAsync(object sender, RoutedEventArgs e)
        {
            var ip = field_ip.Text;

            int.TryParse(field_port.Text, out int port);
            int.TryParse(field_portApi.Text, out int portApi);
            var secretKey = field_secretKey.Text;

            var checkResult = _cs.CheckSettings(ip, port, portApi, secretKey);

            if (checkResult != default)
            {
                MessageBox.Show(checkResult);
            }
            else
            {
                _cs.IP        = ip;
                _cs.Port      = port;
                _cs.PortAPI   = portApi;
                _cs.SecretKey = secretKey;

                var webConnection  = new WebConnection(_cs);
                var isApiAvailable = await webConnection.CheckConnectionAsync(portApi);

                var isServerAvailable = await webConnection.CheckConnectionAsync(port);

                //TODO: поправить
                string serversAvailability = "";
                serversAvailability += isApiAvailable ? Constants.CONNECTION_API_SUCCESSED : Constants.CONNECTION_API_FAILED;
                serversAvailability += Environment.NewLine;
                serversAvailability += isServerAvailable ? Constants.CONNECTION_DOOR_CONTROLLER_SUCCESSED : Constants.CONNECTION_DOOR_CONTROLLER_FAILED;


                if (isServerAvailable || isApiAvailable)
                {
                    Logger.Log = Constants.CONNECTION_ESTABLISHED;
                    MessageBox.Show(serversAvailability);
                }
                else
                {
                    Logger.Log = Constants.CONNECTION_NOT_ESTABLISHED;
                    MessageBox.Show(serversAvailability);
                }
            }
        }
        public void CheckSettingsWithParamsTest_Return_Default()
        {
            // Arrange
            IConnectionSettings connectionSettings = new ConnectionSettings();

            // Act
            var result = connectionSettings.CheckSettings("ip", 1234, 1234, "key");

            // Assert
            Assert.AreEqual(null, result);
        }
Exemplo n.º 3
0
        private void ButtonCheckSettings_Click(object sender, EventArgs e)
        {
            _cs.IP = textBoxIP.Text;

            if (!string.IsNullOrWhiteSpace(maskedTextBoxPort.Text))
            {
                _cs.Port = int.Parse(maskedTextBoxPort.Text);
            }
            else
            {
                _cs.Port = null;
            }

            if (!string.IsNullOrWhiteSpace(maskedTextBoxPortAPI.Text))
            {
                _cs.PortAPI = int.Parse(maskedTextBoxPortAPI.Text);
            }
            else
            {
                _cs.PortAPI = null;
            }

            _cs.SecretKey = textBoxSecretKey.Text;

            var result = _cs.CheckSettings();

            Logger.Log = result ?? Constants.SETTING_CORRECT;

            if (result == null)
            {
                MessageBox.Show(Constants.SETTING_CORRECT);
            }
            else
            {
                MessageBox.Show(Constants.SETTING_INCORRECT);
            }
        }