internal ComponentManagerProxy(ComponentManagerBroker broker, UnsafeNativeMethods.IMsoComponentManager original)
 {
     this._broker = broker;
     this._original = original;
     this._creationThread = SafeNativeMethods.GetCurrentThreadId();
     this._refCount = 0;
 }
Example #2
0
 internal ComponentManagerProxy(ComponentManagerBroker broker, UnsafeNativeMethods.IMsoComponentManager original)
 {
     this._broker         = broker;
     this._original       = original;
     this._creationThread = SafeNativeMethods.GetCurrentThreadId();
     this._refCount       = 0;
 }
 internal static UnsafeNativeMethods.IMsoComponentManager GetComponentManager(IntPtr pOriginal)
 {
     lock (_syncObject)
     {
         if (_broker == null)
         {
             object obj2;
             ((UnsafeNativeMethods.ICorRuntimeHost) RuntimeEnvironment.GetRuntimeInterfaceAsObject(typeof(UnsafeNativeMethods.CorRuntimeHost).GUID, typeof(UnsafeNativeMethods.ICorRuntimeHost).GUID)).GetDefaultDomain(out obj2);
             AppDomain currentDomain = obj2 as AppDomain;
             if (currentDomain == null)
             {
                 currentDomain = AppDomain.CurrentDomain;
             }
             if (currentDomain == AppDomain.CurrentDomain)
             {
                 _broker = new ComponentManagerBroker();
             }
             else
             {
                 _broker = GetRemotedComponentManagerBroker(currentDomain);
             }
         }
     }
     return _broker.GetProxy((long) pOriginal);
 }
 public ComponentManagerBroker()
 {
     if (_broker == null)
     {
         _broker = this;
     }
 }
        /// <devdoc>
        ///     This method is factored out of GetComponentManager so we can prevent System.Runtime.Remoting from being
        ///     loaded into the process if we are using a single domain.
        /// </devdoc>
        private static ComponentManagerBroker GetRemotedComponentManagerBroker(AppDomain domain)
        {
            Type ourType = typeof(ComponentManagerBroker);
            ComponentManagerBroker broker = (ComponentManagerBroker)domain.CreateInstanceAndUnwrap(ourType.Assembly.FullName, ourType.FullName);

            return(broker.Singleton);
        }
 internal static UnsafeNativeMethods.IMsoComponentManager GetComponentManager(IntPtr pOriginal)
 {
     lock (_syncObject)
     {
         if (_broker == null)
         {
             object obj2;
             ((UnsafeNativeMethods.ICorRuntimeHost)RuntimeEnvironment.GetRuntimeInterfaceAsObject(typeof(UnsafeNativeMethods.CorRuntimeHost).GUID, typeof(UnsafeNativeMethods.ICorRuntimeHost).GUID)).GetDefaultDomain(out obj2);
             AppDomain currentDomain = obj2 as AppDomain;
             if (currentDomain == null)
             {
                 currentDomain = AppDomain.CurrentDomain;
             }
             if (currentDomain == AppDomain.CurrentDomain)
             {
                 _broker = new ComponentManagerBroker();
             }
             else
             {
                 _broker = GetRemotedComponentManagerBroker(currentDomain);
             }
         }
     }
     return(_broker.GetProxy((long)pOriginal));
 }
 public ComponentManagerBroker()
 {
     if (_broker == null)
     {
         _broker = this;
     }
 }
Example #8
0
 /// <summary>
 ///  Ctor.  Quite a bit happens here. Here, we register a channel so
 ///  we can be found and we publish ouru object by calling Marshal.
 ///
 ///  Note that we have a single static _broker field.  We assign this
 ///  If it is already assigned that means that someone in the default
 ///  app domain needed a component manger broker and craeted it directly,
 ///  passing in false for "remoteObject".  Therefore, all we need to do
 ///  is remote the existing broker.  This makes the instance of
 ///  ComponentManagerBroker we are creating in this ctor a temporary
 ///  object, because the calling code will use the Singleton property
 ///  to extract the actual _broker value.
 ///  NOTE: ctor must be public here for remoting to grab hold.
 /// </summary>
 public ComponentManagerBroker()
 {
     // Note that we only ever configure a single broker object.
     // We could be extremely transient here.
     if (_broker == null)
     {
         _broker = this;
     }
 }
        /// <devdoc>
        ///    This method locates our per-process app domain and connects to a running
        ///    instance of ComponentManagerBroker.  That instance then demand-
        ///    creates an instance of ComponentManagerProxy for the calling thread
        ///    and returns it.
        /// </devdoc>
        internal static UnsafeNativeMethods.IMsoComponentManager GetComponentManager(IntPtr pOriginal)
        {
            lock (_syncObject) {
                if (_broker == null)
                {
                    // We need the default domain for the process. That's the domain we will use
                    // for all component managers.  There is no managed way to get this domain, however,
                    // so we use ICorRuntimeHost.
                    UnsafeNativeMethods.ICorRuntimeHost host = (UnsafeNativeMethods.ICorRuntimeHost)RuntimeEnvironment.GetRuntimeInterfaceAsObject(typeof(UnsafeNativeMethods.CorRuntimeHost).GUID, typeof(UnsafeNativeMethods.ICorRuntimeHost).GUID);
                    object domainObj;
                    int    hr = host.GetDefaultDomain(out domainObj);
                    Debug.Assert(NativeMethods.Succeeded(hr), "ICorRuntimeHost failed to return the default domain.  The only way that should happen is if it hasn't been started yet, but if it hasn't been started how are we running managed code?");
                    AppDomain domain = domainObj as AppDomain;

                    if (domain == null)
                    {
                        Debug.Assert(NativeMethods.Failed(hr) || domain != null, "ICorRuntimeHost::GetDefaultDomain succeeded but didn't retrn us an app domain.");
                        domain = AppDomain.CurrentDomain;
                    }

                    // Ok, we have a domain.  Next, check to see if it is our current domain.
                    // If it is, we bypass the CreateInstanceAndUnwrap logic because we
                    // can directly go with the broker.  In this case we will create a broker
                    // and  NOT remote it.  We will defer the remoting until we have a different
                    // domain.  To detect this, the _broker static variable will be assigned
                    // a broker in the primary app domain.  The CreateInstance code looks at this
                    // and if it is aready set, simply remotes that broker.  That is why there
                    // is a "Singleton" property on the broker -- just in case we had to create
                    // a temporary broker during CreateInstanceAndUnwrap.

                    if (domain == AppDomain.CurrentDomain)
                    {
                        _broker = new ComponentManagerBroker();
                    }
                    else
                    {
                        _broker = GetRemotedComponentManagerBroker(domain);
                    }
                }
            }

            // However we got here, we got here.  What's important is that we have a proxied instance to the broker object
            // and we can now call on it.
            //
            return(_broker.GetProxy((long)pOriginal));
        }
