using System;

namespace QC.QSPRAutomation.Internal;

public class RemoteableObject : MarshalByRefObject
{
	public ClearLogDelegate clearLogDelegate;

	public AppendToLogDelegate appendToLogDelegate;

	public SendMenuMessageToQSPRDelegate sendMenuMessageToQSPRDelegate;

	public SendSpecialMessageToQSPRDelegate sendSpecialMessageToQSPRDelegate;

	public SetGlobalVariableDelegate setGlobalVariableDelegate;

	public GetGlobalVariableDelegate getGlobalVariableDelegate;

	public GetTestTreeStatusDelegate getTestTreeStatusDelegate;

	public SetConfigInfoDelegate setConfigInfoDelegate;

	public PingDelegate pingDelegate;

	public SendMessageFromQSPRDelegate sendMessageFromQSPRDelegate;

	public SendDebugMessageFromQSRPDelegate sendDebugMessageFromQSPRDelegate;

	public GlobalVaiablesModifiedDelegate globalVariableModifiedDelegate;

	private object localLock = new object();

	public TestMessageReceivedDelegate TestMessageReceived { get; set; }

	public void ClearLog()
	{
		if (clearLogDelegate != null)
		{
			clearLogDelegate();
		}
		else
		{
			AppendToLog("clearLogDelegate is null");
		}
	}

	public string Ping(string message)
	{
		if (pingDelegate != null)
		{
			return pingDelegate(message);
		}
		return null;
	}

	public void AppendToLog(string logMessage)
	{
		if (appendToLogDelegate != null)
		{
			appendToLogDelegate(logMessage);
		}
	}

	public void SendMenuMessageToQSPR(string message)
	{
		if (sendMenuMessageToQSPRDelegate != null)
		{
			sendMenuMessageToQSPRDelegate(message);
		}
		else
		{
			AppendToLog("sendMenuMessageToQSPRDelegate is null");
		}
	}

	public object SendSpecialMessageToQSPR(string message, string additionalInformation)
	{
		object result = null;
		if (sendSpecialMessageToQSPRDelegate != null)
		{
			if (message == "Exit")
			{
				sendSpecialMessageToQSPRDelegate.BeginInvoke(message, additionalInformation, null, null);
			}
			else
			{
				result = sendSpecialMessageToQSPRDelegate(message, additionalInformation);
			}
		}
		else
		{
			AppendToLog("sendSpecialMessageToQSPRDelegate is null");
		}
		return result;
	}

	public bool SetGlobalVariable(string variableName, string value)
	{
		if (setGlobalVariableDelegate != null)
		{
			return setGlobalVariableDelegate(variableName, value);
		}
		AppendToLog("setGlobalVariableDelegate is null");
		return false;
	}

	public string GetGlobalVariable(string variableName)
	{
		if (getGlobalVariableDelegate != null)
		{
			return getGlobalVariableDelegate(variableName);
		}
		AppendToLog("getGlobalVariableDelegate is null");
		return "";
	}

	public int GetTestTreeStatus()
	{
		if (getTestTreeStatusDelegate != null)
		{
			return getTestTreeStatusDelegate();
		}
		AppendToLog("getTestTreeStatusDelegate is null");
		return -99;
	}

	public void SetConfigInfo(bool clearPrevious, string variableName, string value, bool includeInTestResults)
	{
		if (setConfigInfoDelegate != null)
		{
			setConfigInfoDelegate(clearPrevious, variableName, value, includeInTestResults);
		}
		else
		{
			AppendToLog("setConfigInfoDelegate is null");
		}
	}

	public void SendDebugMessageFromQSPR(string windowName, string text, int traceLevel)
	{
		if (sendDebugMessageFromQSPRDelegate != null)
		{
			sendDebugMessageFromQSPRDelegate(windowName, text, traceLevel);
		}
		else
		{
			AppendToLog("sendDebugMessageFromQSPRDelegate is null");
		}
	}

	public void GlobalVariableModified(string gvName, string gvValue)
	{
		if (globalVariableModifiedDelegate != null)
		{
			globalVariableModifiedDelegate(gvName, gvValue);
		}
		else
		{
			AppendToLog("globalVaiablesModifiedDelegate is null");
		}
	}

	public void HandleTestMessageReceived(object message)
	{
		if (TestMessageReceived != null)
		{
			TestMessageReceived(message);
		}
	}

	public void SendMessageFromQSPR(string serializedMessage)
	{
		if (sendMessageFromQSPRDelegate != null)
		{
			sendMessageFromQSPRDelegate(serializedMessage);
		}
		else
		{
			AppendToLog("sendMessageFromQSPRDelegate is null");
		}
	}

	public override object InitializeLifetimeService()
	{
		return null;
	}
}
