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);
        }
Exemple #2
0
        } // ObjRef

        public ObjRef(MarshalByRefObject o, Type requestedType)
        {
            bool     fServer;
            Identity id = MarshalByRefObject.GetIdentity(o, out fServer);

            Init(o, id, requestedType);
        }
 internal MethodCall(object handlerObject, BinaryMethodCallMessage smuggledMsg)
 {
     if (handlerObject != null)
     {
         this.uri = handlerObject as string;
         if (this.uri == null)
         {
             MarshalByRefObject obj2 = handlerObject as MarshalByRefObject;
             if (obj2 != null)
             {
                 bool flag;
                 this.srvID = MarshalByRefObject.GetIdentity(obj2, out flag) as ServerIdentity;
                 this.uri   = this.srvID.URI;
             }
         }
     }
     this.typeName        = smuggledMsg.TypeName;
     this.methodName      = smuggledMsg.MethodName;
     this.methodSignature = (Type[])smuggledMsg.MethodSignature;
     this.args            = smuggledMsg.Args;
     this.instArgs        = smuggledMsg.InstantiationArgs;
     this.callContext     = smuggledMsg.LogicalCallContext;
     this.ResolveMethod();
     if (smuggledMsg.HasProperties)
     {
         smuggledMsg.PopulateMessageProperties(this.Properties);
     }
 }
        internal static bool RemoveDynamicProperty(MarshalByRefObject obj, String name)
        {
            if (RemotingServices.IsObjectOutOfContext(obj))
            {
                // We have to add a proxy side property, get the identity
                RealProxy rp = RemotingServices.GetRealProxy(obj);
                return(rp.IdentityObject.RemoveProxySideDynamicProperty(name));
            }
            else
            {
                MarshalByRefObject realObj =
                    (MarshalByRefObject)
                    RemotingServices.AlwaysUnwrap((ContextBoundObject)obj);

                // This is a real object. See if we have an identity for it
                ServerIdentity srvID = (ServerIdentity)MarshalByRefObject.GetIdentity(realObj);
                if (srvID != null)
                {
                    return(srvID.RemoveServerSideDynamicProperty(name));
                }
                else
                {
                    // identity not found, we can't set a sink for this object.
                    throw new RemotingException(
                              Environment.GetResourceString("Remoting_NoIdentityEntry"));
                }
            }
        }
Exemple #5
0
        // Set the URI to use to marshal an object.
        public static void SetObjectUriForMarshal
            (MarshalByRefObject obj, String uri)
        {
            if (obj == null)
            {
                return;
            }
            Identity id = obj.GetIdentity();

            if (id != null)
            {
                // Update the object's current identity.
                if (id.otherAppDomain)
                {
                    throw new RemotingException(_("Remoting_NotLocal"));
                }
                if (id.uri != null)
                {
                    throw new RemotingException(_("Remoting_HasIdentity"));
                }
                id.uri = uri;
            }
            else
            {
                // Create a new identity for the object and set it.
                id                = new Identity();
                id.uri            = uri;
                id.context        = Thread.CurrentContext;
                id.otherAppDomain = false;
                obj.SetIdentity(id);
            }
        }
        protected static object FixupArg(object arg, ref ArrayList argsToSerialize)
        {
            int count;

            if (arg == null)
            {
                return(null);
            }
            MarshalByRefObject proxy = arg as MarshalByRefObject;

            if (proxy != null)
            {
                if (!RemotingServices.IsTransparentProxy(proxy) || (RemotingServices.GetRealProxy(proxy) is RemotingProxy))
                {
                    ObjRef ref2 = RemotingServices.MarshalInternal(proxy, null, null);
                    if (ref2.CanSmuggle())
                    {
                        if (!RemotingServices.IsTransparentProxy(proxy))
                        {
                            ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity(proxy);
                            identity.SetHandle();
                            ref2.SetServerIdentity(identity.GetHandle());
                            ref2.SetDomainID(AppDomain.CurrentDomain.GetId());
                        }
                        ObjRef objRef = ref2.CreateSmuggleableCopy();
                        objRef.SetMarshaledObject();
                        return(new SmuggledObjRef(objRef));
                    }
                }
                if (argsToSerialize == null)
                {
                    argsToSerialize = new ArrayList();
                }
                count = argsToSerialize.Count;
                argsToSerialize.Add(arg);
                return(new SerializedArg(count));
            }
            if (CanSmuggleObjectDirectly(arg))
            {
                return(arg);
            }
            Array array = arg as Array;

            if (array != null)
            {
                Type elementType = array.GetType().GetElementType();
                if (elementType.IsPrimitive || (elementType == typeof(string)))
                {
                    return(array.Clone());
                }
            }
            if (argsToSerialize == null)
            {
                argsToSerialize = new ArrayList();
            }
            count = argsToSerialize.Count;
            argsToSerialize.Add(arg);
            return(new SerializedArg(count));
        }
