private ConnectionTestResults IsAccessible(string url, SecurityProtocolType spType)
        {
            ConnectionTestResults connResult = new ConnectionTestResults();

            connResult.ConnectionSuccess    = false;
            connResult.SSLConnectionFailure = false;

            HttpClient c = null;

            try
            {
                ServicePointManager.SecurityProtocol = spType;
                c = new HttpClient();
                //c.BaseAddress = webBrowser1.Url;
                var result = c.GetAsync(url).GetAwaiter().GetResult();
                connResult.ConnectionSuccess = true;
            }
            catch (HttpRequestException exp)
            {
                if (exp.InnerException != null)
                {
                    var secureConnExp = exp.InnerException as WebException;
                    if (secureConnExp != null && secureConnExp.Status == WebExceptionStatus.SecureChannelFailure)
                    {
                        connResult.SSLConnectionFailure = true;
                    }
                }
            }
            finally
            {
                if (c != null)
                {
                    c.Dispose();
                }
            }

            return(connResult);
        }
示例#2
0
        public string PostBackProc(string data, [AllowNull] string user, int userRights)
        {
            NameValueCollection parts = HttpUtility.ParseQueryString(data);

            string form = parts["id"];


            /////
            ///
            ///
            PluginConfig config = this.pluginConfig;
            string       action = parts["id"];

            if (NameToIdWithPrefix(SaveButtonName) == action)
            {
                try
                {
                    PopulatePluginConfig(config, parts);
                    config.FireConfigChanged();

                    this.divToUpdate.Add(SuccessDivId, "Settings updated successfully");
                }
                catch (Exception e)
                {
                    pluginInstance.LogError(string.Format("Error updating settings: {0}", e.Message));
                    this.divToUpdate.Add(ErrorDivId, "Error updating settings");
                }
            }
            else if (NameToIdWithPrefix(TestButtonName) == action)
            {
                PluginConfig testConfig;
                using (testConfig = new PluginConfig(HS, true))
                {
                    PopulatePluginConfig(testConfig, parts);

                    ConnectionTestResults results = ElasticsearchManager.PerformConnectivityTest(testConfig);

                    if (results.ConnectionSuccessful)
                    {
                        StringBuilder stb = new StringBuilder();
                        stb.Append(@"<div>");
                        stb.Append(@"<h3>Connection Test Successful!<h3>");
                        stb.Append(BuildClusterHealthView(results.ClusterHealth));
                        stb.Append(@"</div>");
                        this.divToUpdate.Add(SuccessDivId, stb.ToString());
                        this.divToUpdate.Add(ErrorDivId, "");
                    }
                    else
                    {
                        string message = "Connection test failed";
                        if (results.ClusterHealth != null && results.ClusterHealth.OriginalException != null)
                        {
                            message += ": " + results.ClusterHealth.OriginalException.Message;
                        }

                        this.divToUpdate.Add(SuccessDivId, "");
                        this.divToUpdate.Add(ErrorDivId, message);
                    }
                }
            }

            return(base.postBackProc(Name, data, user, userRights));
        }