Example #10
0
        /// <devdoc>
        ///    This method locates our per-process app domain and connects to a running
        ///    instance of ComponentManagerBroker.  That instance then demand-
        ///    creates an instance of ComponentManagerProxy for the calling thread
        ///    and returns it.
        /// </devdoc>
        internal static UnsafeNativeMethods.IMsoComponentManager GetComponentManager(IntPtr pOriginal) {

            lock(_syncObject) {

                if (_broker == null) {

                    // We need the default domain for the process. That's the domain we will use
                    // for all component managers.  There is no managed way to get this domain, however,
                    // so we use ICorRuntimeHost.
                    UnsafeNativeMethods.ICorRuntimeHost host = (UnsafeNativeMethods.ICorRuntimeHost) RuntimeEnvironment.GetRuntimeInterfaceAsObject(typeof(UnsafeNativeMethods.CorRuntimeHost).GUID, typeof(UnsafeNativeMethods.ICorRuntimeHost).GUID);
                    object domainObj;
                    int hr = host.GetDefaultDomain(out domainObj);
                    Debug.Assert(NativeMethods.Succeeded(hr), "ICorRuntimeHost failed to return the default domain.  The only way that should happen is if it hasn't been started yet, but if it hasn't been started how are we running managed code?");
                    AppDomain domain = domainObj as AppDomain;

                    if (domain == null) {
                        Debug.Assert(NativeMethods.Failed(hr) || domain != null, "ICorRuntimeHost::GetDefaultDomain succeeded but didn't retrn us an app domain.");
                        domain = AppDomain.CurrentDomain;
                    }

                    // Ok, we have a domain.  Next, check to see if it is our current domain.  
                    // If it is, we bypass the CreateInstanceAndUnwrap logic because we
                    // can directly go with the broker.  In this case we will create a broker
                    // and  NOT remote it.  We will defer the remoting until we have a different
                    // domain.  To detect this, the _broker static variable will be assigned
                    // a broker in the primary app domain.  The CreateInstance code looks at this
                    // and if it is aready set, simply remotes that broker.  That is why there
                    // is a "Singleton" property on the broker -- just in case we had to create
                    // a temporary broker during CreateInstanceAndUnwrap.

                    if (domain == AppDomain.CurrentDomain) {
                        _broker = new ComponentManagerBroker();
                    }
                    else {
                        _broker = GetRemotedComponentManagerBroker(domain);
                    }
                }
            }

            // However we got here, we got here.  What's important is that we have a proxied instance to the broker object
            // and we can now call on it.
            // 
            return _broker.GetProxy((long)pOriginal);
        }
Example #11
0
        /// <devdoc>
        ///     Ctor.  Quite a bit happens here. Here, we register a channel so 
        ///     we can be found and we publish ouru object by calling Marshal.
        ///
        ///     Note that we have a single static _broker field.  We assign this
        ///     If it is already assigned that means that someone in the default
        ///     app domain needed a component manger broker and craeted it directly,
        ///     passing in false for "remoteObject".  Therefore, all we need to do
        ///     is remote the existing broker.  This makes the instance of
        ///     ComponentManagerBroker we are creating in this ctor a temporary
        ///     object, because the calling code will use the Singleton property
        ///     to extract the actual _broker value.
        ///    NOTE: ctor must be public here for remoting to grab hold.
        /// </devdoc>
        public ComponentManagerBroker() {

            // Note that we only ever configure a single broker object.
            // We could be extremely transient here.
            if (_broker == null) {
                _broker = this;
            }
        }