Remove the Result wrapper from web service response? - web-services

I have a asmx webservice and it has a web method
[WebMethod(Description = "Request for Read Stop Sale")]
[SoapHeader("Security", Direction = SoapHeaderDirection.In)]
[SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare,Action="OTA_HotelBookingRule")]
public XmlDocument ReadStopSales()
{
....
I am getting some details from database and converting and transforming it into
XML and then putting it into XmlDocument object and returning it...
XmlResultDocument.LoadXml(results.ToString());
return XmlResultDocument;
}
the result which i am loading into XmlResultDocument has the root element <OTA_HotelBookingRuleRS xmlns="">
I am testing this method by calling on SoapUI, it is giving me following result:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ReadStopSalesResult xmlns="http://localhost:6092/connectAPI.asmx">
<OTA_HotelBookingRuleRS xmlns="">
<RuleMessage HotelCode="5">
<StatusApplication RatePlanCode="579_1" InvTypeCode="579" RatePlanCategory="BB"/>
<BookingRules>
<BookingRule Start="2015-07-15" End="2015-07-15">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-16" End="2015-07-16">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-17" End="2015-07-17">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-18" End="2015-07-18">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-19" End="2015-07-19">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-20" End="2015-07-20">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-21" End="2015-07-21">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-22" End="2015-07-22">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-23" End="2015-07-23">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-24" End="2015-07-24">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-25" End="2015-07-25">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-26" End="2015-07-26">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
</BookingRules>
</RuleMessage>
</OTA_HotelBookingRuleRS>
</ReadStopSalesResult>
</soap:Body>
</soap:Envelope>
I do not need the element <ReadStopSalesResult xmlns="http://localhost:6092/connectAPI.asmx">
In this element "ReadStopSales" is the webmethod name as you can see in C# code.
I want my result as below:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<OTA_HotelBookingRuleRS xmlns="">
<RuleMessage HotelCode="5">
<StatusApplication RatePlanCode="579_1" InvTypeCode="579" RatePlanCategory="BB"/>
<BookingRules>
<BookingRule Start="2015-07-15" End="2015-07-15">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-16" End="2015-07-16">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-17" End="2015-07-17">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-18" End="2015-07-18">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-19" End="2015-07-19">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-20" End="2015-07-20">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-21" End="2015-07-21">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-22" End="2015-07-22">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-23" End="2015-07-23">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-24" End="2015-07-24">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-25" End="2015-07-25">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
<BookingRule Start="2015-07-26" End="2015-07-26">
<RestrictionStatus Restriction="Master" Status="Open"/>
</BookingRule>
</BookingRules>
</RuleMessage>
</OTA_HotelBookingRuleRS>
</soap:Body>
</soap:Envelope>
please help how to remove default result element ....

You can try implementing a WebserviceHandler and change the Response message. Sample code will look like :
public class ChangeMessageHandler implements SOAPHandler<SOAPMessageContext> {
#Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
try {
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
soapMessage.getSOAPBody().appendChild(context.getMessage().getSOAPBody().getFirstChild().getFirstChild());
context.setMessage(soapMessage);
}
catch (Exception ex) {
}
}
return true;
} }
Basically, I am trying to fetch the second node and adding it to new message.

Related

XPath query is not working in IXMLDOMDocument2, but passes online XPath tester

