arpadboda commented on a change in pull request #584: minificpp-773
URL: https://github.com/apache/nifi-minifi-cpp/pull/584#discussion_r290653710
##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -134,14 +157,81 @@ void ConsumeWindowsEventLog::onTrigger(const
std::shared_ptr<core::ProcessContex
}
}
-bool ConsumeWindowsEventLog::subscribe(const
std::shared_ptr<core::ProcessContext> &context)
-{
+void ConsumeWindowsEventLog::createTextOutput(std::wstringstream& stream,
MSXML2::IXMLDOMElementPtr pRoot, std::vector<std::wstring>& ancestors) {
+ const auto pNodeChildren = pRoot->childNodes;
+
+ auto writeAncestors = [](std::wstringstream& stream,
std::vector<std::wstring>& ancestors) {
+ for (size_t j = 0; j < ancestors.size() - 1; j++) {
+ stream << ancestors[j] + L'/';
+ }
+ stream << ancestors[ancestors.size() - 1];
+ };
+
+ if (0 == pNodeChildren->length) {
+ writeAncestors(stream, ancestors);
+
+ stream << std::endl;
+ }
+ else {
+ for (long i = 0; i < pNodeChildren->length; i++) {
+ std::wstringstream curStream;
+
+ const auto pNode = pNodeChildren->item[i];
+
+ const auto nodeType = pNode->GetnodeType();
+
+ if (DOMNodeType::NODE_TEXT == nodeType) {
+ const auto nodeValue = pNode->text;
+ if (nodeValue.length()) {
+ writeAncestors(stream, ancestors);
+
+ std::wstring strNodeValue = static_cast<LPCWSTR>(nodeValue);
+
+ // Remove '\n', '\r' - just substitute all whitespaces with ' '.
+ strNodeValue = std::regex_replace(strNodeValue,
std::wregex(L"\\s+"), L" ");
+
+ curStream << L" = " << strNodeValue;
+ }
+
+ stream << curStream.str() << std::endl;
+ } else if (DOMNodeType::NODE_ELEMENT == nodeType) {
+ curStream << pNode->nodeName;
+
+ const auto pAttributes = pNode->attributes;
+ for (long iAttr = 0; iAttr < pAttributes->length; iAttr++) {
+ const auto pAttribute = pAttributes->item[iAttr];
+
+ curStream << L" " << pAttribute->nodeName << L'(' <<
static_cast<_bstr_t>(pAttribute->nodeValue) << L')';
+ }
+
+ ancestors.emplace_back(curStream.str());
+ createTextOutput(stream, pNode, ancestors);
+ ancestors.resize(ancestors.size() - 1);
Review comment:
I think a simple pop_back() would do the same here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services