示例#1
0
        private async Task <bool> CanConnectUsingBasic(Connection connection)
        {
            try
            {
                var proxy = new WITSMLWebServiceConnection(connection.Uri, WMLSVersion.WITSML141);

                if (!string.IsNullOrWhiteSpace(connection.Username))
                {
                    proxy.Username = connection.Username;
                    proxy.SetSecurePassword(connection.SecurePassword);
                }

                connection.SetServerCertificateValidation();

                proxy.GetVersion();

                _log.Debug("Witsml connection test passed");
                return(await Task.FromResult(true));
            }
            catch (Exception ex)
            {
                _log.Error("Witsml connection test failed: {0}", ex);
                return(await Task.FromResult(false));
            }
        }
        /// <summary>
        /// Gets the supported versions from the server.
        /// </summary>
        /// <param name="proxy">The proxy.</param>
        /// <param name="connection">The connection.</param>
        /// <param name="throwOnError">if set to <c>true</c> throw on error.</param>
        /// <returns>The supported versions.</returns>
        internal string GetVersions(WITSMLWebServiceConnection proxy, Connection connection, bool throwOnError = true)
        {
            // Update proxy connection settings
            connection.UpdateProxy(proxy);

            var parent            = Parent?.Parent;
            var supportedVersions = string.Empty;

            // Output Request for GetVersion
            parent?.OutputRequestMessages(Functions.GetVersion, null, parent?.GetOptionsIn(Functions.GetVersion));

            try
            {
                supportedVersions = proxy.GetVersion();
                _log.DebugFormat("Supported versions '{0}' found on WITSML server with uri '{1}'", supportedVersions, connection.Uri);
            }
            catch (Exception ex)
            {
                _log.WarnFormat("Exception getting versions on WITSML server with uri '{0}' : '{1}'", connection.Uri, ex.Message);

                if (throwOnError)
                {
                    throw;
                }

                parent?.OutputError("Error connecting to server.", ex);
                return(supportedVersions);
            }

            if (parent == null)
            {
                return(supportedVersions);
            }

            parent.ClearQueryResults();
            parent.OutputResults(null, supportedVersions, 0);
            parent.OutputMessages(null, supportedVersions, 0);

            return(supportedVersions);
        }