1 /*----------------------------------------------------------------------------
2 Name: HelloManagedCppOverC.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Author: "Marcel Ruff" <xmlBlaster@marcelruff.info>
6 Note: Example xmlBlaster access with a managed .net C++ client
7 -----------------------------------------------------------------------------*/
8 #include "stdafx.h"
9 #using <xmlBlasterClientCmanaged.dll>
10
11 using namespace System;
12 using namespace System::Collections;
13 using namespace org::xmlBlaster::client;
14
15 /**
16 * @example HelloManagedCppOverC --help
17 * @example HelloManagedCppOverC.exe -dispatch/connection/plugin/socket/hostname myserverIP
18 */
19 int main(array<System::String ^> ^args)
20 {
21 String^ callbackSessionId = L"secret";
22 String^ connectQos = String::Format(
23 L"<qos>\n"+
24 " <securityService type='htpasswd' version='1.0'>\n"+
25 " <![CDATA[\n"+
26 " <user>fritz</user>\n"+
27 " <passwd>secret</passwd>\n"+
28 " ]]>\n"+
29 " </securityService>\n"+
30 " <queue relating='callback' maxEntries='50000' maxEntriesCache='10000'>\n"+
31 " <callback type='SOCKET' sessionId='{0}'>\n"+
32 " </callback>\n"+
33 " </queue>\n"+
34 "</qos>", callbackSessionId);
35 try {
36 Console::WriteLine(L"C++ xmlBlaster client using managed wrapper around C client DLL");
37 Hashtable^ props = gcnew Hashtable();
38 //props->Add(L"dispatch/connection/plugin/socket/hostname", L"localhost");
39 bool help = false;
40 IEnumerator^ myEnum = args->GetEnumerator();
41 while ( myEnum->MoveNext() ) {
42 String^ key = safe_cast<String^>(myEnum->Current);
43 if (key->Equals(L"--help")||key->Equals(L"-help"))
44 help = true;
45 if (myEnum->MoveNext()) {
46 String^ value = safe_cast<String^>(myEnum->Current);
47 if (key->StartsWith("-"))
48 key = key->Substring(1);
49 props->Add(key, value);
50 }
51 }
52 XmlBlasterAccessM xb(props);
53 if (help) {
54 Console::WriteLine("Usage:\nXmlBlaster C SOCKET client {0}\n{1}\n",
55 xb.getVersion(), xb.getUsage());
56 return 1;
57 }
58
59 xb.connect(connectQos);
60 Console::WriteLine("Connected to xmlBlaster");
61
62 xb.disconnect(L"");
63 Console::WriteLine("Disconnected from xmlBlaster");
64 return 0;
65 }
66 catch (XmlBlasterExceptionM^ e) {
67 Console::WriteLine("Caught an exception:" + e->getMessage());
68 }
69 }
syntax highlighted by Code2HTML, v. 0.9.1