SetIdentity() 개인적인 정적인 메소드

private static SetIdentity ( Identity idObj, String URI, DuplicateIdentityOption duplicateOption ) : Identity
idObj Identity
URI String
duplicateOption DuplicateIdentityOption
리턴 Identity
        internal static Identity FindOrCreateIdentity(string objURI, string URL, ObjRef objectRef)
        {
            Identity identity = null;
            bool     flag     = URL != null;

            identity = IdentityHolder.ResolveIdentity(flag ? URL : objURI);
            if (flag && identity != null && identity is ServerIdentity)
            {
                throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_WellKnown_CantDirectlyConnect"), URL));
            }
            if (identity == null)
            {
                identity = new Identity(objURI, URL);
                ReaderWriterLock tableLock = IdentityHolder.TableLock;
                bool             flag2     = !tableLock.IsWriterLockHeld;
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    if (flag2)
                    {
                        tableLock.AcquireWriterLock(int.MaxValue);
                    }
                    identity = IdentityHolder.SetIdentity(identity, null, DuplicateIdentityOption.UseExisting);
                    identity.RaceSetObjRef(objectRef);
                }
                finally
                {
                    if (flag2 && tableLock.IsWriterLockHeld)
                    {
                        tableLock.ReleaseWriterLock();
                    }
                }
            }
            return(identity);
        }
예제 #2
0
        internal static ServerIdentity FindOrCreateServerIdentity(MarshalByRefObject obj, string objURI, int flags)
        {
            bool           fServer;
            ServerIdentity serverIdentity1 = (ServerIdentity)MarshalByRefObject.GetIdentity(obj, out fServer);

            if (serverIdentity1 == null)
            {
                Context        serverCtx = !(obj is ContextBoundObject) ? IdentityHolder.DefaultContext : Thread.CurrentContext;
                ServerIdentity id        = new ServerIdentity(obj, serverCtx);
                if (fServer)
                {
                    serverIdentity1 = obj.__RaceSetServerIdentity(id);
                }
                else
                {
                    RealProxy      realProxy       = RemotingServices.GetRealProxy((object)obj);
                    ServerIdentity serverIdentity2 = id;
                    realProxy.IdentityObject = (Identity)serverIdentity2;
                    serverIdentity1          = (ServerIdentity)realProxy.IdentityObject;
                }
                if (IdOps.bIsInitializing(flags))
                {
                    serverIdentity1.IsInitializing = true;
                }
            }
            if (IdOps.bStrongIdentity(flags))
            {
                ReaderWriterLock tableLock = IdentityHolder.TableLock;
                bool             flag      = !tableLock.IsWriterLockHeld;
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    if (flag)
                    {
                        tableLock.AcquireWriterLock(int.MaxValue);
                    }
                    if (serverIdentity1.ObjURI == null || !serverIdentity1.IsInIDTable())
                    {
                        IdentityHolder.SetIdentity((Identity)serverIdentity1, objURI, DuplicateIdentityOption.Unique);
                    }
                    if (serverIdentity1.IsDisconnected())
                    {
                        serverIdentity1.SetFullyConnected();
                    }
                }
                finally
                {
                    if (flag && tableLock.IsWriterLockHeld)
                    {
                        tableLock.ReleaseWriterLock();
                    }
                }
            }
            return(serverIdentity1);
        }