예제 #1
0
        public CheckFieldResult CheckField(object model, string propertyName, string value)
        {
            ConnectionFactory factory;

            try
            {
                factory = new ConnectionFactory {
                    Uri = value
                };
            }
            catch
            {
                return(CheckFieldResult.Failed(propertyName, value));
            }

            var schema = factory.Ssl.Enabled ? "amqps" : "amqp";
            var url    = $"{schema}://{factory.HostName}:{factory.Port}";

            try
            {
                using (var connection = factory.CreateConnection())
                {
                    bool checkResult = connection.IsOpen;
                    return(checkResult
                        ? CheckFieldResult.Ok(propertyName, url)
                        : CheckFieldResult.Failed(propertyName, url));
                }
            }
            catch
            {
                return(CheckFieldResult.Failed(propertyName, url));
            }
        }
예제 #2
0
        public CheckFieldResult CheckField(object model, string propertyName, string value)
        {
            string url = string.Empty;

            try
            {
                url = GetFullUrl(value);
            }
            catch (Exception)
            {
                return(CheckFieldResult.Failed(propertyName, string.Concat(value, _path)));
            }

            try
            {
                bool checkResult;

                var httpClient = HttpClientProvider.Client;
                httpClient.Timeout = _timeout;

                using (var response = httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).GetAwaiter().GetResult())
                {
                    checkResult = response.IsSuccessStatusCode;
                }

                return(checkResult
                    ? CheckFieldResult.Ok(propertyName, url)
                    : CheckFieldResult.Failed(propertyName, url));
            }
            catch (Exception)
            {
                return(CheckFieldResult.Failed(propertyName, url));
            }
        }
예제 #3
0
        public CheckFieldResult CheckField(object model, string propertyName, string value)
        {
            string address;
            int    port;

            if (_isPortProvided)
            {
                address = value;

                if (string.IsNullOrEmpty(_portName))
                {
                    port = _port;
                }
                else
                {
                    var portProperty = model.GetType().GetTypeInfo().GetProperty(_portName);
                    if (portProperty == null)
                    {
                        return(CheckFieldResult.Failed(propertyName, value, $"Property '{_portName}' not found"));
                    }

                    var portValue = portProperty.GetValue(model).ToString();

                    if (!int.TryParse(portValue, out port))
                    {
                        return(CheckFieldResult.Failed(propertyName, value, $"Invalid port value in property '{_portName}'"));
                    }
                }
            }
            else
            {
                if (value.SplitParts(':', 2, out var values))
                {
                    address = values[0];

                    if (!int.TryParse(values[1], out port))
                    {
                        return(CheckFieldResult.Failed(propertyName, value, "Invalid port"));
                    }
                }
                else
                {
                    return(CheckFieldResult.Failed(propertyName, value, "Invalid address"));
                }
            }

            bool checkResult = TcpHelper.TcpCheck(address, port);

            string url = $"tcp://{address}:{port}";

            return(checkResult
                ? CheckFieldResult.Ok(propertyName, url)
                : CheckFieldResult.Failed(propertyName, url));
        }
        public CheckFieldResult CheckField(object model, string propertyName, string value)
        {
            string url = string.Empty;

            try
            {
                var account = CloudStorageAccount.Parse(value);
                var client  = account.CreateCloudTableClient();
                url = client.BaseUri.ToString();
                client.ListTablesSegmentedAsync(null).GetAwaiter().GetResult();
                return(CheckFieldResult.Ok(propertyName, url));
            }
            catch
            {
                return(CheckFieldResult.Failed(propertyName, url));
            }
        }
예제 #5
0
        public CheckFieldResult CheckField(object model, string propertyName, string value)
        {
            var url = string.Empty;

            try
            {
                var sb = new SqlConnectionStringBuilder(value);
                url = sb.DataSource;

                using (var connection = new SqlConnection(sb.ConnectionString))
                {
                    connection.Open();
                }
                return(CheckFieldResult.Ok(propertyName, url));
            }
            catch (Exception ex)
            {
                return(CheckFieldResult.Failed(propertyName, url, ex.Message));
            }
        }
        public CheckFieldResult CheckField(object model, string propertyName, string value)
        {
            try
            {
                var mongoUrl = MongoUrl.Create(value);

                var client = new MongoClient(mongoUrl);

                client.ListDatabases();

                return(client.Cluster.Description.State == ClusterState.Connected
                    ? CheckFieldResult.Ok(propertyName, value)
                    : CheckFieldResult.Failed(propertyName, value));
            }
            catch (MongoConfigurationException)
            {
                return(CheckFieldResult.Failed(propertyName, value));
            }
            catch (TimeoutException)
            {
                return(CheckFieldResult.Failed(propertyName, value));
            }
        }