本文整理汇总了C#中System.MarshalByRefObject.__RaceSetServerIdentity方法的典型用法代码示例。如果您正苦于以下问题:C# MarshalByRefObject.__RaceSetServerIdentity方法的具体用法?C# MarshalByRefObject.__RaceSetServerIdentity怎么用?C# MarshalByRefObject.__RaceSetServerIdentity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.MarshalByRefObject
的用法示例。
在下文中一共展示了MarshalByRefObject.__RaceSetServerIdentity方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindOrCreateServerIdentity
[System.Security.SecurityCritical] // auto-generated
internal static ServerIdentity FindOrCreateServerIdentity(
MarshalByRefObject obj, String objURI, int flags)
{
Message.DebugOut("Entered FindOrCreateServerIdentity \n");
ServerIdentity srvID = null;
bool fServer;
srvID = (ServerIdentity) MarshalByRefObject.GetIdentity(obj, out fServer);
if (srvID == null)
{
// Create a new server identity and add it to the
// table. IdentityHolder will take care of ----s
Context serverCtx = null;
if (obj is ContextBoundObject)
{
serverCtx = Thread.CurrentContext;
}
else
{
serverCtx = DefaultContext;
}
Contract.Assert(null != serverCtx, "null != serverCtx");
ServerIdentity serverID = new ServerIdentity(obj, serverCtx);
// Set the identity depending on whether we have the server or proxy
if(fServer)
{
srvID = obj.__RaceSetServerIdentity(serverID);
Contract.Assert(srvID == MarshalByRefObject.GetIdentity(obj), "Bad ID state!" );
}
else
{
RealProxy rp = null;
rp = RemotingServices.GetRealProxy(obj);
Contract.Assert(null != rp, "null != rp");
rp.IdentityObject = serverID;
srvID = (ServerIdentity) rp.IdentityObject;
}
Message.DebugOut("Created ServerIdentity \n");
}
#if false
// Check that we are asked to create the identity for the same
// URI as the one already associated with the server object.
// It is an error to associate two URIs with the same server
// object
// GopalK: Try eliminating the test because it is also done by GetOrCreateIdentity
if ((null != objURI) && (null != srvID.ObjURI))
{
if (string.Compare(objURI, srvID.ObjURI, StringComparison.OrdinalIgnoreCase) == 0) // case-insensitive compare
{
Message.DebugOut("Trying to associate a URI with identity again .. throwing execption \n");
throw new RemotingException(
String.Format(
Environment.GetResourceString(
"Remoting_ResetURI"),
srvID.ObjURI, objURI));
}
}
#endif
// NOTE: for purely x-context cases we never execute this ...
// the server ID is not put in the ID table.
if ( IdOps.bStrongIdentity(flags) )
{
// We need to guarantee that finally is not interrupted so that the lock is released.
// TableLock has a long path without reliability contract. To avoid adding contract on
// the path, we will use ReaderWriterLock directly.
ReaderWriterLock rwlock = TableLock;
bool takeAndRelease = !rwlock.IsWriterLockHeld;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
if (takeAndRelease)
rwlock.AcquireWriterLock(INFINITE);
// It is possible that we are marshaling out of this app-domain
// for the first time. We need to do two things
// (1) If there is no URI associated with the identity then go ahead
// and generate one.
// (2) Add the identity to the URI -> Identity map if not already present
// (For purely x-context cases we don't need the URI)
// (3) If the object ref is null, then this object hasn't been
// marshalled yet.
// (4) if id was created through SetObjectUriForMarshal, it would be
// in the ID table
if ((srvID.ObjURI == null) ||
(srvID.IsInIDTable() == false))
{
// we are marshalling a server object, so there should not be a
// a different identity at this location.
SetIdentity(srvID, objURI, DuplicateIdentityOption.Unique);
//.........这里部分代码省略.........
示例2: SetObjectUriForMarshal
public static void SetObjectUriForMarshal( MarshalByRefObject obj, String uri)
{
// if obj is ever Marshal'd it should use this uri. If a uri has
// already been assigned to the object, it should throw.
Message.DebugOut("Entered SetObjectUriForMarshal \n");
Identity idObj = null;
Identity srvIdObj = null;
bool fServer;
idObj = MarshalByRefObject.GetIdentity(obj, out fServer);
srvIdObj = idObj as ServerIdentity;
// Ensure that if we have a transparent proxy then we are not given a remoting
// proxy. This routine should only be called for objects that
// live in this AppDomains.
if ((idObj != null) &&
(srvIdObj == null)) // <-- means idObj is not a ServerIdentity
{
throw new RemotingException(
Environment.GetResourceString(
"Remoting_SetObjectUriForMarshal__ObjectNeedsToBeLocal"));
}
if ((idObj != null) && (idObj.URI != null))
{
throw new RemotingException(
Environment.GetResourceString(
"Remoting_SetObjectUriForMarshal__UriExists"));
}
if (idObj == null)
{
// obj is not ContextBound
Contract.Assert(!(obj is ContextBoundObject), "ContextBoundObject's shouldn't get here.");
// Create a new server identity and add it to the
// table. IdentityHolder will take care of ----s
Context serverCtx = null;
serverCtx = Thread.GetDomain().GetDefaultContext();
Contract.Assert(null != serverCtx, "null != serverCtx");
ServerIdentity serverID = new ServerIdentity(obj, serverCtx, uri);
// set the identity
idObj = obj.__RaceSetServerIdentity(serverID);
Contract.Assert(idObj == MarshalByRefObject.GetIdentity(obj), "Bad ID state!" );
// If our serverID isn't used then someone else marshalled the object
// before we could set the uri.
if (idObj != serverID)
{
throw new RemotingException(
Environment.GetResourceString(
"Remoting_SetObjectUriForMarshal__UriExists"));
}
}
else
{
// This is the ContextBoundObject case
Contract.Assert(obj is ContextBoundObject, "Object should have been a ContextBoundObject.");
idObj.SetOrCreateURI(uri, true);
}
Message.DebugOut("Created ServerIdentity \n");
} // SetObjectUriForMarshal
示例3: FindOrCreateServerIdentity
internal static ServerIdentity FindOrCreateServerIdentity(MarshalByRefObject obj, string objURI, int flags)
{
ServerIdentity idObj = null;
bool flag;
idObj = (ServerIdentity) MarshalByRefObject.GetIdentity(obj, out flag);
if (idObj == null)
{
Context serverCtx = null;
if (obj is ContextBoundObject)
{
serverCtx = Thread.CurrentContext;
}
else
{
serverCtx = DefaultContext;
}
ServerIdentity id = new ServerIdentity(obj, serverCtx);
if (flag)
{
idObj = obj.__RaceSetServerIdentity(id);
}
else
{
RealProxy realProxy = null;
realProxy = RemotingServices.GetRealProxy(obj);
realProxy.IdentityObject = id;
idObj = (ServerIdentity) realProxy.IdentityObject;
}
}
if (IdOps.bStrongIdentity(flags))
{
ReaderWriterLock tableLock = TableLock;
bool flag2 = !tableLock.IsWriterLockHeld;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
if (flag2)
{
tableLock.AcquireWriterLock(0x7fffffff);
}
if ((idObj.ObjURI == null) || !idObj.IsInIDTable())
{
SetIdentity(idObj, objURI, DuplicateIdentityOption.Unique);
}
if (idObj.IsDisconnected())
{
idObj.SetFullyConnected();
}
}
finally
{
if (flag2 && tableLock.IsWriterLockHeld)
{
tableLock.ReleaseWriterLock();
}
}
}
return idObj;
}
示例4: FindOrCreateServerIdentity
} // CasualResolveReference
//
//
// This is typically called when we need to create/establish
// an identity for a serverObject.
internal static ServerIdentity FindOrCreateServerIdentity(
MarshalByRefObject obj, String objURI, int flags)
{
Message.DebugOut("Entered FindOrCreateServerIdentity \n");
ServerIdentity srvID = null;
bool bLock = false;
try
{
bool fServer;
srvID = (ServerIdentity) MarshalByRefObject.GetIdentity(obj, out fServer);
if (srvID == null)
{
// Create a new server identity and add it to the
// table. IdentityHolder will take care of races
Context serverCtx = null;
if (obj is ContextBoundObject)
{
serverCtx = Thread.CurrentContext;
}
else
{
serverCtx = DefaultContext;
}
BCLDebug.Assert(null != serverCtx, "null != serverCtx");
ServerIdentity serverID = new ServerIdentity(obj, serverCtx);
// Set the identity depending on whether we have the server or proxy
if(fServer)
{
srvID = obj.__RaceSetServerIdentity(serverID);
BCLDebug.Assert(srvID == MarshalByRefObject.GetIdentity(obj), "Bad ID state!" );
}
else
{
RealProxy rp = null;
rp = RemotingServices.GetRealProxy(obj);
BCLDebug.Assert(null != rp, "null != rp");
rp.IdentityObject = serverID;
srvID = (ServerIdentity) rp.IdentityObject;
}
Message.DebugOut("Created ServerIdentity \n");
}
// NOTE: for purely x-context cases we never execute this ...
// the server ID is not put in the ID table.
if ( IdOps.bStrongIdentity(flags) )
{
TableLock.AcquireWriterLock(INFINITE);
bLock = true;
// It is possible that we are marshaling out of this app-domain
// for the first time. We need to do two things
// (1) If there is no URI associated with the identity then go ahead
// and generate one.
// (2) Add the identity to the URI -> Identity map if not already present
// (For purely x-context cases we don't need the URI)
// (3) If the object ref is null, then this object hasn't been
// marshalled yet.
// (4) if id was created through SetObjectUriForMarshal, it would be
// in the ID table
if ((srvID.ObjURI == null) ||
(srvID.IsInIDTable() == false))
{
// we are marshalling a server object, so there should not be a
// a different identity at this location.
SetIdentity(srvID, objURI, DuplicateIdentityOption.Unique);
}
// If the object is marked as disconnect, mark it as connected
if(srvID.IsDisconnected())
srvID.SetFullyConnected();
}
}
finally
{
if (bLock)
{
TableLock.ReleaseWriterLock();
}
}
Message.DebugOut("Leaving FindOrCreateServerIdentity \n");
BCLDebug.Assert(null != srvID,"null != srvID");
return srvID;
}
示例5: SetObjectUriForMarshal
public static void SetObjectUriForMarshal(MarshalByRefObject obj, string uri)
{
Identity identity = null;
Identity identity2 = null;
bool flag;
identity = MarshalByRefObject.GetIdentity(obj, out flag);
identity2 = identity as ServerIdentity;
if ((identity != null) && (identity2 == null))
{
throw new RemotingException(Environment.GetResourceString("Remoting_SetObjectUriForMarshal__ObjectNeedsToBeLocal"));
}
if ((identity != null) && (identity.URI != null))
{
throw new RemotingException(Environment.GetResourceString("Remoting_SetObjectUriForMarshal__UriExists"));
}
if (identity == null)
{
Context serverCtx = null;
serverCtx = Thread.GetDomain().GetDefaultContext();
ServerIdentity id = new ServerIdentity(obj, serverCtx, uri);
if (obj.__RaceSetServerIdentity(id) != id)
{
throw new RemotingException(Environment.GetResourceString("Remoting_SetObjectUriForMarshal__UriExists"));
}
}
else
{
identity.SetOrCreateURI(uri, true);
}
}