1 /*----------------------------------------------------------------------------
 2 Name:      HelloOverC.cs
 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 using xmlBlaster client C DLL library
 7 Compile:   csc.exe /reference:%XMLBLASTER_HOME%\lib\xmlBlasterClientCmanaged.dll HelloOverC.cs
 8 CompileCE: Does not work as the Compact Framework (CF) does not support C++/CLI managed dlls:
 9            C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Csc.exe /noconfig /nostdlib+ /warn:4 /define:DEBUG;TRACE;Smartphone /reference:"C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v1.0\WindowsCE\mscorlib.dll" /reference:"C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v1.0\WindowsCE\System.Data.dll" /reference:"C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v1.0\WindowsCE\System.dll" /reference:"C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\CompactFramework\2.0\v1.0\WindowsCE\System.Xml.dll" /debug+ /filealign:512 /optimize- /out:obj\Debug\CsharpOverC-Arm4.exe /reference:%XMLBLASTER_HOME%\lib\xmlBlasterClientCmanaged.dll /target:exe HelloOverC.cs Properties\AssemblyInfo.cs
10 Start:     Copy xmlBlasterClientCmanaged.dll to the current directory and launch
11            HelloOverC.exe --help
12 -----------------------------------------------------------------------------*/
13 #region Using directives

14 using System;
15 using System.Collections;
16 //using System.Collections.Generic;

17 using System.Text;
18 using org.xmlBlaster.client; // xmlBlasterClientCmanaged.dll

19 #endregion

20 
21 class HelloOverC
22 {
23    const string callbackSessionId = "secretCb";
24 
25    static void Main(string[] argv)
26    {
27       new HelloOverC(argv);
28    }
29 
30    public HelloOverC(string[] args)
31    {
32       string connectQos = String.Format(
33             "<qos>\n" +
34             " <securityService type='htpasswd' version='1.0'>\n" +
35             "  <![CDATA[\n" +
36             "   <user>fritz</user>\n" +
37             "   <passwd>secret</passwd>\n" +
38             "  ]]>\n" +
39             " </securityService>\n" +
40             " <queue relating='callback' maxEntries='50000' maxEntriesCache='10000'>\n" +
41             "   <callback type='SOCKET' sessionId='{0}'>\n" +
42             "   </callback>\n" +
43             " </queue>\n" +
44             "</qos>", callbackSessionId);
45       try
46       {
47          Console.WriteLine("Hello World");
48          Hashtable props = new Hashtable();
49          //props->Add(L"dispatch/connection/plugin/socket/hostname", L"localhost");

50          bool help = false;
51          IEnumerator myEnum = args.GetEnumerator();
52          while (myEnum.MoveNext())
53          {
54             string key = (string)myEnum.Current;
55             if (key.Equals("--help") || key.Equals("-help"))
56                help = true;
57             if (myEnum.MoveNext())
58             {
59                string value = (string)myEnum.Current;
60                if (key.StartsWith("-"))
61                   key = key.Substring(1);
62                props.Add(key, value);
63             }
64          }
65 
66          XmlBlasterAccessM xb = new XmlBlasterAccessM(props);
67          if (help)
68          {
69             Console.WriteLine("Usage:\nXmlBlaster C SOCKET client {0}\n{1}\n",
70                      xb.getVersion(), xb.getUsage());
71             return;
72          }
73 
74          xb.connect(connectQos);
75          Console.WriteLine("Connected to xmlBlaster");
76 
77          xb.disconnect("");
78          Console.WriteLine("Disconnected from xmlBlaster");
79       }
80       catch (XmlBlasterExceptionM e)
81       {
82          Console.WriteLine("Caught an exception:" + e.getMessage());
83       }
84    }
85 }


syntax highlighted by Code2HTML, v. 0.9.1