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);
        }
Exemplo n.º 2
0
        internal void SetOrCreateURI(String uri, bool bIdCtor)
        {
            if (bIdCtor == false)
            {
                // This method is called either from the ID Constructor or
                // with a writeLock on the ID Table
                BCLDebug.Assert(IdentityHolder.IsWriterLockHeld(), "IDTable should be write-locked");
                if (null != _ObjURI)
                {
                    throw new RemotingException(
                              Environment.GetResourceString("Remoting_SetObjectUriForMarshal__UriExists"));
                }
            }

            if (null == uri)
            {
                // We insert the tick count, so that the uri is not 100% predictable.
                // (i.e. perhaps we should consider using a random number as well)
                _ObjURI = IDGuidString + Environment.TickCount + "_" + GetNextSeqNum() + ".rem";
            }
            else
            {
                if (this is ServerIdentity)
                {
                    _ObjURI = IDGuidString + uri;
                }
                else
                {
                    _ObjURI = uri;
                }
            }
        } // SetOrCreateURI
Exemplo n.º 3
0
 internal virtual void AssertValid()
 {
     if (this.URI != null)
     {
         Identity identity = IdentityHolder.ResolveIdentity(this.URI);
     }
 }
        internal static Identity ResolveIdentity(string URI)
        {
            if (URI == null)
            {
                throw new ArgumentNullException("URI");
            }
            ReaderWriterLock tableLock = IdentityHolder.TableLock;
            bool             flag      = !tableLock.IsReaderLockHeld;

            RuntimeHelpers.PrepareConstrainedRegions();
            Identity result;

            try
            {
                if (flag)
                {
                    tableLock.AcquireReaderLock(int.MaxValue);
                }
                result = IdentityHolder.ResolveReference(IdentityHolder.URITable[IdentityHolder.MakeURIKey(URI)]);
            }
            finally
            {
                if (flag && tableLock.IsReaderLockHeld)
                {
                    tableLock.ReleaseReaderLock();
                }
            }
            return(result);
        }
Exemplo n.º 5
0
 internal virtual void AssertValid()
 {
     if (this.URI == null)
     {
         return;
     }
     IdentityHolder.ResolveIdentity(this.URI);
 }
Exemplo n.º 6
0
 internal virtual void AssertValid()
 {
     if (URI != null)
     {
         Identity resolvedIdentity = IdentityHolder.ResolveIdentity(URI);
         BCLDebug.Assert(
             (resolvedIdentity == null) || (resolvedIdentity == this),
             "Server ID mismatch with URI");
     }
 }
Exemplo n.º 7
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);
        }
        internal static Identity CasualResolveIdentity(string uri)
        {
            if (uri == null)
            {
                return(null);
            }
            Identity identity = IdentityHolder.CasualResolveReference(IdentityHolder.URITable[IdentityHolder.MakeURIKeyNoLower(uri)]);

            if (identity == null)
            {
                identity = IdentityHolder.CasualResolveReference(IdentityHolder.URITable[IdentityHolder.MakeURIKey(uri)]);
                if (identity == null || identity.IsInitializing)
                {
                    identity = RemotingConfigHandler.CreateWellKnownObject(uri);
                }
            }
            return(identity);
        }
            internal void AddWellKnownEntry(WellKnownServiceTypeEntry entry, bool fReplace)
            {
                if (this.CheckForRedirectedClientType(entry.TypeName, entry.AssemblyName))
                {
                    throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_CantUseRedirectedTypeForWellKnownService"), new object[] { entry.TypeName, entry.AssemblyName }));
                }
                string key = entry.ObjectUri.ToLower(CultureInfo.InvariantCulture);

                if (fReplace)
                {
                    this._wellKnownExportInfo[key] = entry;
                    IdentityHolder.RemoveIdentity(entry.ObjectUri);
                }
                else
                {
                    this._wellKnownExportInfo.Add(key, entry);
                }
            }
