Exemplo n.º 1
0
void ElementRatings::LogMetadataElements(const Metawall::IMWMetadataElementsPtr spElements, const CStdString& message)
{
	try
	{
		if(!Workshare::Logging::ShouldLogInfo())
			return;

		CStdString sMessage(_T("Selected Elements. "));
		sMessage.append(message);

		for(long index = 1; index <= spElements->Count; index++)
		{	
			Metawall::IMWMetadataElementPtr spElement(spElements->Item[index]);
			CStdString sEnabled = (VARIANT_FALSE != spElement->Enabled) ? _T("1") : _T("0");
			sMessage.AppendFormat(_T("\n:%s = %s"), CStdString(spElement->Name).c_str(), sEnabled.c_str());
		}
		LOG_WS_INFO(sMessage.c_str());	
	}
	catch(_com_error const& e)
	{
		LOG_WS_ERROR_RESULT(e);
	}
	catch(...)
	{
		LOG_WS_ERROR(_T("Failed to log. Unknown exception"));	
	}
}
CString CItemPageAnalyzeBase::_GetCollectionItemValue(CComQIPtr<IHTMLElementCollection>& spChildElements, 
													  INT index, ItemValueType valueType, BOOL bTrim /* = FALSE */)
{
	HRESULT hr = E_FAIL;

	CString strResult;
	CComVariant varIndex(index);
	CComPtr<IDispatch> spDispValue;

	COM_VERIFY(spChildElements->item(varIndex, varIndex, &spDispValue));
	CComQIPtr<IHTMLElement>	spElement(spDispValue);
	if (spElement)
	{
		CComBSTR bstrValue;

		switch (valueType)
		{
		case ivtInnerText:
			COM_VERIFY(spElement->get_innerText(&bstrValue));
			strResult = OLE2CT(bstrValue);
			break;
		case ivtToString:
			COM_VERIFY(spElement->toString(&bstrValue));
			strResult = OLE2CT(bstrValue);
			break;
		default:
			FTLASSERT(FALSE);
			break;
		}
	}
	if (bTrim)
	{
		strResult.Trim();
	}
	return strResult;
}
void CPageEvents::OnOK() 
{
  // Save any changes made to the currently-selected node's attributes
  UpdateNodeFromItem(m_lParamSelected);

  // Inspect the <Event> nodes of the document
  if (NULL != m_spXMLDoc)
  {
    // Get all of the <Event> nodes in the document
    IXMLDOMNodeListPtr spNodeList;
    VERIFY(SUCCEEDED(m_spXMLDoc->getElementsByTagName(m_bstrEvent,
      &spNodeList)));

    // Process each node
    IXMLDOMNodePtr spNode;
    do  
    {
      // Get the next node of the child list
      VERIFY(SUCCEEDED(spNodeList->nextNode(&spNode)));
      if (NULL != spNode)
      {
        // Query for the IXMLDOMElement interface
        IXMLDOMElementPtr spElement(spNode);
        ASSERT(NULL != spElement);

        // Get the event id attribute
        CComVariant varEventID;
        spElement->getAttribute(m_bstrID, &varEventID);
        VERIFY(SUCCEEDED(varEventID.ChangeType(VT_I4)));
        AGCEventID idEventBegin = (AGCEventID)(V_UI4(&varEventID));
        AGCEventID idEventEnd = (AGCEventID)(idEventBegin + 1);

        // Get the LogAsNTEvent attribute
        IXMLDOMAttributePtr spAttrNT;
        if (S_OK == spElement->getAttributeNode(m_bstrLogAsNTEvent, &spAttrNT))
        {
          CComVariant varLog2NT;
          spAttrNT->get_value(&varLog2NT);
          VERIFY(SUCCEEDED(varLog2NT.ChangeType(VT_BOOL)));

          // Add this event id to the range, if it should be logged
          if (V_BOOL(&varLog2NT))
            m_spRangesNT->AddByValues(idEventBegin, idEventEnd);
        }

        // Get the LogAsDBEvent attribute
        IXMLDOMAttributePtr spAttrDB;
        if (S_OK == spElement->getAttributeNode(m_bstrLogAsDBEvent, &spAttrDB))
        {
          CComVariant varLog2DB;
          spAttrDB->get_value(&varLog2DB);
          VERIFY(SUCCEEDED(varLog2DB.ChangeType(VT_BOOL)));

          // Add this event id to the range, if it should be logged
          if (V_BOOL(&varLog2DB))
            m_spRangesDB->AddByValues(idEventBegin, idEventEnd);
        }
      }
    } while (NULL != spNode);

    // Set the enabled ranges of the event logger object
    VERIFY(SUCCEEDED(m_spEventLogger->put_EnabledNTEvents(m_spRangesNT)));
    VERIFY(SUCCEEDED(m_spEventLogger->put_EnabledDBEvents(m_spRangesDB)));
  }

  // Perform default processing
  CPropertyPage::OnOK();
}
HRESULT CPageEvents::AddXMLNodeToTree(IXMLDOMNode* pNode, HTREEITEM hParent)
{
  // Get the list of child nodes
  IXMLDOMNodeListPtr spChildren;
  RETURN_FAILED(pNode->get_childNodes(&spChildren));

  // Process each child node
  IXMLDOMNodePtr spChild;
  do  
  {
    // Get the next node of the child list
    RETURN_FAILED(spChildren->nextNode(&spChild));
    if (NULL != spChild)
    {
      // Get the child node's tagname
      int       iImage;
      CString     strType;
      CString     strID;
      bool        bIsGroup, bIsEvent;
      CComBSTR      bstrText;
      IXMLDOMElementPtr spElement(spChild);
      if (NULL != spElement)
      {
        CComBSTR bstrTagName;
        RETURN_FAILED(spElement->get_tagName(&bstrTagName));
        if (bstrTagName.Length())
        {
          // Accept the Event and EventGroup tag names
          if (0 == wcscmp(bstrTagName, m_bstrEvent))
          {
            bIsGroup = false;
            bIsEvent = true;
          }
          else if (0 == wcscmp(bstrTagName, m_bstrEventGroup))
          {
            bIsGroup = true;
            bIsEvent = false;
          }

          // Get the display attributes if this is a group or event node
          if (bIsGroup || bIsEvent)
          {
            // Get the type of the element
            CComBSTR bstrSeverity;
            GetElementSeverity(spElement, &bstrSeverity);
            iImage = ImageFromSeverity(bstrSeverity);
            strType = TypeFromSeverity(bstrSeverity);

            // Get the id of the element
            CComBSTR bstrID;
            GetElementID(spElement, &bstrID);
            strID = bstrID;

            // Get the name of the element
            RETURN_FAILED(GetElementDisplayName(spElement, &bstrText));
          }
        }
      }

      // Add the node to the tree and list controls
      if (bstrText.Length())
      {
        // Typecast the element pointer as an LPARAM
        IXMLDOMElement* pElement = spElement.Detach();
        LPARAM lParam = reinterpret_cast<LPARAM>(pElement);

        // Insert the element into the tree
        USES_CONVERSION;
        LPCTSTR pszText = OLE2CT(bstrText);
        UINT mask  = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
        HTREEITEM hItem = m_tree.InsertItem(mask, pszText, iImage, iImage,
          0, 0, lParam, hParent, TVI_LAST);

        // Insert the element into the list, if its not an <EventGroup>
        if (!bIsGroup)
        {
          int iItem = m_listEvents.GetItemCount();
          iItem = m_listEvents.InsertItem(LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM,
            iItem, strType, 0, 0, iImage, lParam);
          if (-1 != iItem)
          {
            // Keep a reference on the element pointer in the LPARAM
            pElement->AddRef();

            // Keep track of maximum widths
            int cx = m_listEvents.GetStringWidth(strType + "  ");
            m_cxMaxType = max(m_cxMaxType, cx);
            cx = m_listEvents.GetStringWidth(strID + "    ");
            m_cxMaxID = max(m_cxMaxID, cx);

            // Set the subitems
            m_listEvents.SetItem(iItem, 1, LVIF_TEXT, strID, 0, 0, 0, 0);
            m_listEvents.SetItem(iItem, 2, LVIF_TEXT, pszText, 0, 0, 0, 0);
          }
        }

        // Recurse into node, if it's a group
        if (bIsGroup)
        {
          RETURN_FAILED(AddXMLNodeToTree(spChild, hItem));
        }
      }
    }
  } while (NULL != spChild);

  // Indicate success
  return S_OK;
}