当前位置: 首页>>代码示例>>C#>>正文


C# MarshalByRefObject.CreateObjRef方法代码示例

本文整理汇总了C#中System.MarshalByRefObject.CreateObjRef方法的典型用法代码示例。如果您正苦于以下问题:C# MarshalByRefObject.CreateObjRef方法的具体用法?C# MarshalByRefObject.CreateObjRef怎么用?C# MarshalByRefObject.CreateObjRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.MarshalByRefObject的用法示例。


在下文中一共展示了MarshalByRefObject.CreateObjRef方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MarshalInternal

 internal static ObjRef MarshalInternal(MarshalByRefObject Obj, string ObjURI, Type RequestedType, bool updateChannelData)
 {
     if (Obj == null)
     {
         return null;
     }
     ObjRef objRefGiven = null;
     Identity orCreateIdentity = null;
     orCreateIdentity = GetOrCreateIdentity(Obj, ObjURI);
     if (RequestedType != null)
     {
         ServerIdentity identity2 = orCreateIdentity as ServerIdentity;
         if (identity2 != null)
         {
             identity2.ServerType = RequestedType;
             identity2.MarshaledAsSpecificType = true;
         }
     }
     objRefGiven = orCreateIdentity.ObjectRef;
     if (objRefGiven == null)
     {
         if (IsTransparentProxy(Obj))
         {
             objRefGiven = GetRealProxy(Obj).CreateObjRef(RequestedType);
         }
         else
         {
             objRefGiven = Obj.CreateObjRef(RequestedType);
         }
         if ((orCreateIdentity == null) || (objRefGiven == null))
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_InvalidMarshalByRefObject"), "Obj");
         }
         objRefGiven = orCreateIdentity.RaceSetObjRef(objRefGiven);
     }
     ServerIdentity identity3 = orCreateIdentity as ServerIdentity;
     if (identity3 != null)
     {
         MarshalByRefObject obj2 = null;
         identity3.GetServerObjectChain(out obj2);
         Lease lease = orCreateIdentity.Lease;
         if (lease != null)
         {
             lock (lease)
             {
                 if (lease.CurrentState == LeaseState.Expired)
                 {
                     lease.ActivateLease();
                 }
                 else
                 {
                     lease.RenewInternal(orCreateIdentity.Lease.InitialLeaseTime);
                 }
             }
         }
         if (updateChannelData && (objRefGiven.ChannelInfo != null))
         {
             object[] currentChannelData = ChannelServices.CurrentChannelData;
             if (!(Obj is AppDomain))
             {
                 objRefGiven.ChannelInfo.ChannelData = currentChannelData;
             }
             else
             {
                 int length = currentChannelData.Length;
                 object[] destinationArray = new object[length];
                 Array.Copy(currentChannelData, destinationArray, length);
                 for (int i = 0; i < length; i++)
                 {
                     if (!(destinationArray[i] is CrossAppDomainData))
                     {
                         destinationArray[i] = null;
                     }
                 }
                 objRefGiven.ChannelInfo.ChannelData = destinationArray;
             }
         }
     }
     TrackingServices.MarshaledObject(Obj, objRefGiven);
     return objRefGiven;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:81,代码来源:RemotingServices.cs

