1 /*
  2 gacutil -l | grep -i unit
  3 
  4 gmcs /unsafe /r:nunit.framework /define:"XMLBLASTER_MONO" -debug+ -out:Start.exe *.cs service/*.cs ../../../src/csharp/XmlBlasterAccess.cs ../../../src/csharp/Key.cs ../../../src/csharp/Qos.cs ../../../src/csharp/service/*.cs  ../../../src/csharp/util/*.cs
  5 mono Start.exe
  6 
  7 gmcs /unsafe /r:nunit.framework /t:library /define:"XMLBLASTER_MONO" -debug+ -out:xmlBlasterClient.dll *.cs service/*.cs ../../../src/csharp/XmlBlasterAccess.cs ../../../src/csharp/Key.cs ../../../src/csharp/Qos.cs ../../../src/csharp/service/*.cs  ../../../src/csharp/util/*.cs
  8 mono nunit-console.exe xmlBlasterClient.dll
  9 
 10 gacutil -l
 11 csc /unsafe /r:nunit.framework /t:library -debug+ -out:xmlBlasterClient.dll *.cs ..\..\..\src\csharp\XmlBlasterAccess.cs ..\..\..\src\csharp\Key.cs ..\..\..\src\csharp\Qos.cs ..\..\..\src\csharp\service\*.cs  ..\..\..\src\csharp\util\*.cs
 12 */
 13 using System;
 14 using System.IO;
 15 using System.Collections;
 16 using System.Threading;
 17 //using System.Xml;

 18 using org.xmlBlaster.client;
 19 using org.xmlBlaster.util;
 20 using org.xmlBlaster.contrib.service;
 21 
 22 public class Start : I_LoggingCallback, I_ConnectionStateListener {
 23    public void OnLogging(XmlBlasterLogLevel logLevel, string location, string message)
 24    {
 25       Console.WriteLine(logLevel + " " + location + " " + message);
 26    }
 27 
 28    static void Main(string[] argv) {
 29       Console.WriteLine("Startup");
 30 
 31       //new Start().testXmlBlasterPing();

 32 
 33       new Start().testXmlBlaster();
 34 
 35       //(new Start()).TestPinger();

 36       
 37       //simpleServiceTest();

 38 
 39       /*
 40 
 41       testStuff();
 42 
 43       TestSer testSer = new TestSer("William", 54);
 44       //testSer.name = "Jack";
 45       //testSer.age = 23;
 46 
 47 #if XMLBLASTER_MONO
 48       string path = @"/tmp";
 49 #else
 50       string path = @"C:\tmp\in";
 51 #endif
 52       string name = Path.Combine(path, "2007-04-20T12-10-44.xml");
 53       FileLocator.writeBinaryFile(name, Serialization.Serialize<TestSer>(testSer));
 54 
 55       TestSer[] arr = FileLocator.GetObjectsFromFiles<TestSer>(path, "*.xml");
 56       foreach (TestSer f in arr) {
 57          Console.WriteLine("File: -> " + f.ToString());
 58       }
 59       //testNmea();
 60       //testXmlBlaster();
 61       testService();
 62        */
 63    }
 64 
 65    public static void simpleServiceTest() {
 66       string xml = "<s>"
 67    + "<p k='serviceName'>track</p>"
 68    + "<p k='result'>&lt;A&gt;&lt;B&gt;Hallo&amp;&lt;/B&gt;&lt;C /&gt;&lt;/A&gt;</p>"
 69    + "</s>";
 70       ServiceTO service = ServiceTO.parse(xml);
 71 
 72       Console.WriteLine(service.getPropValue("result"));
 73 
 74       Console.WriteLine("Done");
 75    }
 76 
 77    private void TestPinger()
 78    {
 79       XmlBlasterAccess xbAccess = new XmlBlasterAccess();
 80       long sleepMillis = 5000;
 81       XbPinger xbPinger = new XbPinger(xbAccess, sleepMillis, this);
 82       xbPinger.Start();
 83 
 84       Thread.Sleep(12*1000);
 85       xbPinger.Stop();
 86 
 87       Thread.Sleep(10000000);
 88    }
 89 
 90 
 91    public class TestSer {
 92       public TestSer() {
 93       }
 94       public TestSer(string n, int a) {
 95          this.name = n;
 96          this.age = a;
 97       }
 98       public string name;
 99       public int age;
100       public override string ToString() {
101          return "name=" + this.name + " age=" + this.age;
102       }
103    }
104 
105    private static void testStuff() {
106       //Stuff.ToUtcMillisecondsEpoch(DateTime dateTime)

107       //Stuff.GetCurrentUtcMillisecondsEpoch()

108       //Stuff.DateTimeFromUtcMillisecondsEpoch(long milliEpoch)

109       long millis = Stuff.GetCurrentUtcMillisecondsEpoch();
110       Console.WriteLine("Current millis=" + millis);
111 
112       // From Java: millis=1183965018906 gmt=9 Jul 2007 07:10:18 GMT iso=2007-07-09 07:10:18.906Z local=09.07.2007 09:10:18

113       long utcMillis = 1183965018906L;
114       DateTime dateTimeUtc = Stuff.DateTimeFromUtcMillisecondsEpoch(utcMillis);
115       long newUtcMillis = Stuff.ToUtcMillisecondsEpoch(dateTimeUtc);
116       Console.WriteLine("dateTimeUtc=" + Stuff.ToUtcIsoDateTimeString(dateTimeUtc)
117          + " utcMillis=" + utcMillis + " newUtcMillis=" + newUtcMillis);
118 
119 
120 
121       DateTime now = DateTime.Now;
122       string nowUtc = Stuff.ToUtcIsoDateTimeString(now);
123       Console.WriteLine("Now UTC is: " + nowUtc);
124       DateTime again = Stuff.UtcDateTimeFromIsoString(nowUtc);
125       Console.WriteLine("--->" + Stuff.ToUtcIsoDateTimeString(again));
126 
127 
128       Hashtable h = new Hashtable();
129       //h.Add("key1", "value1");

130       h.Add("key<", "<&>!§");
131       string xml = Stuff.ToClientPropertiesXml(h, true);
132       Console.WriteLine(xml);
133    }
134 
135    private static void testService() {
136       ServiceTOTest t = new ServiceTOTest();
137       t.CheckBase64();
138       t.CheckToXml();
139       t.CheckToXmlParsing2();
140       //t.CheckXmlParsing();

141       //t.CheckXmlSubtagsParsing();

142       //t.CheckXmlBase64Parsing();

143    }
144 
145    private static void testNmea() {
146       NmeaTest n = new NmeaTest();
147       n.CheckSerialInput();
148    }
149 
150    private void testXmlBlasterPing()
151    {
152       try
153       {
154          I_XmlBlasterAccess xb = XmlBlasterAccessFactory.CreateInstance();
155          xb.RegisterConnectionListener(this);
156          Hashtable properties = new Hashtable();
157          properties.Add("dispatch/connection/pingInterval", "12500");
158          properties.Add("dispatch/connection/delay", "8600");
159          properties.Add("dispatch/connection/pollOnInitialConnectFail", "true");
160          xb.Initialize(properties);
161          string connectQos =
162             "<qos>\n" +
163             " <securityService type='htpasswd' version='1.0'>\n" +
164             "   <user>fritz</user>\n" +
165             "   <passwd>secret</passwd>\n" +
166             " </securityService>\n" +
167             "</qos>";
168          ConnectReturnQos crq = xb.Connect(connectQos, null);
169          Console.WriteLine("Done, sleeping now");
170       }
171       catch (Exception e)
172       {
173          Console.WriteLine("Test failed, sleeping now: " + e.ToString());
174       }
175 
176       Thread.Sleep(1000000);
177    }
178 
179    public void reachedAlive(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
180    {
181       Console.WriteLine("****CLIENT reachedAlive " + oldState + "->ALIVE");
182    }
183 
184    public void reachedPolling(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
185    {
186       Console.WriteLine("****CLIENT reachedPolling " + oldState + "->POLLING");
187    }
188 
189    public void reachedDead(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
190    {
191       Console.WriteLine("****CLIENT reachedDead " + oldState + "->DEAD");
192    }
193 
194 
195    private void testXmlBlaster() {
196       QosTest qosTest = new QosTest();
197       qosTest.CheckConnectReturnQos();
198       qosTest.CheckComplete();
199       qosTest.CheckEmpty();
200       try {
201          qosTest.CheckInvalid();
202       }
203       catch (Exception e) {
204          Console.WriteLine("OK Expected: " + e.ToString());
205       }
206 
207 
208       KeyTest keyTest = new KeyTest();
209       keyTest.CheckComplete();
210 
211       XmlBlasterAccessTest xbTest = new XmlBlasterAccessTest();
212       xbTest.CheckMethods();
213 
214       Console.WriteLine("Done");
215    }
216 }


syntax highlighted by Code2HTML, v. 0.9.1