// XmlProjectPostGen.cpp: implementation of the CXmlProjectPostGen class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AsCfgBuilder.h"
#include "XmlProjectPostGen.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CXmlProjectPostGen::CXmlProjectPostGen()
{
	SetDefaults();
}

CXmlProjectPostGen::~CXmlProjectPostGen()
{

}

void CXmlProjectPostGen::SetActionId(enGeneratorAction actionId)
{
	actionId_ = actionId;
}

enGeneratorAction CXmlProjectPostGen::GetActionId() const
{
	return actionId_;
}

void CXmlProjectPostGen::SetConfigId(enGeneratorConfig configId)
{
	configId_ = configId;
}

enGeneratorConfig CXmlProjectPostGen::GetConfigId() const
{
	return configId_;
}

void CXmlProjectPostGen::SetTestProjectActionId(enTestProjectAction actionId)
{
	testProjectActionId_ = actionId;
}

enTestProjectAction CXmlProjectPostGen::GetTestProjectActionId() const
{
	return testProjectActionId_;
}

void CXmlProjectPostGen::SetDefaults()
{
	actionId_ = enGeneratorAction_GenerateAndCompile;
	configId_ = enGeneratorConfig_All;
	testProjectActionId_ = enTestProjectAction_None;
}

void CXmlProjectPostGen::Clear()
{}

bool CXmlProjectPostGen::BuildFromXml(IXMLDOMNode* node)
{
	Clear();
	
	ExtractMemberNode(node, _T("GeneratorActionId"), (int&)actionId_);
	ExtractMemberNode(node, _T("ConfigurationId"), (int&)configId_);
	ExtractMemberNode(node, _T("TestProjectActionId"), (int&)testProjectActionId_);

	return true;
}

bool CXmlProjectPostGen::AppendToDOMDocument(IXMLDOMDocument2* xmlDoc, IXMLDOMElement* parentElement)
{
	IXMLDOMElement* newElement;
	HRESULT hr;

	hr = xmlDoc->createElement(CComBSTR((const TCHAR*)GetXmlNodeName()), &newElement);
   
	AppendMemberNode(_T("GeneratorActionId"), actionId_, newElement, xmlDoc);
	AppendMemberNode(_T("ConfigurationId"), configId_, newElement, xmlDoc);
	AppendMemberNode(_T("TestProjectActionId"), testProjectActionId_, newElement, xmlDoc);

	if (parentElement)
		hr = parentElement->appendChild(newElement, NULL);
	else
		hr = xmlDoc->appendChild(newElement, NULL);

	return true;
}