Exemple #7
0
 internal override void AssertValid()
 {
     base.AssertValid();
     if ((null != this.TPOrObject) && !RemotingServices.IsTransparentProxy(this.TPOrObject))
     {
         BCLDebug.Assert(MarshalByRefObject.GetIdentity((MarshalByRefObject)this.TPOrObject) == this, "Server ID mismatch with Object");
     }
 }
Exemple #8
0
        private static void VerifyIsOkToCallMethod(Object server, IMethodMessage msg)
        {
            bool bTypeChecked      = false;
            MarshalByRefObject mbr = server as MarshalByRefObject;

            if (mbr != null)
            {
                bool     fServer;
                Identity id = MarshalByRefObject.GetIdentity(mbr, out fServer);
                if (id != null)
                {
                    ServerIdentity srvId = id as ServerIdentity;
                    if ((srvId != null) && srvId.MarshaledAsSpecificType)
                    {
                        Type srvType = srvId.ServerType;
                        if (srvType != null)
                        {
                            MethodBase mb            = GetMethodBase(msg);
                            Type       declaringType = mb.DeclaringType;

                            // make sure that srvType is not more restrictive than method base
                            // (i.e. someone marshaled with a specific type or interface exposed)
                            if ((declaringType != srvType) &&
                                !declaringType.IsAssignableFrom(srvType))
                            {
                                throw new RemotingException(
                                          String.Format(
                                              Environment.GetResourceString("Remoting_InvalidCallingType"),
                                              mb.DeclaringType.FullName, srvType.FullName));
                            }
                            // Set flag so we don't repeat this work below.
                            bTypeChecked = true;
                        }
                    }
                }

                // We must always verify that the type corresponding to
                // the method being invoked is compatible with the real server
                // type.
                if (!bTypeChecked)
                {
                    MethodBase mb            = GetMethodBase(msg);
                    Type       reflectedType = mb.ReflectedType;
                    if (!reflectedType.IsInterface)
                    {
                        if (!reflectedType.IsInstanceOfType(mbr))
                        {
                            throw new RemotingException(
                                      String.Format(
                                          Environment.GetResourceString("Remoting_InvalidCallingType"),
                                          reflectedType.FullName,
                                          mbr.GetType().FullName));
                        }
                    }
                }
            }
        } // VerifyIsOkToCallMethod
Exemple #9
0
        public static String[] GetUrlsForObject(MarshalByRefObject obj)
        {
            if (null == obj)
            {
                return(null);
            }

            RegisteredChannelList regChnlList = s_registeredChannels;
            int count = regChnlList.Count;

            Hashtable table = new Hashtable();
            bool      fServer;
            Identity  id = MarshalByRefObject.GetIdentity(obj, out fServer);

            if (null != id)
            {
                String uri = id.ObjURI;

                if (null != uri)
                {
                    for (int i = 0; i < count; i++)
                    {
                        if (regChnlList.IsReceiver(i))
                        {
                            try
                            {
                                String[] urls = ((IChannelReceiver)regChnlList.GetChannel(i)).GetUrlsForUri(uri);
                                // Add the strings to the table
                                for (int j = 0; j < urls.Length; j++)
                                {
                                    table.Add(urls[j], urls[j]);
                                }
                            }
                            catch (NotSupportedException)
                            {
                                // We do not count the channels that do not
                                // support this method
                            }
                        }
                    }
                }
            }

            // copy url's into string array
            ICollection keys = table.Keys;

            String[] urlList = new String[keys.Count];
            int      co      = 0;

            foreach (String key in keys)
            {
                urlList[co++] = key;
            }
            return(urlList);
        }
Exemple #10
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);
        }
