#pragma once

#include "SAXContentHandlerImpl.h"
#include <string>

#include "WindowData.h"
#include "TestResults.h"

class LogParser : public SAXContentHandlerImpl
{
private:
	static const int defaultMsgDelay = 500;
	WindowData * currentWindow;
	WindowData * currentParent;

	int msgType;
	LPARAM lParam;
	WPARAM wParam;

	boolean useDefaultDelay;
	int delay;

	void sendMessage(HWND hwnd);

	_TCHAR * runCommand;
	_TCHAR * workingPath;
	unsigned int startupTime;
	HANDLE hProcess;

	std::wstring sessionId;
	RESULT result;
	unsigned int currentMessage;

	TestResults * results;

	std::wstring expectedValue;
	std::wstring actualFile;
	std::wstring expectedFile;

public:
	LogParser(_TCHAR * runCommand, unsigned int startupChar, TestResults * results, bool useDefaultDelay = false);
	~LogParser(void);

	virtual HRESULT STDMETHODCALLTYPE startElement( 
			wchar_t __RPC_FAR *pwchNamespaceUri,
			int cchNamespaceUri,
			wchar_t __RPC_FAR *pwchLocalName,
			int cchLocalName,
			wchar_t __RPC_FAR *pwchRawName,
			int cchRawName,
			MSXML2::ISAXAttributes __RPC_FAR *pAttributes);

	virtual HRESULT STDMETHODCALLTYPE endElement( 
			wchar_t __RPC_FAR *pwchNamespaceUri,
			int cchNamespaceUri,
			wchar_t __RPC_FAR *pwchLocalName,
			int cchLocalName,
			wchar_t __RPC_FAR *pwchRawName,
			int cchRawName);

	std::wstring GetAttributeValue(MSXML2::ISAXAttributes __RPC_FAR *pAttributes,
							   std::wstring name, std::wstring defvalue);


	int getDefaultMsgDelay();

	void setWorkingPath(TCHAR * workingPath);
};