In the below XML, I'm trying to use an XPath query to select the first <Event> node that has RenderingInfo/Task = StartRemoteSessionRdpClientBegin.
<Events>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Guid="{9e814aad-3204-11d2-9a82-006008a86939}" />
<EventID>0</EventID>
</System>
<EventData>
<Data Name="EventVersion">0</Data>
<Data Name="Reserved">0</Data>
<Data Name="PartitionType"> 0</Data>
</EventData>
<RenderingInfo Culture="en-US">
<Opcode>PartitionInfoExtensionV2</Opcode>
<Provider>MSNT_SystemTrace</Provider>
<EventName xmlns="http://schemas.microsoft.com/win/2004/08/events/trace">EventTrace</EventName>
</RenderingInfo>
<ExtendedTracingInfo xmlns="http://schemas.microsoft.com/win/2004/08/events/trace">
<EventGuid>{68fdd900-4a3e-11d1-84f4-0000f80464e3}</EventGuid>
</ExtendedTracingInfo>
</Event>
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Microsoft.Windows.HVSI.Manager" Guid="{5e3f60ef-a60f-45a9-84ae-e224f761baa3}" />
<EventID>0</EventID>
</System>
<EventData>
<Data Name="ContainerName">2fb583e6-3769-4465-9de0-ce56a1aa84c4</Data>
<Data Name="RDPSessionID">{24259afa-2028-4206-9856-257ea519bfdd}</Data>
<Data Name="PartA_PrivTags">16777216</Data>
</EventData>
<RenderingInfo Culture="en-US">
<Task>StartRemoteSessionRdpClientBegin</Task>
</RenderingInfo>
</Event>
</Events>
From W3School examples I've looked at, I'd think this should be possible with an XPath query like: /Events/Event[RenderingInfo/Task="StartRemoteSessionRdpClientBegin"].
I've tried this with my XML at https://www.uccollabing.com/free-online-xpath-tester-evaluator-tool/ and it seemed to work there, which makes me suspect an issue with my code. Simple queries work e.g. /Events or /Events/*.
Should my above query work?
HRESULT SearchTraceFile(std::wstring fileName)
{
HRESULT hr = S_OK;
_bstr_t xPath = L"/Events/Event[RenderingInfo/Task=\"StartRemoteSessionRdpClientBegin\"]";
wprintf(L"Query path: %s\n", static_cast<wchar_t*>(xPath));
RETURN_IF_FAILED(CoInitialize(NULL));
wrl::ComPtr<IXMLDOMDocument2> xmlDoc;
RETURN_IF_FAILED(CoCreateInstance(
CLSID_DOMDocument60,
nullptr,
CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument2, (void**)&xmlDoc));
_variant_t localFileName(fileName.c_str());
VARIANT_BOOL successful = VARIANT_FALSE;
RETURN_IF_FAILED(xmlDoc->load(localFileName, &successful));
RETURN_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_DATA), (successful != VARIANT_TRUE));
_variant_t varXPath(L"XPath");
xmlDoc->setProperty(L"SelectionLanguage", varXPath);
xmlDoc->setProperty(L"MaxElementDepth", CComVariant(10));
wrl::ComPtr<IXMLDOMNodeList> events;
wrl::ComPtr<IXMLDOMNode> spTaskNode;
hr = xmlDoc->selectSingleNode(xPath, &spTaskNode);
if (FAILED(hr)) return hr;
if (S_FALSE == hr)
{
wprintf(L"Not found\n");
return S_OK;
}
BSTR value = NULL;
hr = spTaskNode->get_text(&value);
if (FAILED(hr)) wprintf(L"get_text failed 0x%08x\n", hr);
else wprintf(L"get_text succedded\n");
wprintf(L"value:\n%s\n", value);
::SysFreeString(value);
return hr;
}
Your XML involves namespaces, so you have to take that into account in your XPath query. This is documented on MSDN:
Specify Namespace when you query the DOM with XPath
For example:
HRESULT SearchTraceFile(std::wstring fileName)
{
_bstr_t xPath = L"/Events/e:Event[e:RenderingInfo/e:Task=\"StartRemoteSessionRdpClientBegin\"]"; // <-- NOTE THE 'e:' PREFIXES!
wprintf(L"Query path: %s\n", static_cast<wchar_t*>(xPath));
RETURN_IF_FAILED(CoInitialize(NULL));
wrl::ComPtr<IXMLDOMDocument2> xmlDoc;
RETURN_IF_FAILED(CoCreateInstance(
CLSID_DOMDocument60,
nullptr,
CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument2, (void**)&xmlDoc));
_variant_t localFileName(fileName.c_str());
VARIANT_BOOL successful = VARIANT_FALSE;
RETURN_IF_FAILED(xmlDoc->load(localFileName, &successful));
RETURN_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_DATA), (successful != VARIANT_TRUE));
xmlDoc->setProperty(L"SelectionLanguage", _variant_t(L"XPath"));
xmlDoc->setProperty(L"SelectionNamespaces", _variant_t(L"xmlns:e='http://schemas.microsoft.com/win/2004/08/events/event'")); // <-- ADD THIS!
xmlDoc->setProperty(L"MaxElementDepth", _variant_t(10));
wrl::ComPtr<IXMLDOMNodeList> events;
wrl::ComPtr<IXMLDOMNode> spTaskNode;
HRESULT hr = xmlDoc->selectSingleNode(xPath, &spTaskNode);
if (FAILED(hr)) {
wprintf(L"selectSingleNode failed 0x%08x\n", hr);
return hr;
}
if (S_FALSE == hr)
{
wprintf(L"Not found\n");
return S_OK;
}
_bstr_t value;
hr = spTaskNode->get_text(value.GetAddress());
if (FAILED(hr)) {
wprintf(L"get_text failed 0x%08x\n", hr);
return hr;
}
wprintf(L"get_text succeeded\nvalue:\n%s\n", static_cast<wchar_t*>(value));
return S_OK;
}