Exemple #11
0
        internal ILease GetLease(MarshalByRefObject obj)
        {
            bool     fServer  = true;
            Identity identity = MarshalByRefObject.GetIdentity(obj, out fServer);

            if (identity == null)
            {
                return(null);
            }
            return(identity.Lease);
        }
Exemple #12
0
        protected static object FixupArg(object arg, ref ArrayList argsToSerialize)
        {
            if (arg == null)
            {
                return((object)null);
            }
            if (arg is MarshalByRefObject marshalByRefObject)
            {
                if (!RemotingServices.IsTransparentProxy((object)marshalByRefObject) || RemotingServices.GetRealProxy((object)marshalByRefObject) is RemotingProxy)
                {
                    ObjRef objRef = RemotingServices.MarshalInternal(marshalByRefObject, (string)null, (Type)null);
                    if (objRef.CanSmuggle())
                    {
                        if (!RemotingServices.IsTransparentProxy((object)marshalByRefObject))
                        {
                            ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity(marshalByRefObject);
                            identity.SetHandle();
                            objRef.SetServerIdentity(identity.GetHandle());
                            objRef.SetDomainID(AppDomain.CurrentDomain.GetId());
                        }
                        ObjRef smuggleableCopy = objRef.CreateSmuggleableCopy();
                        smuggleableCopy.SetMarshaledObject();
                        return((object)new SmuggledObjRef(smuggleableCopy));
                    }
                }
                if (argsToSerialize == null)
                {
                    argsToSerialize = new ArrayList();
                }
                int count = argsToSerialize.Count;
                argsToSerialize.Add(arg);
                return((object)new MessageSmuggler.SerializedArg(count));
            }
            if (MessageSmuggler.CanSmuggleObjectDirectly(arg))
            {
                return(arg);
            }
            if (arg is Array array)
            {
                Type elementType = array.GetType().GetElementType();
                if (elementType.IsPrimitive || elementType == typeof(string))
                {
                    return(array.Clone());
                }
            }
            if (argsToSerialize == null)
            {
                argsToSerialize = new ArrayList();
            }
            int count1 = argsToSerialize.Count;

            argsToSerialize.Add(arg);
            return((object)new MessageSmuggler.SerializedArg(count1));
        }
