using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using QC.Tools.Properties;

namespace QC.Tools.QTMDatabaseService;

[GeneratedCode("System.Web.Services", "4.0.30319.1")]
[WebServiceBinding(Name = "QTMDatabaseServiceSoap", Namespace = "http://qtm")]
[DebuggerStepThrough]
[DesignerCategory("code")]
public class QTMDatabaseService : SoapHttpClientProtocol
{
	private SendOrPostCallback GetServerListOperationCompleted;

	private SendOrPostCallback GetDatabaseListOperationCompleted;

	private bool useDefaultCredentialsSetExplicitly;

	public new string Url
	{
		get
		{
			return base.Url;
		}
		set
		{
			if (IsLocalFileSystemWebService(base.Url) && !useDefaultCredentialsSetExplicitly && !IsLocalFileSystemWebService(value))
			{
				base.UseDefaultCredentials = false;
			}
			base.Url = value;
		}
	}

	public new bool UseDefaultCredentials
	{
		get
		{
			return base.UseDefaultCredentials;
		}
		set
		{
			base.UseDefaultCredentials = value;
			useDefaultCredentialsSetExplicitly = true;
		}
	}

	public event GetServerListCompletedEventHandler GetServerListCompleted;

	public event GetDatabaseListCompletedEventHandler GetDatabaseListCompleted;

	public QTMDatabaseService()
	{
		Url = Settings.Default.DatabaseOptions_QTMDatabaseService_QTMDatabaseService;
		if (IsLocalFileSystemWebService(Url))
		{
			UseDefaultCredentials = true;
			useDefaultCredentialsSetExplicitly = false;
		}
		else
		{
			useDefaultCredentialsSetExplicitly = true;
		}
	}

	[SoapDocumentMethod("http://qtm/GetServerList", RequestNamespace = "http://qtm", ResponseNamespace = "http://qtm", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
	public string[] GetServerList()
	{
		object[] array = Invoke("GetServerList", new object[0]);
		return (string[])array[0];
	}

	public void GetServerListAsync()
	{
		GetServerListAsync(null);
	}

	public void GetServerListAsync(object userState)
	{
		if (GetServerListOperationCompleted == null)
		{
			GetServerListOperationCompleted = OnGetServerListOperationCompleted;
		}
		InvokeAsync("GetServerList", new object[0], GetServerListOperationCompleted, userState);
	}

	private void OnGetServerListOperationCompleted(object arg)
	{
		if (this.GetServerListCompleted != null)
		{
			InvokeCompletedEventArgs invokeCompletedEventArgs = (InvokeCompletedEventArgs)arg;
			this.GetServerListCompleted(this, new GetServerListCompletedEventArgs(invokeCompletedEventArgs.Results, invokeCompletedEventArgs.Error, invokeCompletedEventArgs.Cancelled, invokeCompletedEventArgs.UserState));
		}
	}

	[SoapDocumentMethod("http://qtm/GetDatabaseList", RequestNamespace = "http://qtm", ResponseNamespace = "http://qtm", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
	public string[] GetDatabaseList(string serverName)
	{
		object[] array = Invoke("GetDatabaseList", new object[1] { serverName });
		return (string[])array[0];
	}

	public void GetDatabaseListAsync(string serverName)
	{
		GetDatabaseListAsync(serverName, null);
	}

	public void GetDatabaseListAsync(string serverName, object userState)
	{
		if (GetDatabaseListOperationCompleted == null)
		{
			GetDatabaseListOperationCompleted = OnGetDatabaseListOperationCompleted;
		}
		InvokeAsync("GetDatabaseList", new object[1] { serverName }, GetDatabaseListOperationCompleted, userState);
	}

	private void OnGetDatabaseListOperationCompleted(object arg)
	{
		if (this.GetDatabaseListCompleted != null)
		{
			InvokeCompletedEventArgs invokeCompletedEventArgs = (InvokeCompletedEventArgs)arg;
			this.GetDatabaseListCompleted(this, new GetDatabaseListCompletedEventArgs(invokeCompletedEventArgs.Results, invokeCompletedEventArgs.Error, invokeCompletedEventArgs.Cancelled, invokeCompletedEventArgs.UserState));
		}
	}

	public new void CancelAsync(object userState)
	{
		base.CancelAsync(userState);
	}

	private bool IsLocalFileSystemWebService(string url)
	{
		if (url == null || url == string.Empty)
		{
			return false;
		}
		Uri uri = new Uri(url);
		if (uri.Port >= 1024 && string.Compare(uri.Host, "localHost", StringComparison.OrdinalIgnoreCase) == 0)
		{
			return true;
		}
		return false;
	}
}