Using one render pass on top of another

I'm trying to implement imGUI in my app which already have some render pass for rendering meshes. Its command buffer updates only when new meshes added to scene, while imGUI command buffer should be updated every frame. Secondary command buffer doesn't fits me because I always have to reference it from primary cb, which doesn't update so often.
I also want to mention that my code is based on this tutorial.
I came to conclusion that I should have two render passes with two primary command buffers. The only problem now is that I can't combine these two render passes.
There is the code for main rp:
vk::AttachmentDescription colorAttachment;
colorAttachment.format = swapChainImageFormat;
colorAttachment.samples = vk::SampleCountFlagBits::e1;
colorAttachment.loadOp = vk::AttachmentLoadOp::eClear;
colorAttachment.storeOp = vk::AttachmentStoreOp::eStore;
colorAttachment.stencilLoadOp = vk::AttachmentLoadOp::eDontCare;
colorAttachment.stencilStoreOp = vk::AttachmentStoreOp::eNoneQCOM;
colorAttachment.initialLayout = vk::ImageLayout::eUndefined;
colorAttachment.finalLayout = vk::ImageLayout::ePresentSrcKHR;
vk::AttachmentDescription depthAttachment;
depthAttachment.format = FindDepthFormat();
depthAttachment.samples = vk::SampleCountFlagBits::e1;
depthAttachment.loadOp = vk::AttachmentLoadOp::eClear;
depthAttachment.storeOp = vk::AttachmentStoreOp::eDontCare;
depthAttachment.stencilLoadOp = vk::AttachmentLoadOp::eDontCare;
depthAttachment.stencilStoreOp = vk::AttachmentStoreOp::eDontCare;
depthAttachment.initialLayout = vk::ImageLayout::eUndefined;
depthAttachment.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
std::array<vk::AttachmentDescription, 2> attachments = { colorAttachment, depthAttachment };
vk::AttachmentReference colorAttachmentRef;
colorAttachmentRef.attachment = 0;
colorAttachmentRef.layout = vk::ImageLayout::eColorAttachmentOptimal;
vk::AttachmentReference depthAttachmentRef;
depthAttachmentRef.attachment = 1;
depthAttachmentRef.layout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
vk::SubpassDescription subpass;
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &colorAttachmentRef;
subpass.pDepthStencilAttachment = &depthAttachmentRef;
vk::SubpassDependency dependency;
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
dependency.dstSubpass = 0;
dependency.srcStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
dependency.srcAccessMask = vk::AccessFlagBits();
dependency.dstStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
dependency.dstAccessMask = vk::AccessFlagBits::eColorAttachmentRead | vk::AccessFlagBits::eColorAttachmentWrite;
vk::RenderPassCreateInfo renderPassInfo;
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachments.size());
renderPassInfo.pAttachments = attachments.data();
renderPassInfo.subpassCount = 1;
renderPassInfo.pSubpasses = &subpass;
renderPassInfo.dependencyCount = 1;
renderPassInfo.pDependencies = &dependency;
gameRenderPass = device.createRenderPass(renderPassInfo);
There is the code for ui rp:
vk::AttachmentDescription colorAttachment;
colorAttachment.format = swapChainImageFormat;
colorAttachment.samples = vk::SampleCountFlagBits::e1;
colorAttachment.loadOp = vk::AttachmentLoadOp::eLoad;
colorAttachment.storeOp = vk::AttachmentStoreOp::eStore;
colorAttachment.stencilLoadOp = vk::AttachmentLoadOp::eDontCare;
colorAttachment.stencilStoreOp = vk::AttachmentStoreOp::eDontCare;
colorAttachment.initialLayout = vk::ImageLayout::ePresentSrcKHR;
colorAttachment.finalLayout = vk::ImageLayout::ePresentSrcKHR;
vk::AttachmentDescription depthAttachment;
depthAttachment.format = FindDepthFormat();
depthAttachment.samples = vk::SampleCountFlagBits::e1;
depthAttachment.loadOp = vk::AttachmentLoadOp::eClear;
depthAttachment.storeOp = vk::AttachmentStoreOp::eDontCare;
depthAttachment.stencilLoadOp = vk::AttachmentLoadOp::eDontCare;
depthAttachment.stencilStoreOp = vk::AttachmentStoreOp::eDontCare;
depthAttachment.initialLayout = vk::ImageLayout::eUndefined;
depthAttachment.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
std::array<vk::AttachmentDescription, 2> attachments = { colorAttachment, depthAttachment };
vk::AttachmentReference colorAttachmentRef;
colorAttachmentRef.attachment = 0;
colorAttachmentRef.layout = vk::ImageLayout::eColorAttachmentOptimal;
vk::AttachmentReference depthAttachmentRef;
depthAttachmentRef.attachment = 1;
depthAttachmentRef.layout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
vk::SubpassDescription subpass;
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &colorAttachmentRef;
subpass.pDepthStencilAttachment = &depthAttachmentRef;
vk::SubpassDependency dependency;
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
dependency.dstSubpass = 0;
dependency.srcStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
dependency.srcAccessMask = vk::AccessFlagBits();
dependency.dstStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
dependency.dstAccessMask = vk::AccessFlagBits::eColorAttachmentRead | vk::AccessFlagBits::eColorAttachmentWrite;
vk::RenderPassCreateInfo renderPassInfo;
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachments.size());
renderPassInfo.pAttachments = attachments.data();
renderPassInfo.subpassCount = 1;
renderPassInfo.pSubpasses = &subpass;
renderPassInfo.dependencyCount = 1;
renderPassInfo.pDependencies = &dependency;
uiRenderPass = device.createRenderPass(renderPassInfo);
And there is the code of my DrawFrame function:
device.waitForFences(1, &inFlightFences[currentFrame], true, UINT64_MAX);
uint32_t imageIndex;
device.acquireNextImageKHR(swapChain, UINT64_MAX, imageAvailableSemaphores[currentFrame], nullptr, &imageIndex);
if (imagesInFlight[imageIndex].operator!=(nullptr))
{
device.waitForFences(1, &imagesInFlight[imageIndex], true, UINT64_MAX);
}
imagesInFlight[imageIndex] = inFlightFences[currentFrame];
vk::SubmitInfo submitInfo;
vk::Semaphore waitSemaphores[] = { imageAvailableSemaphores[currentFrame] };
vk::PipelineStageFlags waitStages[] = { vk::PipelineStageFlagBits::eColorAttachmentOutput };
submitInfo.waitSemaphoreCount = 1;
submitInfo.pWaitSemaphores = waitSemaphores;
submitInfo.pWaitDstStageMask = waitStages;
vk::Semaphore signalSemaphores[] = { renderFinishedSemaphores[currentFrame] };
submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = signalSemaphores;
device.resetFences(1, &inFlightFences[currentFrame]);
UpdateUniformBuffer(imageIndex);
UpdateUiCommandBuffer(imageIndex);
if (comandUpdateRequired[imageIndex])
{
UpdateGameCommandBuffer(imageIndex);
comandUpdateRequired[imageIndex] = false;
}
std::vector<vk::CommandBuffer> commands = { gameCommandBuffers[imageIndex], uiCommandBuffers[imageIndex] };
submitInfo.commandBufferCount = static_cast<uint32_t>(commands.size());
submitInfo.pCommandBuffers = commands.data();
graphicsQueue.submit(1, &submitInfo, inFlightFences[currentFrame]);
vk::PresentInfoKHR presentInfo;
presentInfo.waitSemaphoreCount = 1;
presentInfo.pWaitSemaphores = signalSemaphores;
vk::SwapchainKHR swapChains[] = { swapChain };
presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = swapChains;
presentInfo.pImageIndices = &imageIndex;
presentQueue.presentKHR(presentInfo);
presentQueue.waitIdle();
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
And the result is:
As you can see, clear color is used to overwrite the results of my first render pass, what is not what I want.
Note that load and store operations already in use and it still doesn't work.
UPDATE
There is a code of my second cb:
device.freeCommandBuffers(commandPool, 1, &uiCommandBuffers[index]);
vk::CommandBufferAllocateInfo allocInfo;
allocInfo.commandPool = commandPool;
allocInfo.level = vk::CommandBufferLevel::ePrimary;
allocInfo.commandBufferCount = 1;
device.allocateCommandBuffers(&allocInfo, &uiCommandBuffers[index]);
vk::CommandBufferBeginInfo beginInfo;
uiCommandBuffers[index].begin(beginInfo);
std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue(std::array<float, 4>{ 1.0f, 0.0f, 0.0f, 1.0f });
clearValues[1].depthStencil = { 1.0f, 0 };
vk::RenderPassBeginInfo renderPassInfo;
renderPassInfo.renderPass = gameRenderPass;
renderPassInfo.framebuffer = uiSwapChainFramebuffers[index];
renderPassInfo.renderArea.offset = { 0, 0 };
renderPassInfo.renderArea.extent = swapChainExtent;
renderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size()); // It doesn't work at all if I set clear values count to 0
renderPassInfo.pClearValues = clearValues.data();
//renderPassInfo.clearValueCount = 0;
//renderPassInfo.pClearValues = nullptr;
uiCommandBuffers[index].beginRenderPass(renderPassInfo, vk::SubpassContents::eInline);
auto drawData = ImGui::GetDrawData();
if (drawData)
{
ImGui_ImplVulkan_RenderDrawData(drawData, uiCommandBuffers[index]);
}
uiCommandBuffers[index].endRenderPass();
uiCommandBuffers[index].end();
If you want to render the UI using a second pass, just set the storeOp of the color attachment in the first render pass to VK_ATTACHMENT_STORE_OP_STORE and the loadOp for it in the second render pass to VK_ATTACHMENT_LOAD_OP_LOAD to keep the contents.
Another option would be to do this in a single render pass, like I do in my samples. Just render your scene, and put the draw calls for the UI in the same render pass.