示例2: MarshalInternal

        [System.Security.SecurityCritical]  // auto-generated 
        internal static ObjRef MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType, bool updateChannelData) 
        {
            BCLDebug.Trace("REMOTE", "Entered Marshal for URI" +  ObjURI + "\n"); 

            if (null == Obj)
                return null;
 
            ObjRef objectRef = null;
            Identity idObj = null; 
 
            idObj = GetOrCreateIdentity(Obj, ObjURI);
            if (RequestedType != null) 
            {
                ServerIdentity srvIdObj = idObj as ServerIdentity;
                if (srvIdObj != null)
                { 
                    // If more than one thread, marshals with different types the
                    // results would be non-deterministic, so we just let the last 
                    // call win (also allows type to be marshalled a second time 
                    // to change the exposed type).
                    srvIdObj.ServerType = RequestedType; 
                    srvIdObj.MarshaledAsSpecificType = true;
                }
            }
 
            // If there is no objref associated with the identity then go ahead
            // and create one and stick it back into the identity object 
 
#if _DEBUG
            idObj.AssertValid(); 
#endif

            Contract.Assert(null != idObj.ObjURI,"null != idObj.ObjURI");
 
            Message.DebugOut("RemotingServices::Marshal: trying to create objref\n");
 
            // We should definitely have an identity object at this point of time 
            Contract.Assert(null != idObj,"null != idObj");
 
            // Extract the objref from the identity
            objectRef = idObj.ObjectRef;
            if (null == objectRef)
            { 
                Message.DebugOut("RemotingServices::Marshal: really trying to create objref\n");
 
                if (IsTransparentProxy(Obj)) 
                {
                    RealProxy realProxy = GetRealProxy(Obj); 
                    Contract.Assert(null != realProxy,"null != realProxy");
                    objectRef = realProxy.CreateObjRef(RequestedType);
                }
                else 
                {
                    // Create a new object ref which contains the default information 
                    objectRef = Obj.CreateObjRef(RequestedType); 
                }
 
                Message.DebugOut("RemotingServices::Marshal: created objref\n");
                if (idObj == null || objectRef == null)
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidMarshalByRefObject"), "Obj");
 
                // The ObjectRef property setter will take care of ----s
                objectRef = idObj.RaceSetObjRef(objectRef); 
            } 

 
            // Retime lease on every marshal on the server side
            // and extend lease on every marshal on the client side <EMAIL>- GopalK</EMAIL>
            ServerIdentity srvId = idObj as ServerIdentity;
            if (srvId != null) 
            {
                // Ensure that the lease is started soon as the object is 
                // marshaled. 
                MarshalByRefObject obj = null;
                // This call forces creation of the lifetime lease sink. 
                srvId.GetServerObjectChain(out obj);

                // Server side ... object being marshaled => give it another
                // full lease 
                Lease lease = idObj.Lease;
                if (lease != null) 
                { 
                    // We always make Identity reference our own Lease though
                    // the actual object implements its own ILease object. 
                    // This seems completely broken. Further, ILease interface
                    // should have the activate method.  <EMAIL>- GopalK</EMAIL>

                    // This lock ensures coordination with the lifetime service 
                    // which might have decided to Disconnect the object about
                    // the same time as it is being marshaled 
                    lock (lease) 
                    {
                        if (lease.CurrentState == LeaseState.Expired) 
                        {
                            // Lease.Renew is a no-op if LeaseState==Expired
                            // So we do a full ActivateLease
                            lease.ActivateLease(); 
                        }
                        else 
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:RemotingServices.cs

示例3: MarshalInternal

        // Internal flavor without security!
        internal static ObjRef MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType)
        {        
            BCLDebug.Trace("REMOTE", "Entered Marshal for URI" +  ObjURI + "\n");

            if (null == Obj)
                return null;

            ObjRef objectRef = null;
            Identity idObj = null;

            idObj = GetOrCreateIdentity(Obj, ObjURI);
            if (RequestedType != null)
            {
                ServerIdentity srvIdObj = idObj as ServerIdentity;
                if (srvIdObj != null)
                {
                    // If more than one thread, marshals with different types the 
                    // results would be non-deterministic, so we just let the last
                    // call win (also allows type to be marshalled a second time
                    // to change the exposed type).
                    srvIdObj.ServerType = RequestedType;
                    srvIdObj.MarshaledAsSpecificType = true;                    
                }
            }

            // If there is no objref associated with the identity then go ahead
            // and create one and stick it back into the identity object

#if _DEBUG
            idObj.AssertValid();
#endif

            BCLDebug.Assert(null != idObj.ObjURI,"null != idObj.ObjURI");

            Message.DebugOut("RemotingServices::Marshal: trying to create objref\n");

            // We should definitely have an identity object at this point of time
            BCLDebug.Assert(null != idObj,"null != idObj");

            // Extract the objref from the identity
            objectRef = idObj.ObjectRef;
            if (null == objectRef)
            {
                Message.DebugOut("RemotingServices::Marshal: really trying to create objref\n");

                if (IsTransparentProxy(Obj))
                {
                    RealProxy realProxy = GetRealProxy(Obj);
                    BCLDebug.Assert(null != realProxy,"null != realProxy");
                    objectRef = realProxy.CreateObjRef(RequestedType);    
                }
                else
                {
                    // Create a new object ref which contains the default information
                    objectRef = Obj.CreateObjRef(RequestedType);
                }

                Message.DebugOut("RemotingServices::Marshal: created objref\n");
                BCLDebug.Assert(null != idObj,"null != idObj");
                BCLDebug.Assert(null != objectRef,"null != objectRef");
                // The ObjectRef property setter will take care of races
                objectRef = idObj.RaceSetObjRef(objectRef);                
            }


            // Retime lease on every marshal on the server side 
            // and extend lease on every marshal on the client side                        
            ServerIdentity srvId = idObj as ServerIdentity;
            if (srvId != null)
            {
                // Ensure that the lease is started soon as the object is 
                // marshaled.
                MarshalByRefObject obj = null;
                // This call forces creation of the lifetime lease sink.
                srvId.GetServerObjectChain(out obj);    

                // Server side ... object being marshaled => give it another
                // full lease
                Lease lease = idObj.Lease;
                if (lease != null)
                {
                    // We always make Identity reference our own Lease though 
                    // the actual object implements its own ILease object. 
                    // This seems completely broken. Further, ILease interface 
                    // should have the activate method.                         

                    // This lock ensures coordination with the lifetime service
                    // which might have decided to Disconnect the object about
                    // the same time as it is being marshaled
                    lock (lease)
                    {
                        if (lease.CurrentState == LeaseState.Expired)
                        {
                            // Lease.Renew is a no-op if LeaseState==Expired
                            // So we do a full ActivateLease
                            lease.ActivateLease();
                        }
                        else
                        {
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:remotingservices.cs


注:本文中的System.MarshalByRefObject.CreateObjRef方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。