CleanupIdentities() private static method

private static CleanupIdentities ( Object state ) : void
state Object
return void
        internal static void FlushIdentityTable()
        {
            ReaderWriterLock tableLock = IdentityHolder.TableLock;
            bool             flag      = !tableLock.IsWriterLockHeld;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                if (flag)
                {
                    tableLock.AcquireWriterLock(int.MaxValue);
                }
                IdentityHolder.CleanupIdentities(null);
            }
            finally
            {
                if (flag && tableLock.IsWriterLockHeld)
                {
                    tableLock.ReleaseWriterLock();
                }
            }
        }
        private static Identity SetIdentity(Identity idObj, string URI, DuplicateIdentityOption duplicateOption)
        {
            bool flag = idObj is ServerIdentity;

            if (idObj.URI == null)
            {
                idObj.SetOrCreateURI(URI);
                if (idObj.ObjectRef != null)
                {
                    idObj.ObjectRef.URI = idObj.URI;
                }
            }
            string key = IdentityHolder.MakeURIKey(idObj.URI);
            object obj = IdentityHolder.URITable[key];

            if (obj != null)
            {
                WeakReference weakReference = obj as WeakReference;
                Identity      identity;
                bool          flag2;
                if (weakReference != null)
                {
                    identity = (Identity)weakReference.Target;
                    flag2    = (identity is ServerIdentity);
                }
                else
                {
                    identity = (Identity)obj;
                    flag2    = (identity is ServerIdentity);
                }
                if (identity != null && identity != idObj)
                {
                    if (duplicateOption == DuplicateIdentityOption.Unique)
                    {
                        string uri = idObj.URI;
                        throw new RemotingException(Environment.GetResourceString("Remoting_URIClash", new object[]
                        {
                            uri
                        }));
                    }
                    if (duplicateOption == DuplicateIdentityOption.UseExisting)
                    {
                        idObj = identity;
                    }
                }
                else if (weakReference != null)
                {
                    if (flag2)
                    {
                        IdentityHolder.URITable[key] = idObj;
                    }
                    else
                    {
                        weakReference.Target = idObj;
                    }
                }
            }
            else
            {
                object value;
                if (flag)
                {
                    value = idObj;
                    ((ServerIdentity)idObj).SetHandle();
                }
                else
                {
                    value = new WeakReference(idObj);
                }
                IdentityHolder.URITable.Add(key, value);
                idObj.SetInIDTable();
                IdentityHolder.SetIDCount++;
                if (IdentityHolder.SetIDCount % 64 == 0)
                {
                    IdentityHolder.CleanupIdentities(null);
                }
            }
            return(idObj);
        }
Beispiel #3
0
        private static Identity SetIdentity(Identity idObj, string URI, DuplicateIdentityOption duplicateOption)
        {
            bool flag1 = idObj is ServerIdentity;

            if (idObj.URI == null)
            {
                idObj.SetOrCreateURI(URI);
                if (idObj.ObjectRef != null)
                {
                    idObj.ObjectRef.URI = idObj.URI;
                }
            }
            string str  = IdentityHolder.MakeURIKey(idObj.URI);
            object obj1 = IdentityHolder.URITable[(object)str];

            if (obj1 != null)
            {
                WeakReference weakReference = obj1 as WeakReference;
                Identity      identity;
                bool          flag2;
                if (weakReference != null)
                {
                    identity = (Identity)weakReference.Target;
                    flag2    = identity is ServerIdentity;
                }
                else
                {
                    identity = (Identity)obj1;
                    flag2    = identity is ServerIdentity;
                }
                if (identity != null && identity != idObj)
                {
                    if (duplicateOption != DuplicateIdentityOption.Unique)
                    {
                        if (duplicateOption == DuplicateIdentityOption.UseExisting)
                        {
                            idObj = identity;
                        }
                    }
                    else
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_URIClash", (object)idObj.URI));
                    }
                }
                else if (weakReference != null)
                {
                    if (flag2)
                    {
                        IdentityHolder.URITable[(object)str] = (object)idObj;
                    }
                    else
                    {
                        weakReference.Target = (object)idObj;
                    }
                }
            }
            else
            {
                object obj2;
                if (flag1)
                {
                    obj2 = (object)idObj;
                    ((ServerIdentity)idObj).SetHandle();
                }
                else
                {
                    obj2 = (object)new WeakReference((object)idObj);
                }
                IdentityHolder.URITable.Add((object)str, obj2);
                idObj.SetInIDTable();
                ++IdentityHolder.SetIDCount;
                if (IdentityHolder.SetIDCount % 64 == 0)
                {
                    IdentityHolder.CleanupIdentities((object)null);
                }
            }
            return(idObj);
        }