Different CRC32 checksum for the same file

Basically, I have an application which imports a few DLLs and some Python libraries.
I did another application which calculates CRC32 for each of these files and I've added the list on my main application because I want to make it to check these files.
The problem is that sometimes the main application detects a DLL or a library modified even if it wasn't. It don't happens everytime and I am wondering why does that happens? What can determine the CRC32 checksum to differ? It's because my application loads these DLLs or is something external like viruses or anything else?
Here's the code for both main application and the application which does the CRC32 list:
#include "boost/crc.hpp"
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/progress.hpp"
#include "boost/integer.hpp"
using namespace std;
namespace fs = boost::filesystem;
int CheckCRC32(LPCSTR szFileName, DWORD dwCRC32)
{
if (!fs::exists(szFileName))
return 1;
DWORD dwResult = 0;
boost::crc_32_type result;
std::streamsize const buffer_size = 1024;
ifstream file(szFileName, std::ios_base::binary);
if (file)
{
do
{
char buffer[buffer_size];
file.read(buffer, buffer_size);
result.process_bytes(buffer, file.gcount());
} while(file);
}
else
return 1;
dwResult = result.checksum();
if (dwResult <= 0)
return 1;
if (dwResult != dwCRC32)
return 2;
return 0;
}
Also, if you have another solution for doing such things or if you have a solution for this method, please let me know.
I am not really trusting your 1024 bytes fixed buffer and the order of calls you chose. Either it is your intention to only use the first 1024 bytes of your files for the crc or this could already be the problem. On the other hand, if the files you crc are smaller than those 1024, it is up to the behavior of file.read() what happens.
Just to give you an option, here the code for a "low level" alternative. If the same crc values will be obtained with this version will depend on whether my initial crc value of 0 is "by the book" or if you need to use another start value.
#include <Windows.h>
#include <cstdint>
#include <string>
#include <vector>
static uint32_t crc32_tab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
uint32_t
crc32(uint32_t crc, const void *buf, size_t size)
{
const uint8_t *p = static_cast<const uint8_t*>(buf);
crc = crc ^ ~0U;
while (size--)
crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
return crc ^ ~0U;
}
bool Crc32OfFile(const char * pathToFile, uint32_t &result)
{
bool success = false;
HANDLE hFile =
::CreateFileA
( pathToFile
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN
, NULL
);
if (INVALID_HANDLE_VALUE != hFile)
{
DWORD fileSize = ::GetFileSize(hFile, NULL);
std::vector<uint8_t> buffer;
buffer.resize(fileSize);
DWORD bytesRead = 0UL;
if (::ReadFile(hFile, &buffer[0], buffer.size(), &bytesRead, NULL))
{
if (bytesRead == fileSize)
{
result = crc32(0UL, &buffer[0], buffer.size());
success = true;
}
}
::CloseHandle(hFile);
}
return success;
}

