|
using System;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
namespace TestLibrary {
using InterfaceLibrary;
public class TestObject : MarshalByRefObject, ITestObject {
public delegate String Delegate(String s);
public TestObject() : this(String.Empty) {
}
public TestObject(String name) {
Console.WriteLine("{0}: Object Constructor called.", name);
this.name = name;
counter = 0;
}
String name = "TestObject";
static public int counter = 0;
public String Ping()
{
counter++;
Console.WriteLine("\nEntering Ping() on {0}, counter {1}", name, counter);
return String.Format("Returning from Ping() on {0}, counter {1}", name, counter);
}
[OneWay] public void OneWayMethod(String s) {
Console.WriteLine("\nEntering OneWayMethod() on {0} with parameter {1}", name, s);
}
public void RegularMethod(String s) {
Console.WriteLine("\nEntering RegularMethod() on {0} with parameter {1}", name, s);
}
public String AsyncMethod(String s) {
Console.WriteLine("\nEntering AsyncMethod() on {0} with parameter {1}", name, s);
return String.Format("Returning from AsyncMethod() with {0} on {1}", s, name);
}
public String CallMe(ICallbackObject cb) {
Console.WriteLine("\nEntering CallMe() on {0}", name);
Console.WriteLine("{0}: Trying a callback...", name);
String result = cb.Callback(String.Format("Calling back from CallMe() on {0} ...", name));
Console.WriteLine("Callback result: {0}", result);
return String.Format("Returning from CallMe() on {0}", name);
}
public String CallMeOneWay(ICallbackObject cb) {
Console.WriteLine("\nEntering CallMeOneWay() on {0}", name);
Console.WriteLine("{0}: Trying a one way callback ...", name);
cb.OneWayCallback(String.Format("Calling back from CallMeOneWay() on {0} ...", name));
return String.Format("Returning from CallMeOneWay() on {0}", name);
}
public String CallMeAsync(ICallbackObject cb) {
Console.WriteLine("\nEntering CallMeAsync() on {0}", name);
Console.WriteLine("{0}: Trying async callback ...", name);
Delegate async = new Delegate(cb.AsyncCallback);
IAsyncResult asyncResult = async.BeginInvoke(String.Format("Calling back from CallMeAsync() on {0} ...", name), null, null);
//
//Wait for the call to complete
//
asyncResult.AsyncWaitHandle.WaitOne();
String result = async.EndInvoke(asyncResult);
Console.WriteLine("Callback result: {0}", result);
return String.Format("Returning from CallMeAsync() on {0}", name);
}
}
public class KnossosObject : TestObject, IKnossosObject {
public KnossosObject() : base("knossos") { }
}
public class ZakrosObject : TestObject, IZakrosObject {
public ZakrosObject() : base("zakros") { }
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am a consultant, trainer, software archtect/engineer, since the early 1980s, working in the greater area of Boston, MA, USA.
My work comprises the entire spectrum of software, shrink-wrapped applications, IT client-server, systems and protocol related work, compilers and operating systems, and more ....
I am currently focused on platform development for distributed computing in service oriented data centers.