Exemple #13
0
 // Get the URI for a specific object.
 public static String GetObjectUri(MarshalByRefObject obj)
 {
     if (obj != null)
     {
         Identity identity = obj.GetIdentity();
         if (identity != null)
         {
             return(identity.uri);
         }
     }
     return(null);
 }
        private static void VerifyIsOkToCallMethod(object server, IMethodMessage msg)
        {
            bool flag = false;
            MarshalByRefObject marshalByRefObject = server as MarshalByRefObject;

            if (marshalByRefObject == null)
            {
                return;
            }
            bool     fServer;
            Identity identity = MarshalByRefObject.GetIdentity(marshalByRefObject, out fServer);

            if (identity != null)
            {
                ServerIdentity serverIdentity = identity as ServerIdentity;
                if (serverIdentity != null && serverIdentity.MarshaledAsSpecificType)
                {
                    Type serverType = serverIdentity.ServerType;
                    if (serverType != (Type)null)
                    {
                        MethodBase  methodBase    = StackBuilderSink.GetMethodBase(msg);
                        RuntimeType reflectedType = (RuntimeType)methodBase.DeclaringType;
                        if ((Type)reflectedType != serverType && !reflectedType.IsAssignableFrom(serverType))
                        {
                            throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidCallingType"), (object)methodBase.DeclaringType.FullName, (object)serverType.FullName));
                        }
                        if (reflectedType.IsInterface)
                        {
                            StackBuilderSink.VerifyNotIRemoteDispatch(reflectedType);
                        }
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                return;
            }
            RuntimeType reflectedType1 = (RuntimeType)StackBuilderSink.GetMethodBase(msg).ReflectedType;

            if (!reflectedType1.IsInterface)
            {
                if (!reflectedType1.IsInstanceOfType((object)marshalByRefObject))
                {
                    throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidCallingType"), (object)reflectedType1.FullName, (object)marshalByRefObject.GetType().FullName));
                }
            }
            else
            {
                StackBuilderSink.VerifyNotIRemoteDispatch(reflectedType1);
            }
        }
Exemple #15
0
        internal static bool RemoveDynamicProperty(MarshalByRefObject obj, string name)
        {
            if (RemotingServices.IsObjectOutOfContext((object)obj))
            {
                return(RemotingServices.GetRealProxy((object)obj).IdentityObject.RemoveProxySideDynamicProperty(name));
            }
            ServerIdentity serverIdentity = (ServerIdentity)MarshalByRefObject.GetIdentity((MarshalByRefObject)RemotingServices.AlwaysUnwrap((ContextBoundObject)obj));

            if (serverIdentity != null)
            {
                return(serverIdentity.RemoveServerSideDynamicProperty(name));
            }
            throw new RemotingException(Environment.GetResourceString("Remoting_NoIdentityEntry"));
        }
        internal static bool AddDynamicProperty(MarshalByRefObject obj, IDynamicProperty prop)
        {
            if (RemotingServices.IsObjectOutOfContext(obj))
            {
                return(RemotingServices.GetRealProxy(obj).IdentityObject.AddProxySideDynamicProperty(prop));
            }
            MarshalByRefObject obj2     = (MarshalByRefObject)RemotingServices.AlwaysUnwrap((ContextBoundObject)obj);
            ServerIdentity     identity = (ServerIdentity)MarshalByRefObject.GetIdentity(obj2);

            if (identity == null)
            {
                throw new RemotingException(Environment.GetResourceString("Remoting_NoIdentityEntry"));
            }
            return(identity.AddServerSideDynamicProperty(prop));
        }
Exemple #17
0
        internal ILease GetLease(MarshalByRefObject obj)
        {
            BCLDebug.Trace("REMOTE", "LeaseManager GetLease ", obj);
            bool     fServer = true;
            Identity idObj   = MarshalByRefObject.GetIdentity(obj, out fServer);

            if (idObj == null)
            {
                return(null);
            }
            else
            {
                return(idObj.Lease);
            }
        }
        private static void VerifyIsOkToCallMethod(object server, IMethodMessage msg)
        {
            bool flag = false;
            MarshalByRefObject obj2 = server as MarshalByRefObject;

            if (obj2 != null)
            {
                bool     flag2;
                Identity identity = MarshalByRefObject.GetIdentity(obj2, out flag2);
                if (identity != null)
                {
                    ServerIdentity identity2 = identity as ServerIdentity;
                    if ((identity2 != null) && identity2.MarshaledAsSpecificType)
                    {
                        Type serverType = identity2.ServerType;
                        if (serverType != null)
                        {
                            MethodBase  methodBase    = GetMethodBase(msg);
                            RuntimeType declaringType = (RuntimeType)methodBase.DeclaringType;
                            if ((declaringType != serverType) && !declaringType.IsAssignableFrom(serverType))
                            {
                                throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidCallingType"), new object[] { methodBase.DeclaringType.FullName, serverType.FullName }));
                            }
                            if (declaringType.IsInterface)
                            {
                                VerifyNotIRemoteDispatch(declaringType);
                            }
                            flag = true;
                        }
                    }
                }
                if (!flag)
                {
                    RuntimeType reflectedType = (RuntimeType)GetMethodBase(msg).ReflectedType;
                    if (!reflectedType.IsInterface)
                    {
                        if (!reflectedType.IsInstanceOfType(obj2))
                        {
                            throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidCallingType"), new object[] { reflectedType.FullName, obj2.GetType().FullName }));
                        }
                    }
                    else
                    {
                        VerifyNotIRemoteDispatch(reflectedType);
                    }
                }
            }
        }
        public static string[] GetUrlsForObject(MarshalByRefObject obj)
        {
            bool flag;

            if (obj == null)
            {
                return(null);
            }
            RegisteredChannelList list = s_registeredChannels;
            int       count            = list.Count;
            Hashtable hashtable        = new Hashtable();
            Identity  identity         = MarshalByRefObject.GetIdentity(obj, out flag);

            if (identity != null)
            {
                string objURI = identity.ObjURI;
                if (objURI != null)
                {
                    for (int i = 0; i < count; i++)
                    {
                        if (list.IsReceiver(i))
                        {
                            try
                            {
                                string[] urlsForUri = ((IChannelReceiver)list.GetChannel(i)).GetUrlsForUri(objURI);
                                for (int j = 0; j < urlsForUri.Length; j++)
                                {
                                    hashtable.Add(urlsForUri[j], urlsForUri[j]);
                                }
                            }
                            catch (NotSupportedException)
                            {
                            }
                        }
                    }
                }
            }
            ICollection keys = hashtable.Keys;

            string[] strArray2 = new string[keys.Count];
            int      num4      = 0;

            foreach (string str2 in keys)
            {
                strArray2[num4++] = str2;
            }
            return(strArray2);
        }
Exemple #20
0
        public static string[] GetUrlsForObject(MarshalByRefObject obj)
        {
            if (obj == null)
            {
                return(null);
            }
            RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
            int       count     = registeredChannelList.Count;
            Hashtable hashtable = new Hashtable();
            bool      flag;
            Identity  identity = MarshalByRefObject.GetIdentity(obj, out flag);

            if (identity != null)
            {
                string objURI = identity.ObjURI;
                if (objURI != null)
                {
                    for (int i = 0; i < count; i++)
                    {
                        if (registeredChannelList.IsReceiver(i))
                        {
                            try
                            {
                                string[] urlsForUri = ((IChannelReceiver)registeredChannelList.GetChannel(i)).GetUrlsForUri(objURI);
                                for (int j = 0; j < urlsForUri.Length; j++)
                                {
                                    hashtable.Add(urlsForUri[j], urlsForUri[j]);
                                }
                            }
                            catch (NotSupportedException)
                            {
                            }
                        }
                    }
                }
            }
            ICollection keys = hashtable.Keys;

            string[] array = new string[keys.Count];
            int      num   = 0;

            foreach (object obj2 in keys)
            {
                string text = (string)obj2;
                array[num++] = text;
            }
            return(array);
        }
Exemple #21
0
        public static string[] GetUrlsForObject(MarshalByRefObject obj)
        {
            if (obj == null)
            {
                return((string[])null);
            }
            RegisteredChannelList registeredChannelList = ChannelServices.s_registeredChannels;
            int       count     = registeredChannelList.Count;
            Hashtable hashtable = new Hashtable();
            bool      fServer;
            Identity  identity = MarshalByRefObject.GetIdentity(obj, out fServer);

            if (identity != null)
            {
                string objUri = identity.ObjURI;
                if (objUri != null)
                {
                    for (int index1 = 0; index1 < count; ++index1)
                    {
                        if (registeredChannelList.IsReceiver(index1))
                        {
                            try
                            {
                                string[] urlsForUri = ((IChannelReceiver)registeredChannelList.GetChannel(index1)).GetUrlsForUri(objUri);
                                for (int index2 = 0; index2 < urlsForUri.Length; ++index2)
                                {
                                    hashtable.Add((object)urlsForUri[index2], (object)urlsForUri[index2]);
                                }
                            }
                            catch (NotSupportedException ex)
                            {
                            }
                        }
                    }
                }
            }
            ICollection keys = hashtable.Keys;

            string[] strArray = new string[keys.Count];
            int      num      = 0;

            foreach (string str in (IEnumerable)keys)
            {
                strArray[num++] = str;
            }
            return(strArray);
        }
Exemple #22
0
        public ObjRef(MarshalByRefObject o, Type requestedType)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o");
            }
            RuntimeType requestedType1 = requestedType as RuntimeType;

            if (requestedType != (Type)null && requestedType1 == (RuntimeType)null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
            }
            bool     fServer;
            Identity identity = MarshalByRefObject.GetIdentity(o, out fServer);

            this.Init((object)o, identity, requestedType1);
        }
        public ObjRef(MarshalByRefObject o, Type requestedType)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o");
            }
            RuntimeType runtimeType = requestedType as RuntimeType;

            if (requestedType != null && runtimeType == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
            }
            bool     flag;
            Identity identity = MarshalByRefObject.GetIdentity(o, out flag);

            this.Init(o, identity, runtimeType);
        }
        [System.Security.SecurityCritical]  // auto-generated
        public ObjRef(MarshalByRefObject o, Type requestedType)
        {
            bool fServer;

            if (o == null)
            {
                throw new ArgumentNullException("o");
            }
            RuntimeType rt = requestedType as RuntimeType;

            if (requestedType != null && rt == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
            }

            Identity id = MarshalByRefObject.GetIdentity(o, out fServer);

            Init(o, id, rt);
        }
