public FilteredCatalog(ComposablePartCatalog inner,
                        Func<ComposablePartDefinition, bool> filter)
 {
     _inner = inner;
     _innerNotifyChange = inner as INotifyComposablePartCatalogChanged;
     _partsQuery = inner.Parts.Where(filter).AsQueryable();
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the Berico.LinkAnalysis.SnagL.Modularity.FilteredCatalog
 /// class.  The specified ComposablePartCatalog will use the specified  expression to
 /// perform a LINQ Where query in order to filter the parts in the catalog.
 /// </summary>
 /// <param name="inner">The ComposablePartCatalog that will be filtered</param>
 /// <param name="expression">A Func delegate</param>
 public FilteredCatalog(ComposablePartCatalog inner,
                        Expression <Func <ComposablePartDefinition, bool> > expression)
 {
     _inner             = inner;
     _innerNotifyChange = inner as INotifyComposablePartCatalogChanged;
     _partsQuery        = inner.Parts.Where(expression);
 }
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    // NOTE : According to http://msdn.microsoft.com/en-us/library/4bw5ewxy.aspx, the warning is bogus when used with Interlocked API.
#pragma warning disable 420
                    if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0)
#pragma warning restore 420
                    {
                        INotifyComposablePartCatalogChanged notifyCatalog = _catalog as INotifyComposablePartCatalogChanged;
                        if (notifyCatalog != null)
                        {
                            notifyCatalog.Changed  -= OnChangedInternal;
                            notifyCatalog.Changing -= OnChangingInternal;
                        }
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
示例#4
0
 public FilteredCatalog(ComposablePartCatalog inner,
                        Func <ComposablePartDefinition, bool> filter)
 {
     _inner             = inner;
     _innerNotifyChange = inner as INotifyComposablePartCatalogChanged;
     _partsQuery        = inner.Parts.Where(filter).AsQueryable();
 }
示例#5
0
        internal CompositionService(ComposablePartCatalog composablePartCatalog)
        {
            Assumes.NotNull(composablePartCatalog);
            this._notifyCatalog = composablePartCatalog as INotifyComposablePartCatalogChanged;
            try
            {
                if(this._notifyCatalog != null)
                {
                    this._notifyCatalog.Changing += this.OnCatalogChanging;
                }

                var compositionOptions = CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe | CompositionOptions.ExportCompositionService;
                var compositionContainer = new CompositionContainer(composablePartCatalog, compositionOptions);
    
                this._compositionContainer = compositionContainer;
            }
            catch
            {
                if(this._notifyCatalog != null)
                {
                    this._notifyCatalog.Changing -= this.OnCatalogChanging;
                }
                throw;
            }
        }
示例#6
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API.
#pragma warning disable 420
                    if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0)
