Example #1
0
STDMETHODIMP CDataConnector::RequestModelEHTTPConfigAndData(BSTR Id, BSTR IpAddress, BSTR ConfigPath, BSTR DataPath, BSTR Model, LONG* ConfigHandler, LONG* DataHandler)
{
	HRESULT hr = E_OUTOFMEMORY;

	IXMLElementHandler* ConfigElementHandler = static_cast<IXMLElementHandler*>((IXMLElementHandler*)ConfigHandler);
	IXMLElementHandler* DataElementHandler = static_cast<IXMLElementHandler*>((IXMLElementHandler*)DataHandler);

	CComBSTR bstrIpAddress(IpAddress);

	hr = RequestMockSensorsXML(Id, ConfigElementHandler, VARIANT_FALSE);
	hr = RequestMockSensorsXML(Id, DataElementHandler, VARIANT_TRUE);
	
	if(FAILED(hr))
	{
		if(bstrIpAddress.Length() != 0)
		{
			CComBSTR bstrConfig(L"");
			hr = RequestHTTP(IpAddress, ConfigPath, &bstrConfig);

			if(FAILED(hr))
				return hr;

			CComBSTR bstrData(L"");
			hr = RequestHTTP(IpAddress, DataPath, &bstrData);

			if(FAILED(hr))
				return hr;

			CComBSTR bstrConfigXML(L"");
			CComBSTR bstrDataXML(L"");

			hr = ConvertHTTPDataToXMLConfigAndData(Model, bstrConfig.Copy(), &bstrConfigXML, bstrData.Copy(), &bstrDataXML);

			if(FAILED(hr))
				return hr;

			VARIANT varVal;
			VariantInit(&varVal);
			varVal.vt = VT_BSTR;
			varVal.bstrVal = bstrConfigXML.Copy();

			hr = RequestXML(varVal, ConfigElementHandler);

			if(FAILED(hr))
				return hr;

			VariantInit(&varVal);
			VariantClear(&varVal);
			varVal.vt = VT_BSTR;
			varVal.bstrVal = bstrDataXML.Copy();
			hr = RequestXML(varVal, DataElementHandler);
		}
		else
		{
			hr = E_OUTOFMEMORY;
		}
	}

	return hr;
}
Example #2
0
/*
	Function name	: CXML::CreateNodeText
	Description	    : This helper function Creates a text node as a child node of the pNode.
	Return type		: bool 
	Argument        : IXMLDOMNode **pNode
	Argument        : CString &rcsNodeText
	Tested			: Ok
*/
bool CXML::CreateNodeText(IXMLDOMNode **pNode,CString &rcsNodeText)
{
	IXMLDOMText  * pTextNode = NULL;

	if(!(*pNode))
		return false;

	_bstr_t bstrData(rcsNodeText);

	m_hr = m_pXMLDoc->createTextNode(bstrData,&pTextNode);
	if(!SUCCEEDED(m_hr) || !pTextNode)
		return false;
	
	IXMLDOMNode * pINewNode = NULL;
	m_hr = (*pNode)->appendChild(pTextNode,&pINewNode);
	pTextNode->Release();
	if(!SUCCEEDED(m_hr) || !pINewNode)
		return false;

	pINewNode->Release();
	return true;
}
Example #3
0
/*
	Function name	: CXML::ReplaceNodeText
	Description	    : This Helper function replaces the existing text with the given text of 
					: the given node. 
	Return type		: bool 
	Argument        : IXMLDOMNode **pNode
	Argument        : CString &rcsNodeText
	Tested			: 
*/
bool CXML::ReplaceNodeText(IXMLDOMNode **pNode,CString &rcsNodeText)
{
	IXMLDOMText  * pTextNode = NULL;
	if(!(*pNode))
		return false;

	IXMLDOMNode * pTempNode = NULL;
	DOMNodeType nodeType;
	IXMLDOMNode * pINewNode = NULL;
	IXMLDOMNode * pIOldNode = NULL;
	IXMLDOMNodeList * pChildList = NULL;
	long nLen = 0,i=0;


	_bstr_t bstrData(rcsNodeText);

	m_hr = m_pXMLDoc->createTextNode(bstrData,&pTextNode);
	if(!SUCCEEDED(m_hr) || !pTextNode)
		goto on_Error;	


	m_hr = (*pNode)->get_childNodes(&pChildList);
	if(!SUCCEEDED(m_hr) || !pChildList)
		goto on_Error;
	
	m_hr = pChildList->get_length(&nLen);
	if(!SUCCEEDED(m_hr))
		goto on_Error;

	if(nLen == 0)	// no childs, if the tag is empty
	{
		bool bRet = CreateNodeText(pNode,rcsNodeText);
		if(pChildList)
			pChildList->Release();
		if(pTextNode)
			pTextNode->Release();
		return bRet;		
	}

	for(i =0; i< nLen;++i)
	{
		m_hr = pChildList->nextNode(&pTempNode);
		if(!SUCCEEDED(m_hr))
			goto on_Error;

		m_hr = pTempNode->get_nodeType(&nodeType);
		if(!SUCCEEDED(m_hr))
			goto on_Error;

		if(nodeType == NODE_TEXT)
			break;

		if(pTempNode)
		{
			pTempNode->Release();
			pTempNode = NULL;
		}
	}

	m_hr = (*pNode)->replaceChild(pTextNode,pTempNode,&pINewNode);
	if(!SUCCEEDED(m_hr) || !pINewNode)
			goto on_Error;

	if(pChildList)
		pChildList->Release();
	if(pTextNode)
		pTextNode->Release();
	if(pINewNode)
		pINewNode->Release();
	if(pTempNode)
		pTempNode->Release();

	return true;


on_Error:	// Release all the References

	if(pChildList)
		pChildList->Release();
	if(pTextNode)
		pTextNode->Release();
	if(pINewNode)
		pINewNode->Release();
	if(pTempNode)
		pTempNode->Release();
	
	return false; 
}
Example #4
0
/*
	 Function name		: CXML::CreateElement
	 Description	    : This function create an element node set it as the current Node
						: with attributes and value and the text supplied 
	 Return type		: bool 
	 Argument			: IXMLDOMNode **ppRemoveNode
 */	
