示例#1
0
/******************************************************************************
Function Name  :  nParseTSFile
Input(s)       :  CString omstrTSFile
Output         :  INT
Functionality  :  Load the omStrTSFille
Member of      :  CTestSetupEntity
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :
Codetag        : CS002
******************************************************************************/
INT CTestSetupEntity::nParseTSFile(CString omstrTSFile)
{
    MSXML2::IXMLDOMDocumentPtr pIDOMDoc;
    HRESULT hr = pIDOMDoc.CreateInstance(L"Msxml2.DOMDocument");

    if ( FAILED(hr) )
    {
        throw "Unable to create XML parser object";
    }

    if(PathFileExists(omstrTSFile) == FALSE)
    {
        return ERR_PATH_INCORRECT;
    }

    //Create A TestSetup DOM document
    CComVariant varFileName((LPCSTR)omstrTSFile);

    try
    {
        pIDOMDoc->load(varFileName);
        //GetTest Setup Title
        MSXML2::IXMLDOMNodePtr pIDOMTiltleNode;
        _bstr_t bstrNodeName = def_STR_TSNODE_NAME;
        CComVariant NodeValue;
        pIDOMTiltleNode = pIDOMDoc->selectSingleNode(bstrNodeName);
        MSXML2::IXMLDOMNamedNodeMapPtr pDOMTCAtrributes;
        pDOMTCAtrributes = pIDOMTiltleNode->Getattributes();
        MSXML2::IXMLDOMNodePtr pIDOMChildNode;
        //bstrNodeName = def_STR_TSATTRIB_TITLE;
        bstrNodeName.Assign(SysAllocString(CT2W(def_STR_TSATTRIB_TITLE)));
        pIDOMChildNode = pDOMTCAtrributes->getNamedItem(bstrNodeName);
        pIDOMChildNode->get_nodeTypedValue(&NodeValue);
        m_omstrTestSetupTitle = strCopyBSTRToCString(NodeValue);
        pIDOMChildNode.Release();
        //Get Description
        //bstrNodeName = def_STR_TSDESCRIPTION;
        bstrNodeName.Assign(SysAllocString(CT2W(def_STR_TSDESCRIPTION)));
        MSXML2::IXMLDOMNodePtr pIDOMDescriptionNode = pIDOMDoc->selectSingleNode(bstrNodeName);
        pIDOMDescriptionNode->get_nodeTypedValue(&NodeValue);
        m_omstrDescription = strCopyBSTRToCString(NodeValue);
        //Get Header Node
        //bstrNodeName = def_STR_TSHEADER;
        bstrNodeName.Assign(SysAllocString(CT2W(def_STR_TSHEADER)));
        MSXML2::IXMLDOMNodePtr pIDOMHeaderNode = pIDOMDoc->selectSingleNode(bstrNodeName);
        nLoadHeader(pIDOMHeaderNode);
        pIDOMHeaderNode.Release();
        //Get TestCases List
        //bstrNodeName = def_STR_TSTCLIST;
        bstrNodeName.Assign(SysAllocString(CT2W(def_STR_TSTCLIST)));
        MSXML2::IXMLDOMNodePtr pIDOMTSNode = pIDOMDoc->selectSingleNode(bstrNodeName);
        GetData(pIDOMTSNode);
    }
    catch(...)
    {
        return S_FALSE;
    }

    return S_OK;
}
示例#2
0
CStdString SmartTagParser::GetTextForSmartTagName(const CStdString & SmartTagName)
{
    if (m_spXMLDom == NULL)
    {
        CStdString msg;
        msg.Format(_T("SmartTagParser::GetTextForSmartTagName - The XML document pointer is null."));
        throw Workshare::NullReferenceException(msg);
    }

    CComBSTR nodeText = _T("//");
    nodeText += GetNamespacePrefix();
    nodeText += _T(":");
    nodeText += SmartTagName;

    MSXML2::IXMLDOMNodePtr pNode = m_spXMLDom->selectSingleNode(nodeText.m_str);

    if (pNode == NULL)
    {
        CStdString msg;
        msg.Format(_T("SmartTagParser::GetTextForSmartTagName - Failed to get node (%s) from the XML"), nodeText);
        throw Workshare::Exception(msg);
    }

    CStdString sValue = pNode->text;

    if (pNode)
    {
        pNode.Release();
    }

    return sValue;
}
示例#3
0
// 删除子结点
int CBpXMLNode::DeleteChild(const IBpXMLNode *pNodeChild)
{
	if (m_pDOMNode == NULL || pNodeChild == NULL || ((CBpXMLNode*)pNodeChild)->m_pDOMNode == NULL)
		return XML_ERROR;

	try
	{
		MSXML2::IXMLDOMNodePtr pTempNode = m_pDOMNode->removeChild(((CBpXMLNode*)pNodeChild)->m_pDOMNode);
		if (pTempNode == NULL)
			return XML_ERROR;

		pTempNode->Release();
	}
	catch (...)	
	{
		return XML_ERROR;	
	}
	return XML_OK;
}
示例#4
0
// 根据给定的名字,创建Element节点,并将其附加为当前节点的子节点
IBpXMLNode* CBpXMLNode::AppendNewElementChild(const wchar_t *szElementName)
{
	if (m_pDOMNode == NULL)	
		return NULL;

	MSXML2::IXMLDOMDocument	*pDOMDocPtr = NULL;
	m_pDOMNode->get_ownerDocument(&pDOMDocPtr);
	if (pDOMDocPtr == NULL)
		return NULL;

	// 创建Element
	VARIANT vtTemp;
	vtTemp.vt = VT_I2;
	vtTemp.iVal = 1;	

	MSXML2::IXMLDOMNodePtr pDOMNodeCreated = pDOMDocPtr->createNode(vtTemp, _bstr_t(szElementName), L"");
	if (pDOMNodeCreated == NULL)
		return NULL;

	// 用来指向被附加后的节点
	MSXML2::IXMLDOMNodePtr pNodeAppend = NULL;
	try
	{
		pNodeAppend = m_pDOMNode->appendChild(pDOMNodeCreated);
	}
	catch (...)		
	{
		return NULL;	
	}

	if (pNodeAppend == NULL)
	{
		pDOMNodeCreated->Release();
		return NULL;
	}

	CBpXMLNode* pElemCreated = new CBpXMLNode;
	pElemCreated->m_pDOMNode = pNodeAppend;
	return pElemCreated;
}
/******************************************************************************
Function Name  :  GetData
Input(s)       :  MSXML2::IXMLDOMNodePtr& pIDomNode
Output         :  HRESULT
Functionality  :   
Member of      :  CWaitEntity
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :  
******************************************************************************/
HRESULT CWaitEntity::GetData(MSXML2::IXMLDOMNodePtr& pIDomNode)
{
    _bstr_t bstrNodeName;
    CComVariant NodeValue;	
    MSXML2::IXMLDOMNamedNodeMapPtr pDOMWaitAtrributes;
    pDOMWaitAtrributes = pIDomNode->Getattributes();
    MSXML2::IXMLDOMNodePtr pIDOMChildNode;

    //bstrNodeName = L"purpose";
	bstrNodeName.Assign(SysAllocString(CT2W("purpose")));
    pIDOMChildNode = pDOMWaitAtrributes->getNamedItem(bstrNodeName);
    pIDOMChildNode->get_nodeTypedValue(&NodeValue);		
	m_ouData.m_omPurpose = strCopyBSTRToCString(NodeValue);
    
    pIDomNode->get_nodeTypedValue(&NodeValue);
	CString strTemp;	
	strTemp = strCopyBSTRToCString(NodeValue);
    //W4 Removal - Type Conversion No problem.
    m_ouData.m_ushDuration = (USHORT)atoi((LPCSTR)strTemp);
    pIDOMChildNode.Release();
    pDOMWaitAtrributes.Release();
    return S_OK;
}
示例#6
0
MSXML2::IXMLDOMNodePtr CXmlBase::CreateXmlTitle(MSXML2::IXMLDOMDocument2Ptr pDoc)
{
	MSXML2::IXMLDOMProcessingInstructionPtr pi = NULL;
	MSXML2::IXMLDOMNodePtr pNode = NULL;

	if (pDoc == NULL) return NULL;
	try
	{
		pi = pDoc->createProcessingInstruction(_T("xml")
			, _T("version=\"1.0\" encoding=\"UTF-8\""));
		if (pi == NULL) return NULL;
		
		pNode = pi;
		if (NULL == (pNode = pDoc->appendChild(pNode)))
		{
			pi.Release();
			pNode.Release();
			return NULL;
		}
		pi.Release();
		//pNode.Release();
	}
	catch(_com_error &e)
	{
		CString str;
		str.Format(_T("创建xml头发生异常。\r\nComError:\r\n%s")
			, e.ErrorMessage());
		::MessageBox( NULL,str, g_sAppTitle, MB_OK|MB_ICONERROR);
		return NULL;
	}
	catch(...)
	{
		return NULL;
	}
	return pNode;
}
/******************************************************************************
Function Name  :  nLoadHeader
Input(s)       :  MSXML2::IXMLDOMNodePtr& pHeaderDOMNode
Output         :  INT
Functionality  :  Retrives the Header info 
Member of      :  CTestSetupEntity
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :  
Codetag        :  
******************************************************************************/
INT CTestSetupEntity::nLoadHeader(MSXML2::IXMLDOMNodePtr& pHeaderDOMNode)
{
   // CComPtr<IXMLDOMNode> pHeaderDOMNode;
    MSXML2::IXMLDOMNodeListPtr pXMLDOMInfoList;
    MSXML2::IXMLDOMNodePtr pInfoNode;
    MSXML2::IXMLDOMNodePtr pInfoCategoryNode;
    MSXML2::IXMLDOMNodePtr pInfoValueNode;
    _bstr_t bstrNodeName = "info";
    CComVariant NodeValue;		
    pXMLDOMInfoList = pHeaderDOMNode->selectNodes(bstrNodeName);

    LONG lCount = 0;
    pXMLDOMInfoList->get_length(&lCount);
    SInfo ouTempSInfo;
    for(int i = 0; i<lCount; i++)
    {
        pInfoNode = pXMLDOMInfoList->Getitem(i);

        //bstrNodeName = def_STR_CATEGORY_NODE;
		bstrNodeName.Assign(SysAllocString(CT2W(def_STR_CATEGORY_NODE)));
        pInfoCategoryNode = pInfoNode->selectSingleNode(bstrNodeName);
        pInfoCategoryNode->get_nodeTypedValue(&NodeValue);		
				
		ouTempSInfo.m_omCategory = strCopyBSTRToCString(NodeValue);
		
        pInfoCategoryNode.Release();
        
        //bstrNodeName = def_STR_VALUE_NODE;
		bstrNodeName.Assign(SysAllocString(CT2W(def_STR_VALUE_NODE)));
        pInfoCategoryNode = pInfoNode->selectSingleNode(bstrNodeName);
        pInfoCategoryNode->get_nodeTypedValue(&NodeValue);			
		ouTempSInfo.m_omValue = strCopyBSTRToCString(NodeValue);
        pInfoCategoryNode.Release();
        
        pInfoNode.Release();


        if(ouTempSInfo.m_omCategory == def_STR_MODULENAME)
        {
            m_ouTestSetupHeader.m_sModuleName.m_omCategory = ouTempSInfo.m_omCategory;
            m_ouTestSetupHeader.m_sModuleName.m_omValue = ouTempSInfo.m_omValue;
        }
        if(ouTempSInfo.m_omCategory == def_STR_ENGINEERNAME)
        {
            m_ouTestSetupHeader.m_sEngineerInfo1.m_omCategory = ouTempSInfo.m_omCategory;
            m_ouTestSetupHeader.m_sEngineerInfo1.m_omValue = ouTempSInfo.m_omValue;
        }
        if(ouTempSInfo.m_omCategory == def_STR_ENGINERROLE)
        {
            m_ouTestSetupHeader.m_sEngineerInfo2.m_omCategory = ouTempSInfo.m_omCategory;
            m_ouTestSetupHeader.m_sEngineerInfo2.m_omValue = ouTempSInfo.m_omValue;
        }
        if(ouTempSInfo.m_omCategory == def_STR_VERSION)
        {
            m_ouTestSetupHeader.m_sVersion.m_omCategory = ouTempSInfo.m_omCategory;
            m_ouTestSetupHeader.m_sVersion.m_omValue = ouTempSInfo.m_omValue;
        }
    }
//Taking Database
    
    //bstrNodeName = def_STR_LISTOFDB;
	bstrNodeName.Assign(SysAllocString(CT2W(def_STR_LISTOFDB)));
    pInfoNode = pHeaderDOMNode->selectSingleNode(bstrNodeName);
    pInfoNode->get_nodeTypedValue(&NodeValue);		
	m_ouTestSetupHeader.m_omDatabasePath = strCopyBSTRToCString(NodeValue);
    //Set The Database Path
    SetDatabaseFile(m_ouTestSetupHeader.m_omDatabasePath);
    pInfoNode.Release();

    //bstrNodeName = def_STR_REPORT_FORMAT;
	bstrNodeName.Assign(SysAllocString(CT2W(def_STR_REPORT_FORMAT)));
    pInfoNode = pHeaderDOMNode->selectSingleNode(bstrNodeName);
    pInfoNode->get_nodeTypedValue(&NodeValue);
	CString omStrExt;	
	omStrExt = strCopyBSTRToCString(NodeValue);
    pInfoNode.Release();

    
    if(omStrExt == "HTM")
    {
        m_ouTestSetupHeader.m_sReportFile.m_eType = HTM;
    }
    else
    {
        m_ouTestSetupHeader.m_sReportFile.m_eType = TXT;
    }

    //bstrNodeName = def_STR_REPORT_PATH;
	bstrNodeName.Assign(SysAllocString(CT2W(def_STR_REPORT_PATH)));
    pInfoNode = pHeaderDOMNode->selectSingleNode(bstrNodeName);
    pInfoNode->get_nodeTypedValue(&NodeValue);		
	m_ouTestSetupHeader.m_sReportFile.m_omPath = strCopyBSTRToCString(NodeValue);
    pInfoNode.Release();
    
    


    //bstrNodeName = def_STR_REPORT_TIMEMODE;
	bstrNodeName.Assign(SysAllocString(CT2W(def_STR_REPORT_TIMEMODE)));
    pInfoNode = pHeaderDOMNode->selectSingleNode(bstrNodeName);
    pInfoNode->get_nodeTypedValue(&NodeValue);
	CString strTemp;	
	strTemp = strCopyBSTRToCString(NodeValue);
    if(strTemp == "ABS")
    {
        m_ouTestSetupHeader.m_sReportFile.m_eTimeMode = ABS;
    }
    else                    //Default
    {
        m_ouTestSetupHeader.m_sReportFile.m_eTimeMode = REL;
    }
    pInfoNode.Release();


    //bstrNodeName = def_STR_BUS_TYPE;
	bstrNodeName.Assign(SysAllocString(CT2W(def_STR_BUS_TYPE)));
    pInfoNode= pHeaderDOMNode->selectSingleNode(bstrNodeName);
    pInfoNode->get_nodeTypedValue(&NodeValue);		
	strTemp = strCopyBSTRToCString(NodeValue);

    if(strTemp == "CAN")
    {
        m_ouTestSetupHeader.m_eBus = CAN;
    }

    pInfoNode.Release();
    
    return 0;
}
/******************************************************************************
Function Name  :  GetData
Input(s)       :  MSXML2::IXMLDOMNodePtr& pIDomNode
Output         :  HRESULT
Functionality  :  Fills the datastructure from the XML node 
Member of      :  CTestCaseEntity
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :  
******************************************************************************/
HRESULT CTestCaseEntity::GetData(MSXML2::IXMLDOMNodePtr& pIDomNode)
{
//Getting Attributes
    _bstr_t bstrNodeName;
    CComVariant NodeValue;	
    MSXML2::IXMLDOMNamedNodeMapPtr pDOMTCAtrributes;
    pDOMTCAtrributes = pIDomNode->Getattributes();
    MSXML2::IXMLDOMNodePtr pIDOMChildNode;

    //bstrNodeName = L"identifier";
	bstrNodeName.Assign(SysAllocString(CT2W("identifier")));
    pIDOMChildNode = pDOMTCAtrributes->getNamedItem(bstrNodeName);
    pIDOMChildNode->get_nodeTypedValue(&NodeValue);		
	m_ouData.m_omID = strCopyBSTRToCString(NodeValue);
    pIDOMChildNode.Release();
    
    //bstrNodeName = L"title";
	bstrNodeName.Assign(SysAllocString(CT2W("title")));
    pIDOMChildNode = pDOMTCAtrributes->getNamedItem(bstrNodeName);
    pIDOMChildNode->get_nodeTypedValue(&NodeValue);		
	m_ouData.m_omTitle = strCopyBSTRToCString(NodeValue);
    pIDOMChildNode.Release();

    //bstrNodeName = L"exp_handler";
	bstrNodeName.Assign(SysAllocString(CT2W("exp_handler")));
    pIDOMChildNode = pDOMTCAtrributes->getNamedItem(bstrNodeName);
    pIDOMChildNode->get_nodeTypedValue(&NodeValue);
	CString strTemp;	
	strTemp = strCopyBSTRToCString(NodeValue);
    pIDOMChildNode.Release();
    
    if(strTemp == "CONTINUE")
    {
        m_ouData.m_eExcpAction = CONTINUE;
    }
    else
    {
        m_ouData.m_eExcpAction = EXIT;
    }

//Getting Testcases
    MSXML2::IXMLDOMNodeListPtr pDOMChildList = pIDomNode->GetchildNodes();
    LONG lCount;
    pDOMChildList->get_length(&lCount);
    CComBSTR NodeName;
    for(int i = 0;i < lCount; i++)
    {
        pIDOMChildNode = pDOMChildList->Getitem(i);
        pIDOMChildNode->get_nodeName(&NodeName);        
		
        CBaseEntityTA *odpBaseEntity = NULL;
		if(NodeName == def_STR_SEND_NODE)
        {
            odpBaseEntity = new CSendEntity();
        }
        else if(NodeName == def_STR_VERIFY_NODE)
        {
            odpBaseEntity = new CVerifyEntity();
        }
        else if(NodeName == def_STR_WAIT_NODE)
        {
            odpBaseEntity = new CWaitEntity();
        }
        else if(NodeName == def_STR_REPLAY_NODE)
        {
            odpBaseEntity = new CReplayEntity();
        }
        else if(NodeName == def_STR_VERIFYRES_NODE)
        {
            odpBaseEntity = new CVerifyResponse();
        }
        if(odpBaseEntity == NULL)
        {
            //TODO::return a correct value
            return -1;
        }
        odpBaseEntity->GetData(pIDOMChildNode);
        m_ouData.m_odTAEntityList.AddTail(odpBaseEntity);
        //pIDOMChildNode->Release();
    }
    return S_OK;
}