Exemple #25
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static object GetObjectData(object serObj, out string typeName, out string assemName, out string[] fieldNames, out object[] fieldValues)
        {
            Type   objectType = null;
            object retObj     = null;

            if (RemotingServices.IsTransparentProxy(serObj))
            {
                objectType = typeof(MarshalByRefObject);
            }
            else
            {
                objectType = serObj.GetType();
            }

            SerializationInfo si = new SerializationInfo(objectType, s_converter);

            if (serObj is ObjRef)
            {
                s_ObjRefRemotingSurrogate.GetObjectData(serObj, si, s_cloneContext);
            }
            else if (RemotingServices.IsTransparentProxy(serObj) || serObj is MarshalByRefObject)
            {
#if !MONO
                // We can only try to smuggle objref's for actual CLR objects
                //   or for RemotingProxy's.
                if (!RemotingServices.IsTransparentProxy(serObj) ||
                    RemotingServices.GetRealProxy(serObj) is RemotingProxy)
                {
                    ObjRef objRef = RemotingServices.MarshalInternal((MarshalByRefObject)serObj, null, null);
                    if (objRef.CanSmuggle())
                    {
                        if (RemotingServices.IsTransparentProxy(serObj))
                        {
                            RealProxy rp = RemotingServices.GetRealProxy(serObj);
                            objRef.SetServerIdentity(rp._srvIdentity);
                            objRef.SetDomainID(rp._domainID);
                        }
                        else
                        {
                            ServerIdentity srvId = (ServerIdentity)MarshalByRefObject.GetIdentity((MarshalByRefObject)serObj);
                            srvId.SetHandle();
                            objRef.SetServerIdentity(srvId.GetHandle());
                            objRef.SetDomainID(AppDomain.CurrentDomain.GetId());
                        }
                        objRef.SetMarshaledObject();
                        retObj = objRef;
                    }
                }
#endif
                if (retObj == null)
                {
                    // Deal with the non-smugglable remoting objects
                    s_RemotingSurrogate.GetObjectData(serObj, si, s_cloneContext);
                }
            }
            else if (serObj is ISerializable)
            {
                ((ISerializable)serObj).GetObjectData(si, s_cloneContext);
            }
            else
            {
                // Getting here means a bug in cloner
                throw new ArgumentException(Environment.GetResourceString("Arg_SerializationException"));
            }

            if (retObj == null)
            {
                typeName    = si.FullTypeName;
                assemName   = si.AssemblyName;
                fieldNames  = si.MemberNames;
                fieldValues = si.MemberValues;
            }
            else
            {
                typeName    = null;
                assemName   = null;
                fieldNames  = null;
                fieldValues = null;
            }

            return(retObj);
        }