#pragma warning restore 420
                    {
                        INotifyComposablePartCatalogChanged notifyCatalog = _catalog as INotifyComposablePartCatalogChanged;
                        if (notifyCatalog != null)
                        {
                            notifyCatalog.Changed  -= OnChangedInternal;
                            notifyCatalog.Changing -= OnChangingInternal;
                        }
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
示例#7
0
    /// <summary>
    /// Initializes a new instance of the FilteredCatalog class with the specified underlying
    /// catalog and filter.
    /// </summary>
    public FilteredCatalog(ComposablePartCatalog inner,
		Expression<Func<ComposablePartDefinition, bool>> expression)
    {
        _inner = inner;
        _innerNotifyChange = inner as INotifyComposablePartCatalogChanged;
        _partsQuery = inner.Parts.Where(expression);
    }
示例#8
0
        internal CompositionService(ComposablePartCatalog composablePartCatalog)
        {
            Assumes.NotNull(composablePartCatalog);
            _notifyCatalog = composablePartCatalog as INotifyComposablePartCatalogChanged;
            try
            {
                if (_notifyCatalog != null)
                {
                    _notifyCatalog.Changing += OnCatalogChanging;
                }

                var compositionOptions   = CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe | CompositionOptions.ExportCompositionService;
                var compositionContainer = new CompositionContainer(composablePartCatalog, compositionOptions);

                _compositionContainer = compositionContainer;
            }
            catch
            {
                if (_notifyCatalog != null)
                {
                    _notifyCatalog.Changing -= OnCatalogChanging;
                }
                throw;
            }
        }
示例#9
0
        private void UnfreezeInnerCatalog()
        {
            INotifyComposablePartCatalogChanged innerNotifyCatalog = _innerCatalog as INotifyComposablePartCatalogChanged;

            if (innerNotifyCatalog != null)
            {
                innerNotifyCatalog.Changing -= ThrowOnRecomposition;
            }
        }
        private void SubscribeToCatalogNotifications(ComposablePartCatalog catalog)
        {
            INotifyComposablePartCatalogChanged notifyCatalog = catalog as INotifyComposablePartCatalogChanged;

            if (notifyCatalog != null)
            {
                notifyCatalog.Changed  += OnContainedCatalogChanged;
                notifyCatalog.Changing += OnContainedCatalogChanging;
            }
        }
        private void UnsubscribeFromCatalogNotifications(ComposablePartCatalog catalog)
        {
            INotifyComposablePartCatalogChanged notifyCatalog = catalog as INotifyComposablePartCatalogChanged;

            if (notifyCatalog != null)
            {
                notifyCatalog.Changed  -= this.OnContainedCatalogChanged;
                notifyCatalog.Changing -= this.OnContainedCatalogChanging;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InterceptingCatalog"/> class.
        /// </summary>
        /// <param name="interceptedCatalog">Catalog to be intercepted.</param>
        /// <param name="configuration">Interception configuration.</param>
        public InterceptingCatalog(ComposablePartCatalog interceptedCatalog, IInterceptionConfiguration configuration)
        {
            if (interceptedCatalog == null) throw new ArgumentNullException("interceptedCatalog");
            if (configuration == null) throw new ArgumentNullException("configuration");

            this.interceptedCatalog = interceptedCatalog;
            this.interceptedCatalogNotifyChange = interceptedCatalog as INotifyComposablePartCatalogChanged;
            this.configuration = configuration;

            InitializeHandlers();
        }
示例#13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FilteringCatalog"/> class.
        /// </summary>
        /// <param name="inner">A <see cref="ComposablePartCatalog"/> whose parts
        /// are to be filtered based on a given criteria.</param>
        /// <param name="expression">An <see cref="Expression"/> which defines the filter query.</param>
        public FilteringCatalog(ComposablePartCatalog inner,
            Expression<Func<ComposablePartDefinition, bool>> expression)
        {
            if (inner == null)
                throw new ArgumentNullException("inner");

            if (expression == null)
                throw new ArgumentNullException("expression");

            this.innerNotifyChange = inner as INotifyComposablePartCatalogChanged;
            this.partsQuery = inner.Parts.Where(expression);
        }
示例#14
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!this._isDisposed)
                {
                    bool disposeLock = false;
                    INotifyComposablePartCatalogChanged catalogToUnsubscribeFrom = null;
                    HashSet <IDisposable> partsToDispose = null;

                    try
                    {
                        using (new WriteLock(this._lock))
                        {
                            if (!this._isDisposed)
                            {
                                catalogToUnsubscribeFrom = this._catalog as INotifyComposablePartCatalogChanged;
                                this._catalog            = null;

                                partsToDispose       = this._partsToDispose;
                                this._partsToDispose = new HashSet <IDisposable>();
                                this._activatedParts.Clear();
                                this._conditionalReferencesForRecomposableParts = null;

                                disposeLock      = true;
                                this._isDisposed = true;
                            }
                        }
                    }
                    finally
                    {
                        if (catalogToUnsubscribeFrom != null)
                        {
                            catalogToUnsubscribeFrom.Changing -= this.OnCatalogChanging;
                        }

                        if (partsToDispose != null)
                        {
                            foreach (var part in partsToDispose)
                            {
                                part.Dispose();
                            }
                        }

                        if (disposeLock)
                        {
                            this._lock.Dispose();
                        }
                    }
                }
            }
        }