Exemplo n.º 10
0
        internal static void RemoveIdentity(string uri, bool bResetURI)
        {
            string           str       = IdentityHolder.MakeURIKey(uri);
            ReaderWriterLock tableLock = IdentityHolder.TableLock;
            bool             flag      = !tableLock.IsWriterLockHeld;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                if (flag)
                {
                    tableLock.AcquireWriterLock(int.MaxValue);
                }
                object        obj           = IdentityHolder.URITable[(object)str];
                WeakReference weakReference = obj as WeakReference;
                Identity      identity;
                if (weakReference != null)
                {
                    identity             = (Identity)weakReference.Target;
                    weakReference.Target = (object)null;
                }
                else
                {
                    identity = (Identity)obj;
                    if (identity != null)
                    {
                        ((ServerIdentity)identity).ResetHandle();
                    }
                }
                if (identity == null)
                {
                    return;
                }
                IdentityHolder.URITable.Remove((object)str);
                identity.ResetInIDTable(bResetURI);
            }
            finally
            {
                if (flag && tableLock.IsWriterLockHeld)
                {
                    tableLock.ReleaseWriterLock();
                }
            }
        }
Exemplo n.º 11
0
 internal void ResetInIDTable(bool bResetURI)
 {
     BCLDebug.Assert(IdentityHolder.IsWriterLockHeld(), "IDTable should be write-locked");
     while (true)
     {
         int currentFlags = _flags;
         int newFlags     = _flags & (~IDFLG_IN_IDTABLE);
         if (currentFlags == Interlocked.CompareExchange(ref _flags, newFlags, currentFlags))
         {
             break;
         }
     }
     // bResetURI is true for the external API call to Disconnect, it is
     // false otherwise. Thus when a user Disconnects an object
     // its URI will get reset but if lifetime service times it out
     // it will not clear out the URIs
     if (bResetURI)
     {
         ((ObjRef)_objRef).URI = null;
         _ObjURI = null;
     }
 }
        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();
                }
            }
        }
 internal static void RemoveIdentity(string uri)
 {
     IdentityHolder.RemoveIdentity(uri, true);
 }
        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);
        }
 internal ServerIdentity StartupWellKnownObject(string asmName, string svrTypeName, string URI, WellKnownObjectMode mode, bool fReplace)
 {
     lock (s_wkoStartLock)
     {
         MarshalByRefObject obj2     = null;
         ServerIdentity     identity = null;
         Type type = LoadType(svrTypeName, asmName);
         if (!type.IsMarshalByRef)
         {
             throw new RemotingException(Environment.GetResourceString("Remoting_WellKnown_MustBeMBR", new object[] { svrTypeName }));
         }
         identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
         if ((identity != null) && identity.IsRemoteDisconnected())
         {
             IdentityHolder.RemoveIdentity(URI);
             identity = null;
         }
         if (identity == null)
         {
             s_fullTrust.Assert();
             try
             {
                 obj2 = (MarshalByRefObject)Activator.CreateInstance(type, true);
                 if (RemotingServices.IsClientProxy(obj2))
                 {
                     RedirectionProxy proxy = new RedirectionProxy(obj2, type)
                     {
                         ObjectMode = mode
                     };
                     RemotingServices.MarshalInternal(proxy, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     identity.SetSingletonObjectMode();
                 }
                 else if (type.IsCOMObject && (mode == WellKnownObjectMode.Singleton))
                 {
                     ComRedirectionProxy proxy2 = new ComRedirectionProxy(obj2, type);
                     RemotingServices.MarshalInternal(proxy2, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     identity.SetSingletonObjectMode();
                 }
                 else
                 {
                     if (RemotingServices.GetObjectUri(obj2) != null)
                     {
                         throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_WellKnown_CtorCantMarshal"), new object[] { URI }));
                     }
                     RemotingServices.MarshalInternal(obj2, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     if (mode == WellKnownObjectMode.SingleCall)
                     {
                         identity.SetSingleCallObjectMode();
                     }
                     else
                     {
                         identity.SetSingletonObjectMode();
                     }
                 }
             }
             catch
             {
                 throw;
             }
             finally
             {
                 CodeAccessPermission.RevertAssert();
             }
         }
         return(identity);
     }
 }
Exemplo n.º 16
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);
        }