NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Remoting Context Reference

Context Reference

public class Context
{
   public Context();
   public Int32 ContextID {get;}
   public IContextProperty[] ContextProperties {get;}
   public static Context DefaultContext {get;}
   public virtual IContextProperty GetProperty(String name);
   public virtual void SetProperty(IContextProperty prop);
   public virtual void Freeze()
   public override String ToString();

   public void DoCallBack(CrossContextDelegate deleg)

   public static LocalDataStoreSlot AllocateDataSlot()
   public static LocalDataStoreSlot AllocateNamedDataSlot(String name)
   public static LocalDataStoreSlot GetNamedDataSlot(String name)
   public static void FreeNamedDataSlot(String name)
   public static void SetData(LocalDataStoreSlot slot, Object data)
   public static Object GetData(LocalDataStoreSlot slot)

   public static bool RegisterDynamicProperty(
               IDynamicProperty prop, 
               MarshalByRefObject obj, 
               Context ctx);
   public static bool UnregisterDynamicProperty(
               String name, 
               MarshalByRefObject obj, 
               Context ctx);
}

Context

Initializes a new Context.

ContextID

Returns the Context ID for the Context.

ContextProperties

This read-only property returns an array of the context properties.

DefaultContext

This read-only property returns the default context for the AppDomain. Every thread in an app domain for which a context is not explicitly set is considered to be running in the DefaultContext.

GetProperty

Returns a specific context property by name.

SetProperty

Sets a specific context property by name.

Freeze

Freeze the context. Context properties cannot be added after the context has been frozen.

ToString

String representation of the context.

DoCallback

Used to execute code in another context. A callback may be done by calling the DoCallBack method on it by passing in a delegate. The delegate used to request a callback. The delegate must be of type CrossContextDelegate.

RegisterDynamicProperty

This allows users to register a property implementing IContributeDynamicSink with the remoting service. Based on the obj and ctx parameters, the property is asked to contribute a sink that is placed at some location in the path of remoting calls.

If multiple properties are registered, their sinks may be called in an arbitrary order that may change between calls.

Parameters

Parameters Description
name String name for property
property An object that implements IContributeDynamicSink
obj The object/proxy for which the property is registered , may be null.
ctx The context for which the property is registered.

Remarks

If obj is non null then if it is a proxy, all calls made on the proxy are intercepted otherwise if it is a real object, all calls on the object are intercepted the ctx argument must be null

If ctx is non-null then the obj argument must be null and all calls entering and leaving the context are intercepted

If both ctx and obj are null then all calls entering and leaving all contexts are intercepted.

UnregisterDynamicProperty

The property may be unregistered, which implies that the sink will be dropped for subsequent remoting calls.

Unregister dynamic property. See RegisterDynamicProperty. Name, obj, ctx arguments should be exactly the same as a previous RegisterDynamicProperty call.

AllocateDataSlot

Allocates an un-named data slot. The slot is allocated on ALL the contexts.

AllocateNamedDataSlot

Allocates a named data slot. The slot is allocated on ALL the contexts. Named data slots are "public" and can be manipulated by anyone.

GetNamedDataSlot

Looks up a named data slot. If the name has not been used, a new slot is allocated. Named data slots are "public" and can be manipulated by anyone.

FreeNamedDataSlot

Frees a named data slot. The slot is allocated on ALL the contexts. Named data slots are "public" and can be manipulated by anyone.

GetData

Retrieves the value from the specified slot on the current context.

SetData

Sets the data in the specified slot on the current context.

ContextProperty Reference

The properties that make up the context are provided by various automatic services and are setup by Activation Services at the time the Context is created. Each property is itself a managed object. Depending upon whether properties contribute MessageSinks or not, we look upon them as being Active or Passive.

A ContextProperty is a name-value pair holding the property name and the object representing the property in a context. An array of these is returned by Context::GetContextProperties().

class ContextProperty
{
  public String Name {get;}
  public Object Property {get;}
};

Name

This read-only property returns the name of the context property.

Property

This read-only property returns the actual context property object.

CrossContextDelegate Reference

Delegate defined for context call backs. It is expected to be a function on an agile object.

delegate void CrossContextDelegate();

ContextAttribute Reference

ContextAttribute is the root for all context attributes. ContextAttribute provides the default implementations of IContextAttribute and IContextProperty. Simple Context properties can derived from ContextAttribute with the context attribute and the context property being in the class. For more specialized or more sophisticated needs the context attribute still derives from ContextAttribute and context property can be split into a separated class.

[AttributeUsage(AttributeTargets.Class)]
public class ContextAttribute
   : IContextAttribute, IContextPropery
{
   . . . 
   // Default Context Attribute implementation
   . . . 
};