示例#15
0
        public AddInCatalog(ComposablePartCatalog innerCatalog, string packageId, string packageVersion) : base()
        {
            this.InnerCatalog   = innerCatalog;
            this.PackageId      = packageId;
            this.PackageVersion = packageVersion;

            INotifyComposablePartCatalogChanged notify = innerCatalog as INotifyComposablePartCatalogChanged;

            if (notify != null)
            {
                notify.Changed  += (sender, args) => this.OnChanged(args);
                notify.Changing += (sender, args) => this.OnChanging(args);
            }
        }
示例#16
0
        internal FilteredCatalog(ComposablePartCatalog catalog, Func <ComposablePartDefinition, bool> filter, FilteredCatalog complement)
        {
            Requires.NotNull(catalog, nameof(catalog));
            Requires.NotNull(filter, nameof(filter));

            _innerCatalog = catalog;
            _filter       = (p) => filter.Invoke(p.GetGenericPartDefinition() ?? p);
            _complement   = complement;

            INotifyComposablePartCatalogChanged notifyCatalog = _innerCatalog as INotifyComposablePartCatalogChanged;

            if (notifyCatalog != null)
            {
                notifyCatalog.Changed  += OnChangedInternal;
                notifyCatalog.Changing += OnChangingInternal;
            }
        }
示例#17
0
        internal FilteredCatalog(ComposablePartCatalog catalog, Func <ComposablePartDefinition, bool> filter, FilteredCatalog complement)
        {
            Requires.NotNull(catalog, "catalog");
            Requires.NotNull(filter, "filter");

            this._innerCatalog = catalog;
            this._filter       = filter;
            this._complement   = complement;
            this._partsQuery   = this._innerCatalog.Parts.Where(this._filter).AsQueryable();

            INotifyComposablePartCatalogChanged notifyCatalog = this._innerCatalog as INotifyComposablePartCatalogChanged;

            if (notifyCatalog != null)
            {
                notifyCatalog.Changed  += this.OnChangedInternal;
                notifyCatalog.Changing += this.OnChangingInternal;
            }
        }
示例#18
0
/// <summary>
        /// Initializes a new instance of the <see cref="CompositionScopeDefinition"/> class.
        /// </summary>
        /// <param name="catalog">The catalog.</param>
        /// <param name="children">The children.</param>
        private void InitializeCompositionScopeDefinition(ComposablePartCatalog catalog, IEnumerable <CompositionScopeDefinition> children, IEnumerable <ExportDefinition> publicSurface)
        {
            _catalog = catalog;
            if (children != null)
            {
                _children = children.ToArray();
            }
            if (publicSurface != null)
            {
                _publicSurface = publicSurface;
            }

            INotifyComposablePartCatalogChanged notifyCatalog = _catalog as INotifyComposablePartCatalogChanged;

            if (notifyCatalog != null)
            {
                notifyCatalog.Changed  += OnChangedInternal;
                notifyCatalog.Changing += OnChangingInternal;
            }
        }
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (disposing)
         {
             if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0)
             {
                 INotifyComposablePartCatalogChanged notifyCatalog = _catalog as INotifyComposablePartCatalogChanged;
                 if (notifyCatalog != null)
                 {
                     notifyCatalog.Changed  -= OnChangedInternal;
                     notifyCatalog.Changing -= OnChangingInternal;
                 }
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
示例#20
0
/// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    if (!_isDisposed)
                    {
                        INotifyComposablePartCatalogChanged notifyCatalog = null;
                        try
                        {
                            lock (_lock)
                            {
                                if (!_isDisposed)
                                {
                                    _isDisposed   = true;
                                    notifyCatalog = _innerCatalog as INotifyComposablePartCatalogChanged;
                                    _innerCatalog = null;
                                }
                            }
                        }
                        finally
                        {
                            if (notifyCatalog != null)
                            {
                                notifyCatalog.Changed  -= OnChangedInternal;
                                notifyCatalog.Changing -= OnChangingInternal;
                            }
                        }
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!_isDisposed)
                {
                    //Note:  We do not dispose _lock on dispose because DisposePart needs it to check isDisposed state
                    //          to eliminate race conditions between it and Dispose
                    INotifyComposablePartCatalogChanged catalogToUnsubscribeFrom = null;
                    HashSet <IDisposable>   partsToDispose          = null;
                    ImportEngine            importEngine            = null;
                    ExportProvider          sourceProvider          = null;
                    AggregateExportProvider aggregateExportProvider = null;
                    try
                    {
                        using (_lock.LockStateForWrite())
                        {
                            if (!_isDisposed)
                            {
                                catalogToUnsubscribeFrom = _catalog as INotifyComposablePartCatalogChanged;
                                _catalog = null;

                                aggregateExportProvider = _innerExportProvider as AggregateExportProvider;
                                _innerExportProvider    = null;

                                sourceProvider  = _sourceProvider;
                                _sourceProvider = null;

                                importEngine  = _importEngine;
                                _importEngine = null;

                                partsToDispose = _partsToDispose;
                                _gcRoots       = null;
                                _isDisposed    = true;
                            }
                        }
                    }
                    finally
                    {
                        if (catalogToUnsubscribeFrom != null)
                        {
                            catalogToUnsubscribeFrom.Changing -= OnCatalogChanging;
                        }

                        if (aggregateExportProvider != null)
                        {
                            aggregateExportProvider.Dispose();
                        }

                        if (sourceProvider != null)
                        {
                            sourceProvider.ExportsChanging -= OnExportsChangingInternal;
                        }

                        if (importEngine != null)
                        {
                            importEngine.Dispose();
                        }

                        if (partsToDispose != null)
                        {
                            foreach (var part in partsToDispose)
                            {
                                part.Dispose();
                            }
                        }
                    }
                }
            }
        }
