// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Remoting.Channels; using omg.org.CosNaming; using Ch.Elca.Iiop; using Ch.Elca.Iiop.Services; using corbatest.common; namespace CorbaTest.Client { public class Program { private static Test GetStub(string orbhost, int orbport, string name) { NamingContext nc = CorbaInit.GetInit().GetNameService(orbhost, orbport); return (Test)nc.resolve(new NameComponent[] { new NameComponent(name, "") }); } private static void TestFunctional(string orbhost, int orbport, string name) { Test tst = GetStub(orbhost, orbport, name); int a = 123; int b = 456; int c = tst.add(a, b); Console.WriteLine(c);; String s = "ABC"; String s2 = tst.dup(s); Console.WriteLine(s2); Data d = new Data(123, "ABC"); Data d2 = tst.process(d); Console.WriteLine("{0} {1}", d2.iv, d2.sv); } private static void TestInstantiation(string orbhost, int orbport, string name) { Test tst1 = GetStub(orbhost, orbport, name); for(int i = 0; i < 2; i++) { int n = tst1.getCounter(); Console.WriteLine(n); } Test tst2 = GetStub(orbhost, orbport, name); for(int i = 0; i < 2; i++) { int n = tst2.getCounter(); Console.WriteLine(n); } } private const int REP = 100000; private static void TestPerformance(string orbhost, int orbport, string name) { Test tst = GetStub(orbhost, orbport, name); DateTime dt1 = DateTime.Now; Enumerable.Range(0, REP).AsParallel().ForAll(i => { tst.noop(); }); DateTime dt2 = DateTime.Now; Console.WriteLine("{0} requests per second", (int)(REP / (dt2 - dt1).TotalSeconds)); } private static void Test(string lbl, string orbhost, int orbport, string name) { Console.WriteLine(lbl + ":"); TestFunctional(orbhost, orbport, name); TestInstantiation(orbhost, orbport, name); TestPerformance(orbhost, orbport, name); } private const string JAVASE_HOST = "localhost"; private const int JAVASE_PORT = 1050; private const string JAVASE_NAME1 = "TestJ1"; private const string JAVASE_NAME2 = "TestJ2"; private const string IIOPNET_HOST = "localhost"; private const int IIOPNET_PORT = 12345; private const string IIOPNET_NAME = "TestN"; private const String OMNIORB_HOST = "localhost"; private const int OMNIORB_PORT = 2809; private const String OMNIORB_NAME1 = "TestC1"; private const String OMNIORB_NAME2 = "TestC2"; private const String OMNIORB_NAME3 = "TestPy"; public static void Main(string[] args) { ChannelServices.RegisterChannel(new IiopClientChannel(), false); Test("Java SE ORB and Java Server (old style)", JAVASE_HOST, JAVASE_PORT, JAVASE_NAME1); Test("Java SE ORB and Java Server (new style)", JAVASE_HOST, JAVASE_PORT, JAVASE_NAME2); Test("IIOP.NET ORB and .NET Server", IIOPNET_HOST, IIOPNET_PORT, IIOPNET_NAME); Test("OmniORB ORB and C++ Server (old style)", OMNIORB_HOST, OMNIORB_PORT, OMNIORB_NAME1); Test("OmniORB ORB and C++ Server (new style)", OMNIORB_HOST, OMNIORB_PORT, OMNIORB_NAME2); Test("OmniORB ORB and Python Server", OMNIORB_HOST, OMNIORB_PORT, OMNIORB_NAME3); Console.ReadKey(); } } }