Exemple #26
0
        public ObjRef(MarshalByRefObject o, Type requestedType)
        {
            Identity identity = MarshalByRefObject.GetIdentity(o, out bool _);

            this.Init((object)o, identity, requestedType);
        }
	// Get the URI for a specific object.
	public static String GetObjectUri(MarshalByRefObject obj)
			{
				if(obj != null)
				{
					Identity identity = obj.GetIdentity();
					if(identity != null)
					{
						return identity.uri;
					}
				}
				return null;
			}
	// Set the URI to use to marshal an object.
	public static void SetObjectUriForMarshal
				(MarshalByRefObject obj, String uri)
			{
				if(obj == null)
				{
					return;
				}
				Identity id = obj.GetIdentity();
				if(id != null)
				{
					// Update the object's current identity.
					if(id.otherAppDomain)
					{
						throw new RemotingException(_("Remoting_NotLocal"));
					}
					if(id.uri != null)
					{
						throw new RemotingException(_("Remoting_HasIdentity"));
					}
					id.uri = uri;
				}
				else
				{
					// Create a new identity for the object and set it.
					id = new Identity();
					id.uri = uri;
					id.context = Thread.CurrentContext;
					id.otherAppDomain = false;
					obj.SetIdentity(id);
				}
			}
        // Initiates the creation of a lease

        // Creates a sink for invoking a renew on call when an object is created.

        public IMessageSink GetObjectSink(MarshalByRefObject obj,
                                          IMessageSink nextSink)

        {
            bool           fServer;
            ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity(obj, out fServer);

            BCLDebug.Assert(identity != null, "[LifetimeServices.GetObjectSink] identity != null");

            // NOTE: Single Call objects do not have a lease associated with it because they last
            // only for the duration of the call.
            // Singleton objects on the other hand do have leases associated with them and they can
            // be garbage collected.
            if (identity.IsSingleCall())
            {
                BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, no lease SingleCall", obj, ", NextSink " + nextSink);
                return(nextSink);
            }



            // Create lease. InitializeLifetimeService is a virtual method which can be overridded so that a lease with
            // object specific properties can be created.
            Object leaseObj = obj.InitializeLifetimeService();


            BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, return from InitializeLifetimeService obj ", obj, ", lease ", leaseObj);


            // InitializeLifetimeService can return a lease in one of conditions:
            // 1) the lease has a null state which specifies that no lease is to be created.
            // 2) the lease has an initial state which specifies that InitializeLifeTimeService has created a new lease.
            // 3) the lease has another state which indicates that the lease has already been created and registered.


            if (leaseObj == null)
            {
                BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, no lease ", obj, ", NextSink " + nextSink);
                return(nextSink);
            }

            if (!(leaseObj is System.Runtime.Remoting.Lifetime.ILease))
            {
                throw new RemotingException(String.Format(Environment.GetResourceString("Remoting_Lifetime_ILeaseReturn"), leaseObj));
            }

            ILease ilease = (ILease)leaseObj;

            if (ilease.InitialLeaseTime.CompareTo(TimeSpan.Zero) <= 0)
            {
                // No lease
                {
                    BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, no lease because InitialLeaseTime is Zero ", obj);
                    if (ilease is System.Runtime.Remoting.Lifetime.Lease)
                    {
                        ((Lease)ilease).Remove();
                    }
                    return(nextSink);
                }
            }


            Lease lease = null;

            lock (identity)
            {
                if (identity.Lease != null)
                {
                    // Lease already exists for object, object is being marsalled again
                    BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, Lease already exists for object ", obj);
                    lease = (Lease)identity.Lease;
                    lease.Renew(lease.InitialLeaseTime);         // Reset initial lease time
                }
                else
                {
                    // New lease
                    if (!(ilease is System.Runtime.Remoting.Lifetime.Lease))
                    {
                        // InitializeLifetimeService created its own ILease object
                        // Need to create a System.Runtime.Remoting.Lease object
                        BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, New Lease, lease not of type Lease  ", obj);
                        lease = (Lease)LifetimeServices.GetLeaseInitial(obj);
                        if (lease.CurrentState == LeaseState.Initial)
                        {
                            lease.InitialLeaseTime   = ilease.InitialLeaseTime;
                            lease.RenewOnCallTime    = ilease.RenewOnCallTime;
                            lease.SponsorshipTimeout = ilease.SponsorshipTimeout;
                        }
                    }
                    else
                    {
                        // An object of Type Lease was created
                        BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, New Lease, lease is type Lease  ", obj);
                        lease = (Lease)ilease;
                    }

                    // Put lease in active state
                    // Creation phase of lease is over, properties can no longer be set on lease.
                    identity.Lease = lease;         // Place lease into identity for object
                    // If the object has been marshaled activate
                    // the lease
                    if (identity.ObjectRef != null)
                    {
                        lease.ActivateLease();
                    }
                }
            }


            if (lease.RenewOnCallTime > TimeSpan.Zero)
            {
                // RenewOnCall create sink
                BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, lease created ", obj);
                return(new LeaseSink(lease, nextSink));
            }
            else
            {
                // No RenewOnCall so no sink created
                BCLDebug.Trace("REMOTE", "LeaseLifeTimeServiceProperty.GetObjectSink, No RenewOnCall so no sink created ", obj);
                return(nextSink);
            }
        }