bool CXML::CreateElement(CString csTagName,LPCTSTR lpszText,char ** ppAttributes,char ** ppValues,int nNoOfAttributes,bool bSetAsCurNode)
{
	IXMLDOMNode * pNode = NULL;
	if(csTagName.IsEmpty())
		return false;

	if(!m_pICurrentNode)
		return false;

	_variant_t vtNodeType((long)NODE_ELEMENT);
	_bstr_t bstrName(csTagName);
	_bstr_t bstrNameSpace("");

	m_hr = m_pXMLDoc->createNode(vtNodeType,bstrName,bstrNameSpace,&pNode);
	if(!SUCCEEDED(m_hr))
		return false;

	if(m_pINewElement)
	{
		m_pINewElement->Release();
		m_pINewElement = NULL;
	}


	if(!AddNode(&m_pICurrentNode,&pNode,&m_pINewElement,NODE_ELEMENT))
	{
		pNode->Release();
		return false;
	} 

	if(!m_pINewElement)
		return false;

	if(lpszText)
	{
		_bstr_t bstrData(lpszText);

		m_hr = pNode->put_text(bstrData);
		if(!SUCCEEDED(m_hr))
		{
			pNode->Release();
			return false;
		}
	}

	pNode->Release();

	if(nNoOfAttributes && ppAttributes && ppValues )
	{
		for(int i = 0;i<nNoOfAttributes;++i)
		{
			if(!CreateAttributeNode(&m_pINewElement,ppAttributes[i],ppValues[i]))
				return false;
		}
	}

	if(bSetAsCurNode)
	{
		if(m_pICurrentNode)
		{
			m_pICurrentNode->Release();
			m_pICurrentNode = NULL;

		}
		m_pICurrentNode = m_pINewElement;
		m_pICurrentNode->AddRef();
	}
	return true;
}