Count field incorrect syntax error

for the last several days i'm trying to connect to store procedure using ODBC.
This is my CRecordset code:
sp_insertSesMessageStore::sp_insertSesMessageStore(CDatabase* pdb)
: CRecordset(pdb){
// Param Init
m_RETURN_VALUE = -1;
m_PROVIDER_IDParam = _T("");
m_BRANCH_IDParam = _T("");
m_ACCOUNTParam = _T("");
m_SES_USER_UNIQUE_IDParam = _T("");
m_DISPLAY_NAMEParam = _T("");
m_SMTP_ADDRESSParam = _T("");
m_MESSAGE_TYPE_IDParam = 0;
m_PRIORITYParam = 0;
m_SUBJECTParam = _T("");
m_SUMMARYParam = _T("");
m_TEMPLATE_IDParam = _T("");
m_BODY_TYPE_IDParam = 0;
m_TRACKING_IDParam = _T("");
m_EXPIRATION_TIMEParam = _T("");
m_SUBCATEGORY_IDParam = 0;
m_FOLDER_IDParam = 0;
m_NUM_ATTACHMENTSParam = 0;
m_ACCESS_IDParam = _T("");
m_FLAGSParam = 0;
m_FAVORITEParam = FALSE;
m_CERTIFIED_IDParam = _T("");
m_SECURE_RESPONSE_OTPParam = _T("");
m_MESSAGE_IDParam = _T("");
m_nParams = 24;
m_nDefaultType = snapshot;}
This is the DoDataExchange.
void sp_insertSesMessageStore::DoFieldExchange(CFieldExchange* pFX){
// RFX output param mapping
/*pFX->SetFieldType(CFieldExchange::outputParam);
RFX_Long(pFX, _T("[#RETURN_VALUE]"), m_RETURN_VALUE);*/
// RFX input param mapping
pFX->SetFieldType(CFieldExchange::inputParam);
RFX_Text(pFX, _T("[#PROVIDER_ID]"), m_PROVIDER_IDParam, 3);
RFX_Text(pFX, _T("[#BRANCH_ID]"), m_BRANCH_IDParam, 50);
RFX_Text(pFX, _T("[#ACCOUNT]"), m_ACCOUNTParam, 255);
RFX_Text(pFX, _T("[#SES_USER_UNIQUE_ID]"), m_SES_USER_UNIQUE_IDParam, 8);
RFX_Text(pFX, _T("[#DISPLAY_NAME]"), m_DISPLAY_NAMEParam, 255);
RFX_Text(pFX, _T("[#SMTP_ADDRESS]"), m_SMTP_ADDRESSParam, 255);
RFX_Int(pFX, _T("[#MESSAGE_TYPE_ID]"), m_MESSAGE_TYPE_IDParam);
RFX_Byte(pFX, _T("[#PRIORITY]"), m_PRIORITYParam);
RFX_Text(pFX, _T("[#SUBJECT]"), m_SUBJECTParam, 255);
RFX_Text(pFX, _T("[#SUMMARY]"), m_SUMMARYParam, 255);
RFX_Text(pFX, _T("[#TEMPLATE_ID]"), m_TEMPLATE_IDParam, 255);
RFX_Int(pFX, _T("[#BODY_TYPE_ID]"), m_BODY_TYPE_IDParam);
RFX_Text(pFX, _T("[#TRACKING_ID]"), m_TRACKING_IDParam, 255);
RFX_Text(pFX, _T("[#EXPIRATION_TIME]"), m_EXPIRATION_TIMEParam, 16);
RFX_Int(pFX, _T("[#SUBCATEGORY_ID]"), m_SUBCATEGORY_IDParam);
RFX_Int(pFX, _T("[#FOLDER_ID]"), m_FOLDER_IDParam);
RFX_Int(pFX, _T("[#NUM_ATTACHMENTS]"), m_NUM_ATTACHMENTSParam);
RFX_LongBinary(pFX, _T("[#BODY]"), m_BODYParam);
RFX_Text(pFX, _T("[#ACCESS_ID]"), m_ACCESS_IDParam, 255);
RFX_Long(pFX, _T("[#FLAGS]"), m_FLAGSParam);
RFX_Bool(pFX, _T("[#FAVORITE]"), m_FAVORITEParam);
RFX_Text(pFX, _T("[#CERTIFIED_ID]"), m_CERTIFIED_IDParam, 100);
RFX_Text(pFX, _T("[#SECURE_RESPONSE_OTP]"), m_SECURE_RESPONSE_OTPParam, 50);
// RFX input_output param mapping
pFX->SetFieldType(CFieldExchange::inoutParam);
RFX_Text(pFX, _T("[#MESSAGE_ID]"), m_MESSAGE_IDParam, 8);}
BOOL sp_insertSesMessageStore::ExecDirect(){
return Open(CRecordset::forwardOnly, GetDefaultSQL(), CRecordset::executeDirect);}
This is the statement i'm passing.
CString sp_insertSesMessageStore::GetDefaultSQL(){
return _T("{CALL sp_insertSesMessageStore (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");}
This is an auto generated code from a tool i found on the web.
I had isolated the problem, the cause of this exception is the CLongBinary member, can't find the issue, any suggestions?!

