home *** CD-ROM | disk | FTP | other *** search
- using System;
- using System.Runtime.Remoting;
-
- namespace MyObjectLibrary
- {
- // This clas is a Client Activated Object
- public class Baz : MarshalByRefObject
- {
- public String _name;
- public int _totalNumber = 0;
-
- public Baz(String name)
- {
- Console.WriteLine("Baz constructor with args - name: " + name);
- _name = name;
- }
-
- public bool DoWorkWithNumber(int number)
- {
- lock(this)
- {
- Console.WriteLine("Change: " + number);
- _totalNumber += number;
- Console.WriteLine("Total: " + _totalNumber);
-
- }
-
- return true;
- }
-
- public int RetrieveTotalNumber()
- {
- return _totalNumber;
- }
-
- public String RetrieveName()
- {
- return _name;
- }
-
- protected override void Finalize()
- {
- Console.WriteLine("Baz Finalize called");
- }
- }
-
- // General class to demonstrate rich argument types
- public class Foo : MarshalByRefObject
- {
- public Foo()
- {
- }
-
- // fields
- public int intField;
- public double doubleField;
- public String stringField;
- public Object objectField;
-
- // methods
- public void VoidVoid()
- {
- }
-
- public void VoidInt4(int i)
- {
- }
-
- public void VoidString(String s)
- {
- }
-
- public void VoidByteArray(byte[] b)
- {
- }
-
- public String StringVoid()
- {
- return "String";
- }
-
- public String StringString(String s)
- {
- return s;
- }
-
- public byte[] ByteArrayByteArray(byte[] b)
- {
- return b;
- }
-
- // properties
- private int _intProperty = 0;
- private double _doubleProperty = 0.0;
- private String _stringProperty = "Default";
-
-
- public int IntProperty
- {
- get
- {
- return _intProperty;
- }
- set
- {
- _intProperty = value;
- }
- }
-
- public double DoubleProperty
- {
- get
- {
- return _doubleProperty;
- }
- set
- {
- _doubleProperty = value;
- }
- }
-
- public String StringProperty
- {
- get
- {
- return _stringProperty;
- }
- set
- {
- _stringProperty = value;
- }
- }
-
- // error cases
- public void ThrowsException()
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public void ThrowsException(int n)
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public void ThrowsException(String s)
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public void ThrowsException(Object o)
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public int ThrowsExceptionInt()
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public int ThrowsExceptionInt(int n)
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public int ThrowsExceptionInt(String s)
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public int ThrowsExceptionInt(Object o)
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public String ThrowsExceptionString()
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public String ThrowsExceptionString(int n)
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public String ThrowsExceptionString(String s)
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public Object ThrowsExceptionString(Object o)
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public Object ThrowsExceptionObject()
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public Object ThrowsExceptionObject(int n)
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public Object ThrowsExceptionObject(String s)
- {
- throw new RemotePerfException("Exception from server");
- }
-
- public Object ThrowsExceptionObject(Object o)
- {
- throw new RemotePerfException("Exception from server");
- }
- }
-
-
- //
- // Context Classes that show how to build a Context Attribute,
- // Property and Message Sink
- //
-
- [AttributeUsage(AttributeTargets.Class)]
- public class IsolationAttribute :
- ContextAttribute,
- IContributeServerContextSink,
- IContributeClientContextSink
- {
- private static String PROPERTY_NAME = "ContextIsolationAttribute";
-
- public IsolationAttribute()
- : base(PROPERTY_NAME)
- {
- }
-
- // Override ContextAttribute's implementation of IContextAttribute.IsContextOK
- public override bool IsContextOK(Context ctx, IConstructionCallMessage msg)
- {
- return base.IsContextOK(ctx, msg);
- }
-
- // Override ContextAttribute's impl. of IContextAttribute::GetPropForNewCtx
- public IContextProperty GetPropertyForNewContext(Object cookie)
- {
- return this;
- }
-
-
- public IMessageSink GetServerContextSink(IMessageSink nextSink)
- {
- return new IsolationSink(this, nextSink);
- }
-
- public IMessageSink GetClientContextSink(IMessageSink nextSink)
- {
- return new IsolationSink(this, nextSink);
- }
- }
-
- public class IsolationSink : IMessageSink
- {
- private IMessageSink _nextSink;
- private IsolationAttribute _prop;
-
- public IsolationSink(IsolationAttribute prop, IMessageSink nextSink)
- {
- _prop = prop;
- _nextSink = nextSink;
- }
-
- public IMessage SyncProcessMessage(IMessage reqMsg)
- {
- return _nextSink.SyncProcessMessage(reqMsg);
- }
-
- public IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
- {
- return _nextSink.AsyncProcessMessage(reqMsg, replySink);
- }
-
- public IMessageSink NextSink
- {
- get
- {
- return _nextSink;
- }
- }
-
- }
-
- public class RemotePerfException : Exception
- {
- public RemotePerfException(String s) : base(s){}
- }
-
-
- [IsolationAttribute()]
- class ContextBoundClassWithIsolationAttribute : ContextBoundObject
- {
-
- }
- }
-