home *** CD-ROM | disk | FTP | other *** search
- //==========================================================================
- // File: MyObjectApp.cs
- //
- // Summary: This file implements client side of NGWS Remoting.
- // It illustrates NGWS Remoting
- //
- // Classes: MyObjectApp
- //
- //--------------------------------------------------------------------------
- // This file is part of the Microsoft NGWS Samples.
- //
- // Copyright (C) 1999 Microsoft Corporation. All rights reserved.
- //==========================================================================
-
- using System;
- using System.Text;
- using System.Security.Policy;
- using System.Runtime.Remoting;
- using System.IO;
-
- using MyObjectLibrary;
-
- public class MyObjectApp
- {
- static int batchsize=10;
-
- public static int Main(string[] args)
- {
- int ret = Initialize(args);
- Console.WriteLine("Stock Remoting Sample\n");
-
- if (ret != -1)
- {
- switch (scenario)
- {
- case 1:
- Scenario1();
- break;
- case 2:
- Scenario2();
- break;
- case 3:
- Scenario3();
- break;
- case 4:
- Scenario4();
- break;
- }
- }
-
- Console.WriteLine("\nEnd\n");
-
- return ret;
- }
-
- public static int Scenario1()
- {
- // Single new
- int BatchNewStartTC=0;
- int BatchNewDurTC=0;
- BatchNewStartTC = Environment.TickCount;
-
- Foo foo;
- foo = new Foo();
-
- BatchNewDurTC = Environment.TickCount - BatchNewStartTC;
- if (BatchNewDurTC < 1) BatchNewDurTC = 1;
- Console.WriteLine("Single New: {0} ms, {1} ms/call {2} calls/sec", BatchNewDurTC, BatchNewDurTC / batchsize, batchsize / BatchNewDurTC);
-
- // Disconnect
- //RemotingServices.Disconnect(foo);
-
- return 0;
- }
-
- public static int Scenario2()
- {
- //
- // Batch new
- //
-
- int BatchNewStartTC=0;
- int BatchNewDurTC=0;
- BatchNewStartTC = Environment.TickCount;
-
- for (int m=0;m<batchsize;m++)
- {
- Foo foo;
- foo = new Foo();
- foo = null;
- }
-
- BatchNewDurTC = Environment.TickCount - BatchNewStartTC;
- if (BatchNewDurTC < 1) BatchNewDurTC = 1;
- Console.WriteLine("Batch New: {0} ms, {1} ms/call {2} calls/sec", BatchNewDurTC, BatchNewDurTC / batchsize, batchsize / BatchNewDurTC);
-
- return 0;
- }
-
-
- public static void Scenario3()
- {
- bool result = true;
-
- Console.WriteLine("new Baz");
-
- Baz baz = new Baz("John Smith");
-
- Console.WriteLine("Name: " + baz.RetrieveName());
-
- for (int i=0; i < 10; i++)
- {
- Console.WriteLine("bazDoWorkWithNumber (100)");
- result = baz.DoWorkWithNumber(100);
- Console.WriteLine("After DoWorkWithNumber Total Number is " + baz.RetrieveTotalNumber());
-
- Console.WriteLine("bazDoWorkWithNumber (75)");
- result = baz.DoWorkWithNumber(75);
- Console.WriteLine("After DoWorkWithNumber Total Number is " + baz.RetrieveTotalNumber());
-
- Console.WriteLine("bazDoWorkWithNumber (-50)");
- result = baz.DoWorkWithNumber(-50);
- Console.WriteLine("After DoWorkWithNumber Total Number is " + baz.RetrieveTotalNumber());
- }
-
- /*ILease lease = (ILease)baz.GetLifetimeService();
-
- Console.WriteLine("CurrentLeaseTime " + lease.CurrentLeaseTime);
- Console.WriteLine("InitialLeaseTime " + lease.InitialLeaseTime);
- Console.WriteLine("RenewOnCallTime " + lease.RenewOnCallTime);
- Console.WriteLine("SponsorshipTimeout " + lease.SponsorshipTimeout);
-
- lease = null;
- */
-
- // baz = null;
-
- // Console.WriteLine("Sleeping for 45 seconds");
- // System.Threading.Thread.Sleep(45000);
-
- }
-
- public static int Scenario4()
- {
- Foo foo;
- foo = new Foo();
-
- return Scenario10(foo);
- }
-
-
- public static int Scenario10(Foo foo)
- {
- byte[] bytearray1 = new byte[1];
- byte[] bytearray1024 = new byte[1024];
- byte[] bytearray4096 = new byte[4096];
-
- String string1 = new StringBuilder(1).ToString();
- String string1024 = new StringBuilder(1024).ToString();
- String string4096 = new StringBuilder(4096).ToString();
-
- // Calls
-
- {
- int batch = batchsize;
-
- int endpointStartTC=0;
- int endpointDurTC=0;
- endpointStartTC = Environment.TickCount;
-
- int startTC=0;
- int durTC=0;
-
- startTC = Environment.TickCount;
- foo.VoidVoid();
- durTC = Environment.TickCount - startTC;
- Console.WriteLine("VoidVoid : {0} ms, - first call", durTC);
- Console.WriteLine("");
-
- startTC = Environment.TickCount;
- for (int i=0;i<batch;i++)
- foo.VoidVoid();
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("VoidVoid : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
- /*
-
- int intField=1;
- //double doubleField=2.3;
- //String stringField="String";
- Object objectField = new Object();
-
- //int Field Set
- startTC = Environment.TickCount;
- for (int i=0;i<batch;i++)
- foo.intField = intField;
- durTC = Environment.TickCount - startTC;
- Console.WriteLine("intField Set: {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
- */
-
- /*
- //int Field Get
- startTC = Environment.TickCount;
- for(int i=0;i<batch;i++)
- intField = foo.intField;
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("intField Get: {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
-
-
- //double Field Set
- startTC = Environment.TickCount;
- for(int i=0;i<batch;i++)
- foo.doubleField = doubleField;
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("doubleField Set: {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
- //double Field Get
- startTC = Environment.TickCount;
- for(int i=0;i<batch;i++)
- doubleField = foo.doubleField;
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("doubleField Get: {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
- //String Field Set
- startTC = Environment.TickCount;
- for(int i=0;i<batch;i++)
- foo.stringField = stringField;
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("stringField Set: {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
- //String Field Get
- startTC = Environment.TickCount;
- for(int i=0;i<batch;i++)
- stringField = foo.stringField;
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("stringField Get: {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
- //Object Field Set
- startTC = Environment.TickCount;
- for(int i=0;i<batch;i++)
- foo.objectField = objectField;
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("objectField Set: {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
- //Object Field Get
- startTC = Environment.TickCount;
- for(int i=0;i<batch;i++)
- objectField = foo.objectField;
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("objectField Get: {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
- */
-
- startTC = Environment.TickCount;
- for (int i=0;i<batch;i++)
- foo.VoidInt4(1);
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("VoidInt4 : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
- startTC = Environment.TickCount;
- for (int i=0;i<batch;i++)
- foo.VoidString("String");
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("VoidString : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
- //
- startTC = Environment.TickCount;
- for (int i=0;i<batch;i++)
- foo.VoidByteArray(bytearray1);
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("VoidByteArray (1) : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
- //
- startTC = Environment.TickCount;
- for (int i=0;i<batch;i++)
- foo.VoidByteArray(bytearray1024);
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("VoidByteArray (1024) : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
- //
- startTC = Environment.TickCount;
- for (int i=0;i<batch;i++)
- foo.VoidByteArray(bytearray4096);
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("VoidByteArray (4096) : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
- //
-
- //
- startTC = Environment.TickCount;
- for (int i=0;i<batch;i++)
- {
- String s = foo.StringVoid();
- }
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("StringVoid : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
-
- //
-
- {
- startTC = Environment.TickCount;
- for (int i=0;i<batch;i++)
- {
- String StringRet = foo.StringString(string1);
- }
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("String (1) String (1) : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
- }
-
- {
- startTC = Environment.TickCount;
- for (int i=0;i<batch;i++)
- {
- String StringRet = foo.StringString(string1024);
- }
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("String1024 String1024 (2048) : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
- }
-
- //
- {
- startTC = Environment.TickCount;
- for (int i=0;i<batch;i++)
- {
- String StringRet = foo.StringString(string4096);
- }
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("String4096 String4096 (8192) : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
- }
- //
-
-
-
- /*
-
- {
- startTC = Environment.TickCount;
- for(int i=0;i<batch;i++)
- {
- byte[] bytearrayRet = foo.ByteArrayByteArray(bytearray1);
- }
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("ByteArray (1) ByteArray (1) : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
- }
-
- {
- startTC = Environment.TickCount;
- for(int i=0;i<batch;i++)
- {
- byte[] bytearrayRet = foo.ByteArrayByteArray(bytearray1024);
- }
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("ByteArray1024 ByteArray1024 (2048) : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
- }
-
- //
- {
- startTC = Environment.TickCount;
- for(int i=0;i<batch;i++)
- {
- byte[] bytearrayRet = foo.ByteArrayByteArray(bytearray4096);
- }
- durTC = Environment.TickCount - startTC;
- if (durTC < 1) durTC = 1;
- Console.WriteLine("ByteArray4096 ByteArray4096 (8192) : {0} ms, {1} ms/call {2} calls/sec", durTC, durTC / batch, (batch * 1000) / durTC);
- }
- //
- */
-
- Console.WriteLine("");
- endpointDurTC = Environment.TickCount - endpointStartTC;
- Console.WriteLine("Endpoint time : {0} ms",
- endpointDurTC);
- Console.WriteLine("");
- }
-
- return 0;
- }
-
-
-
- //---------------------------------------------------
- public static int scenario = 1;
-
- public static int Initialize(String[] args)
- {
- if (args.Length == 0)
- {
- RemotingServices.ConfigureRemoting("MyObjectApp.cfg");
- return 0;
- }
-
-
- for (int i=0;i<args.Length;i++)
- {
- if (
- String.Compare(args[i],"HELP", true) == 0 ||
- String.Compare(args[i],"?", true) == 0 ||
- String.Compare(args[i],"/h", true) == 0 ||
- String.Compare(args[i],"-h", true) == 0 ||
- String.Compare(args[i],"-?", true) == 0 ||
- String.Compare(args[i],"/?", true) == 0
- )
- {
- Usage();
- return -1;
- }
-
- if (args[i].CompareTo("-b")==0)
- {
- batchsize = Int32.Parse(args[i+1]);
- i++;
- }
-
- if (args[i].CompareTo("-s1")==0)
- {
- scenario = 1;
- }
-
-
- if (args[i].CompareTo("-s2")==0)
- {
- scenario = 2;
- }
-
-
- if (args[i].CompareTo("-s3")==0)
- {
- scenario = 3;
- }
-
- if (args[i].CompareTo("-s4")==0)
- {
- scenario = 4;
- }
-
-
- if (args[i].CompareTo("-cfg")==0)
- {
- RemotingServices.ConfigureRemoting(args[i+1]);
- }
- }
-
- return 0;
- }
-
- public static void Usage()
- {
- Console.WriteLine("Usage: MyObjectApp [-b batchsize] [-s1/-s2/-s3/-s4] [-cfg Configfile.cfg]\n");
- Console.WriteLine("Examples : MyObjectApp");
- Console.WriteLine("Examples : MyObjectApp -b 10");
- Console.WriteLine("Examples : MyObjectApp -s1 (single new)");
- Console.WriteLine("Examples : MyObjectApp -b 10 -s2 (batch new)");
- Console.WriteLine("Examples : MyObjectApp -s3 (Activation)");
- Console.WriteLine("Examples : MyObjectApp -s4 (Coverage)");
- Console.WriteLine("Examples : MyObjectApp -b 10 -cfg MyObjectApp.cfg");
- Console.WriteLine("Examples : MyObjectApp -cfg MyObjectApp.cfg");
- }
- }
-
-