IXMLDOMDocument::selectNodes doesn't work as expected

It's amazing IXMLDOMDocument::selectNodes doesn't work as expected. I know it's because xmlns="http://stackoverflow.com/questions/ask", but I don't know how to make it work if xmlns is present.
V_BSTR(&varParam) = SysAllocString(LR"iPhone5s(XPath)iPhone5s");
V_VT(&varParam) = VT_BSTR;
hr = ptrXMLDom->setProperty(L"SelectionLanguage", varParam);
ptrXMLDom->selectNodes(L"//bookstore", &ptrDomNodeList);
ptrDomNodeList->get_length(&len);//the value is always 0
Remarks: the xml is read-only. Don't tell me to modify original XML.
Here is my code:
#include <msxml6.h>
#include <msxml2.h>//necessary in Visual Studio 2013
HRESULT hr = CoInitialize(NULL);
HRESULT hr = CoCreateInstance(__uuidof(DOMDocument60), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(ppDoc));
if (SUCCEEDED(hr))
{
// these methods should not fail so don't inspect result
(*ppDoc)->put_async(VARIANT_FALSE);
(*ppDoc)->put_validateOnParse(VARIANT_FALSE);
(*ppDoc)->put_resolveExternals(VARIANT_FALSE);
(*ppDoc)->put_preserveWhiteSpace(VARIANT_TRUE);
}
HRESULT hr = S_OK;
IXMLDOMDocument2 *ptrXMLDom = NULL;
VARIANT_BOOL varBool = VARIANT_FALSE;
BSTR bstrXML = nullptr;
VARIANT varParam;
VariantInit(&varParam);
V_BSTR(&varParam) = SysAllocString(LR"iPhone5s(E:\Work\book.xml)iPhone5s");
V_VT(&varParam) = VT_BSTR;
hr = ptrXMLDom->load(varParam, &varBool);
V_BSTR(&varParam) = SysAllocString(LR"iPhone5s(XPath)iPhone5s");
V_VT(&varParam) = VT_BSTR;
hr = ptrXMLDom->setProperty(L"SelectionLanguage", varParam);
ptrXMLDom->selectNodes(L"//bookstore", &ptrDomNodeList);
ptrDomNodeList->get_length(&len);//the value is always 0
CoUninitialize();
Here is the xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Copyright w3school.com.cn -->
<!-- W3School.com.cn bookstore example -->
<bookstore xmlns="http://stackoverflow.com/questions/ask" version="1.0">
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
</bookstore>
i have found the answer by myself.
V_BSTR(&varParam) = SysAllocString(LR"iPhone5s(xmlns:pf='http://stackoverflow.com/questions/ask')iPhone5s");
V_VT(&varParam) = VT_BSTR;
hr = ptrXMLDom->setProperty(L"SelectionNamespaces", varParam);
ptrXMLDom->selectNodes(L"//pf:bookstore/pf:book", &ptrDomNodeList);
ptrDomNodeList->get_length(&len);//4