IContextAttribute Reference

The current context that the thread is executing in and construction call message are passed to the attributes (attributes on the class, call site attributes) via IContextAttribute.IsContextOK. It must return & must return false if it wants to go out of context.

“Prototype” context properties are collected by asking the attributes for context properties.

IContextAttribute is exposed from all context attributes. It is used to determine whether a particular context is OK for the context attribute and returns a context property for a new context.

public interface IContextAttribute
{
  public bool IsContextOK(
                     Context ctx,
                     IConstructionCallMessage msg,  
                  );

  public void GetPropertiesForNewContext(
                     IConstructionCallMessage msg);
}

IsContextOK

Returns whether the context parameter meets the context attribute’s requirements.

GetPropertiesForNewContext

The Attribute can add Context Properties directly to the __ContextProperties List in the IConstructionCallMessage. The context properties will be added to the new context. The default implementation in ContextAttribute will add this to the context property List. Context attributes are free to override GetPropertiesForNewContext and can implement their own behaviour e.g. add a new class that implements the context property to the List.

IContextProperty Reference

IContextProperty is exposed from all context properties. It is used to gather naming information from the context property and also to determine whether the new context is ok for the context property.

public interface IContextProperty
{
    public String Name  {get; };
    public boolean IsNewContextOK(Context newCtx);
    public void Freeze(Context newContext);
}  

Name

Returns the name of the Context Property.

IsNewContextOK

Once all the context properties have been added to the new context, they are all asked whether they are OK in the new context. The context property could look at the other context properties from the parameter new context and determine whether it is ok coexisting with these other context properties. Returns false if not ok in the context.

Freeze

Called when the context is frozen.

IContributeClientContextSink Reference

The IContributeClientContextSink interface is implemented by context properties in a Context that wish to contribute an interception sink at the context boundary on the client end of a remoting call. The Client Context Chain is composed from those properties in the client context that implement IContributeClientContextSink interface and which to contribute a sink via the GetClientContextSink method call. This chain is cached for future use.

interface IContributeClientContextSink
{
  public IMessageSink GetClientContextSink(IMessageSink nextSink);
};

GetClientContextSink

Takes the first sink in the chain of sinks composed so far, chains its message sink in front of the chain formed and returns the composite sink chain.

IContributeServerContextSink Reference

The IContributeServerContextSink interface is implemented by context properties in a Context that wish to contribute an interception sink at the context boundary on the server end of a remoting call. The Server Context Chain is composed from those properties in the server context that implement IContributeServerContextSink interface and which contribute a sink via the GetServerContextSink method call. This chain is cached for future use. Thread Affinity could be an example of such a context property i.e. in this case the MessageSink would involve switching to a specific thread before processing a call further.

interface IContributeServerContextSink
{
  public IMessageSink GetServerContextSink(IMessageSink nextSink);
};

GetServerContextSink

Takes the first sink in the chain of sinks composed so far, chains its message sink in front of the chain formed and returns the composite sink chain.

IContributeObjectSink Reference

The IContributeObjectSink interface is implemented by context properties in a Context that wish to contribute an object specific interception sink on the server end of a remoting call. The Server Object Chain is composed from those context properties in the server object's context that implement IContributeObjectSink interface. [Just-In-Time activation would be an example of such a property i.e. the message sink would activate the object after the call arrives and then pass the message on to the object.]

Note: Server object sinks are per object i.e. the Context Property is free to add one sink per context-bound object.

interface IContributeObjectSink
{
  public IMessageSink GetObjectSink(
                  MarshalByRefObject obj, 
                  IMessageSink nextSink);
};

GetObjectSink

Takes the object and the first sink in the chain of sinks composed so far, chains its message sink in front of the chain formed and returns the composite sink chain.

IContributeEnvoySink Reference

The IContributeEnvoySink interface is implemented by context properties in the Server Context that wish to contribute an envoy message sink on the client end. The Server Envoy Chain is composed from those context properties that implement IContributeEnvoySink interface. The Envoy Chain lives on the client end and acts as representative of the corresponding message sinks from the server context properties.

Note: Envoy object sinks are per object i.e. the Context Property is free to add one sink per context-bound object.

interface IContributeEnvoySink
{
  public IMessageSink GetEnvoySink (
                   MarshalByRefObject obj,
                   IMessageSink nextSink
                   );
};

GetEnvoySink

Takes the first sink in the chain of sinks composed so far, chain its message sink in front of the chain formed. Used as an optimization to create envoy sink when the destination is a different context in the same application domain and is used by the Wrap operation.

ContextStaticAttribute Reference

Used to mark static field to be relative to the context.