Exemple #30
0
        internal static object GetObjectData(object serObj, out string typeName, out string assemName, out string[] fieldNames, out object[] fieldValues)
        {
            object            obj  = (object)null;
            SerializationInfo info = new SerializationInfo(!RemotingServices.IsTransparentProxy(serObj) ? serObj.GetType() : typeof(MarshalByRefObject), ObjectCloneHelper.s_converter);

            if (serObj is ObjRef)
            {
                ObjectCloneHelper.s_ObjRefRemotingSurrogate.GetObjectData(serObj, info, ObjectCloneHelper.s_cloneContext);
            }
            else if (RemotingServices.IsTransparentProxy(serObj) || serObj is MarshalByRefObject)
            {
                if (!RemotingServices.IsTransparentProxy(serObj) || RemotingServices.GetRealProxy(serObj) is RemotingProxy)
                {
                    ObjRef objRef = RemotingServices.MarshalInternal((MarshalByRefObject)serObj, (string)null, (Type)null);
                    if (objRef.CanSmuggle())
                    {
                        if (RemotingServices.IsTransparentProxy(serObj))
                        {
                            RealProxy realProxy = RemotingServices.GetRealProxy(serObj);
                            objRef.SetServerIdentity(realProxy._srvIdentity);
                            objRef.SetDomainID(realProxy._domainID);
                        }
                        else
                        {
                            ServerIdentity serverIdentity = (ServerIdentity)MarshalByRefObject.GetIdentity((MarshalByRefObject)serObj);
                            serverIdentity.SetHandle();
                            objRef.SetServerIdentity(serverIdentity.GetHandle());
                            objRef.SetDomainID(AppDomain.CurrentDomain.GetId());
                        }
                        objRef.SetMarshaledObject();
                        obj = (object)objRef;
                    }
                }
                if (obj == null)
                {
                    ObjectCloneHelper.s_RemotingSurrogate.GetObjectData(serObj, info, ObjectCloneHelper.s_cloneContext);
                }
            }
            else
            {
                if (!(serObj is ISerializable))
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_SerializationException"));
                }
                ((ISerializable)serObj).GetObjectData(info, ObjectCloneHelper.s_cloneContext);
            }
            if (obj == null)
            {
                typeName    = info.FullTypeName;
                assemName   = info.AssemblyName;
                fieldNames  = info.MemberNames;
                fieldValues = info.MemberValues;
            }
            else
            {
                typeName    = (string)null;
                assemName   = (string)null;
                fieldNames  = (string[])null;
                fieldValues = (object[])null;
            }
            return(obj);
        }