示例#22
0
 public DesignTimeCatalog(ComposablePartCatalog inner)
 {
     _inner = inner;
     _innerNotifyChange = inner as INotifyComposablePartCatalogChanged;
 }
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!this._isDisposed)
                {
                    bool disposeLock = false;
                    INotifyComposablePartCatalogChanged catalogToUnsubscribeFrom = null;
                    HashSet <IDisposable> partsToDispose = null;
                    ImportEngine          importEngine   = null;
                    ExportProvider        sourceProvider = null;
                    try
                    {
                        using (this._lock.LockStateForWrite())
                        {
                            if (!this._isDisposed)
                            {
                                catalogToUnsubscribeFrom = this._catalog as INotifyComposablePartCatalogChanged;
                                this._catalog            = null;

                                sourceProvider       = this._sourceProvider;
                                this._sourceProvider = null;

                                importEngine       = this._importEngine;
                                this._importEngine = null;

                                partsToDispose = this._partsToDispose;
                                this._gcRoots  = null;

                                disposeLock      = true;
                                this._isDisposed = true;
                            }
                        }
                    }
                    finally
                    {
                        if (catalogToUnsubscribeFrom != null)
                        {
                            catalogToUnsubscribeFrom.Changing -= this.OnCatalogChanging;
                        }

                        if (sourceProvider != null)
                        {
                            sourceProvider.ExportsChanging -= this.OnExportsChangingInternal;
                        }

                        if (importEngine != null)
                        {
                            importEngine.Dispose();
                        }

                        if (partsToDispose != null)
                        {
                            foreach (var part in partsToDispose)
                            {
                                part.Dispose();
                            }
                        }

                        if (disposeLock)
                        {
                            this._lock.Dispose();
                        }
                    }
                }
            }
        }
示例#24
0
 /// <summary>
 /// 默认构造函数。
 /// </summary>
 /// <param name="composablePartCatalog">包含了所有导出部件的目录Catalog。</param>
 /// <param name="expression">筛选条件表达式。</param>
 public FilteredCatalog(ComposablePartCatalog composablePartCatalog, Expression <Func <ComposablePartDefinition, bool> > expression)
 {
     m_ComposablePartCatalog = composablePartCatalog;
     m_NotifyComposablePartCatalogChanged = composablePartCatalog as INotifyComposablePartCatalogChanged;
     m_Parts = composablePartCatalog.Parts.Where(expression);
 }
示例#25
0
 public DesignTimeCatalog(ComposablePartCatalog inner)
 {
     _inner             = inner;
     _innerNotifyChange = inner as INotifyComposablePartCatalogChanged;
 }