コード例 #1
0
        // Find the controller given the HAV (addIn), optionally also removing it.
        // This code also removes any stale HAVControllerPairs that it finds, as
        // may happen when a HAV is garbage collected.
        private static AddInControllerImpl FindController(Object addIn, bool remove)
        {
            System.Diagnostics.Contracts.Contract.Requires(addIn != null);

            lock (_havLock)
            {
                HAVControllerPair current = _havList;
                HAVControllerPair last    = null;
                while (current != null)
                {
                    Object o = current._HAV.Target;
                    if (o == null)
                    {
                        // this one has been GC'd.  Clean up the WR
                        if (last == null)
                        {
                            _havList = current._next;
                            continue;
                        }
                        else
                        {
                            last._next = current._next;
                            current    = current._next;
                            continue;
                        }
                    }
                    else
                    {
                        if (addIn.Equals(o))
                        {
                            AddInControllerImpl value = current._controller;
                            if (remove)
                            {
                                if (last == null)
                                {
                                    _havList = current._next;
                                }
                                else
                                {
                                    last._next = current._next;
                                }
                            }
                            return(value);
                        }
                    }

                    last    = current;
                    current = current._next;
                }
            }
            return(null);
        }
コード例 #2
0
        // Requires the HAV and the transparent proxy to the add-in adapter,
        // which implements System.AddIn.Contract.IContract.
        internal void AssociateWithHostAddinView(Object hostAddinView, IContract contract)
        {
            System.Diagnostics.Contracts.Contract.Requires(hostAddinView != null);
            _contract = contract;

            // add weak reference on the HAV to our list
            _havReference = new WeakReference(hostAddinView);
            lock (_havLock)
            {
                HAVControllerPair havRef = new HAVControllerPair(hostAddinView, this);
                havRef._next = _havList;
                _havList     = havRef;

                // clean up the list every so often
                _addInCountSinceLastPrune++;
                if (_addInCountSinceLastPrune == AddInCountSinceLastPruneLimit)
                {
                    // searching for a non-exiting addin will have the desired effect
                    // of pruning the list of any stale references.
                    FindController(new Object(), false);
                    _addInCountSinceLastPrune = 0;
                }
            }
        }
コード例 #3
0
        // Requires the HAV and the transparent proxy to the add-in adapter, 
        // which implements System.AddIn.Contract.IContract.
        internal void AssociateWithHostAddinView(Object hostAddinView, IContract contract)
        {
            System.Diagnostics.Contracts.Contract.Requires(hostAddinView != null);
            _contract = contract;

            // add weak reference on the HAV to our list
            _havReference = new WeakReference(hostAddinView);
            lock (_havLock)
            {
                HAVControllerPair havRef = new HAVControllerPair(hostAddinView, this);
                havRef._next = _havList;
                _havList = havRef;

                // clean up the list every so often
                _addInCountSinceLastPrune++;
                if (_addInCountSinceLastPrune == AddInCountSinceLastPruneLimit)
                {
                    // searching for a non-exiting addin will have the desired effect
                    // of pruning the list of any stale references.
                    FindController(new Object(), false);
                    _addInCountSinceLastPrune = 0;
                }
            }
        }
コード例 #4
0
        // Find the controller given the HAV (addIn), optionally also removing it.
        // This code also removes any stale HAVControllerPairs that it finds, as
        // may happen when a HAV is garbage collected.
        private static AddInControllerImpl FindController(Object addIn, bool remove)
        {
            System.Diagnostics.Contracts.Contract.Requires(addIn != null);

            lock (_havLock)
            {
                HAVControllerPair current = _havList;
                HAVControllerPair last = null;
                while(current != null)
                {
                    Object o = current._HAV.Target;
                    if (o == null)
                    {
                        // this one has been GC'd.  Clean up the WR
                        if (last == null)
                        {
                            _havList = current._next;
                            continue;
                        }
                        else
                        {
                            last._next = current._next;
                            current = current._next;
                            continue;
                        }
                    }
                    else
                    {
                        if (addIn.Equals(o))
                        {
                            AddInControllerImpl value = current._controller;
                            if (remove)
                            {
                                if (last == null)
                                    _havList = current._next;
                                else
                                    last._next = current._next;
                            }
                            return value;
                        }
                    }

                    last = current;
                    current = current._next;
                }
            }
            return null;
        }