Example #1
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;
                    ExportProvider sourceProviderToUnsubscribeFrom = null;
                    using (this._lock.LockStateForWrite())
                    {
                        if (!this._isDisposed)
                        {
                            sourceProviderToUnsubscribeFrom = this._sourceProvider;
                            this._sourceProvider            = null;
                            this._recompositionManager      = null;
                            this._partManagers = null;
                            this._isDisposed   = true;
                            disposeLock        = true;
                        }
                    }

                    if (sourceProviderToUnsubscribeFrom != null)
                    {
                        sourceProviderToUnsubscribeFrom.ExportsChanging -= this.OnExportsChanging;
                    }

                    if (disposeLock)
                    {
                        this._lock.Dispose();
                    }
                }
            }
        }
Example #2
0
        private void StopSatisfyingImports(PartManager partManager, AtomicComposition atomicComposition)
        {
            // When not running in a atomicCompositional state, schedule reindexing after ensuring
            // that this isn't a redundant removal
            if (atomicComposition == null)
            {
                ConditionalWeakTable <ComposablePart, PartManager> partManagers = null;
                RecompositionManager recompositionManager = null;

                using (_lock.LockStateForRead())
                {
                    partManagers         = _partManagers;
                    recompositionManager = _recompositionManager;
                }
                if (partManagers != null)                            // Disposal race may have been won by dispose
                {
                    partManagers.Remove(partManager.Part);

                    // Take care of lifetime requirements
                    partManager.DisposeAllDependencies();

                    if (partManager.TrackingImports)
                    {
                        partManager.TrackingImports = false;
                        recompositionManager.AddPartToUnindex(partManager);
                    }
                }
            }
            else
            {
                // While in a atomicCompositional state use a less efficient but effective means
                // of achieving the same results
                GetEngineContext(atomicComposition).RemovePartManager(partManager);
            }
        }
Example #3
0
        private CompositionResult TryRecomposeImports(PartManager partManager,
                                                      IEnumerable <ExportDefinition> changedExports, AtomicComposition atomicComposition)
        {
            var result = CompositionResult.SucceededResult;

            switch (partManager.State)
            {
            case ImportState.ImportsPreviewed:
            case ImportState.Composed:
                // Validate states to continue.
                break;

            default:
            {
                // All other states are invalid and for recomposition.
                return(new CompositionResult(ErrorBuilder.InvalidStateForRecompposition(partManager.Part)));
            }
            }

            var  affectedImports = RecompositionManager.GetAffectedImports(partManager.Part, changedExports);
            bool partComposed    = (partManager.State == ImportState.Composed);

            bool recomposedImport = false;

            foreach (var import in affectedImports)
            {
                result = result.MergeResult(
                    TryRecomposeImport(partManager, partComposed, import, atomicComposition));

                recomposedImport = true;
            }

            // Knowing that the part has already been composed before and that the only possible
            // changes are to recomposable imports, we can safely go ahead and do this now or
            // schedule it for later
            if (result.Succeeded && recomposedImport && partComposed)
            {
                if (atomicComposition == null)
                {
                    result = result.MergeResult(partManager.TryOnComposed());
                }
                else
                {
                    atomicComposition.AddCompleteAction(() => partManager.TryOnComposed().ThrowOnErrors());
                }
            }

            return(result);
        }
Example #4
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)
                {
                    ExportProvider sourceProviderToUnsubscribeFrom = this._sourceProvider;

                    this._sourceProvider       = null;
                    this._recompositionManager = null;
                    this._partManagers         = null;

                    this._isDisposed = true;

                    if (sourceProviderToUnsubscribeFrom != null)
                    {
                        sourceProviderToUnsubscribeFrom.ExportsChanging -= this.OnExportsChanging;
                    }
                }
            }
        }
Example #5
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;
                    ExportProvider sourceProviderToUnsubscribeFrom = null;
                    using (this._lock.LockStateForWrite())
                    {
                        if (!this._isDisposed)
                        {
                            sourceProviderToUnsubscribeFrom = this._sourceProvider;
                            this._sourceProvider = null;
                            this._recompositionManager = null;
                            this._partManagers = null;
                            this._isDisposed = true;
                            disposeLock = true;
                        }
                    }

                    if (sourceProviderToUnsubscribeFrom != null)
                    {
                        sourceProviderToUnsubscribeFrom.ExportsChanging -= this.OnExportsChanging;
                    }

                    if (disposeLock)
                    {
                        this._lock.Dispose();
                    }
                }
            }
        }
Example #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 virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!this._isDisposed)
                {
                    ExportProvider sourceProviderToUnsubscribeFrom = this._sourceProvider;

                    this._sourceProvider = null;
                    this._recompositionManager = null;
                    this._partManagers = null;

                    this._isDisposed = true;

                    if (sourceProviderToUnsubscribeFrom != null)
                    {
                        sourceProviderToUnsubscribeFrom.ExportsChanging -= this.OnExportsChanging;
                    }
                }
            }
        }