1 /*----------------------------------------------------------------------------
 2 Name:      HelloManaged.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 HelloManaged.cs
 8 Start:     Copy xmlBlasterClientCmanaged.dll to the current directory and launch
 9            HelloManaged.exe --help
10 -----------------------------------------------------------------------------*/
11 using System;
12 using System.Collections;
13 using System.Collections.Generic;
14 using System.Text;
15 using org.xmlBlaster.client; // xmlBlasterClientCmanaged.dll

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

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


syntax highlighted by Code2HTML, v. 0.9.1