Exemple #31
0
        internal static object GetObjectData(object serObj, out string typeName, out string assemName, out string[] fieldNames, out object[] fieldValues)
        {
            Type   type = null;
            object obj2 = null;

            if (RemotingServices.IsTransparentProxy(serObj))
            {
                type = typeof(MarshalByRefObject);
            }
            else
            {
                type = serObj.GetType();
            }
            SerializationInfo info = new SerializationInfo(type, s_converter);

            if (serObj is ObjRef)
            {
                s_ObjRefRemotingSurrogate.GetObjectData(serObj, info, s_cloneContext);
            }
            else if (RemotingServices.IsTransparentProxy(serObj) || (serObj is MarshalByRefObject))
            {
                if (!RemotingServices.IsTransparentProxy(serObj) || (RemotingServices.GetRealProxy(serObj) is RemotingProxy))
                {
                    ObjRef ref2 = RemotingServices.MarshalInternal((MarshalByRefObject)serObj, null, null);
                    if (ref2.CanSmuggle())
                    {
                        if (RemotingServices.IsTransparentProxy(serObj))
                        {
                            RealProxy realProxy = RemotingServices.GetRealProxy(serObj);
                            ref2.SetServerIdentity(realProxy._srvIdentity);
                            ref2.SetDomainID(realProxy._domainID);
                        }
                        else
                        {
                            ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity((MarshalByRefObject)serObj);
                            identity.SetHandle();
                            ref2.SetServerIdentity(identity.GetHandle());
                            ref2.SetDomainID(AppDomain.CurrentDomain.GetId());
                        }
                        ref2.SetMarshaledObject();
                        obj2 = ref2;
                    }
                }
                if (obj2 == null)
                {
                    s_RemotingSurrogate.GetObjectData(serObj, info, s_cloneContext);
                }
            }
            else
            {
                if (!(serObj is ISerializable))
                {
                    throw new ArgumentException(Environment.GetResourceString("Arg_SerializationException"));
                }
                ((ISerializable)serObj).GetObjectData(info, s_cloneContext);
            }
            if (obj2 == null)
            {
                typeName    = info.FullTypeName;
                assemName   = info.AssemblyName;
                fieldNames  = info.MemberNames;
                fieldValues = info.MemberValues;
                return(obj2);
            }
            typeName    = null;
            assemName   = null;
            fieldNames  = null;
            fieldValues = null;
            return(obj2);
        }
        } // 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);
        }