1 // -----------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 // -----------------------------------------------------------------------
5 using System
.Collections
.Generic
;
6 using System
.ComponentModel
.Composition
.Primitives
;
7 using System
.Diagnostics
;
9 using System
.Runtime
.CompilerServices
;
10 using Microsoft
.Internal
;
11 using Microsoft
.Internal
.Collections
;
13 namespace System
.ComponentModel
.Composition
.Hosting
15 public partial class ImportEngine
18 /// Used to wrap the start and stop of enforcing export changes don't
19 /// break required imports. This context is stored in a AtomicComposition.
21 private class EngineContext
23 private ImportEngine _importEngine
;
24 private List
<PartManager
> _addedPartManagers
= new List
<PartManager
>();
25 private List
<PartManager
> _removedPartManagers
= new List
<PartManager
>();
26 private EngineContext _parentEngineContext
;
28 public EngineContext(ImportEngine importEngine
, EngineContext parentEngineContext
)
30 this._importEngine
= importEngine
;
31 this._parentEngineContext
= parentEngineContext
;
34 public void AddPartManager(PartManager part
)
36 Assumes
.NotNull(part
);
37 if (!this._removedPartManagers
.Remove(part
))
39 this._addedPartManagers
.Add(part
);
43 public void RemovePartManager(PartManager part
)
45 Assumes
.NotNull(part
);
46 if (!this._addedPartManagers
.Remove(part
))
48 this._removedPartManagers
.Add(part
);
52 public IEnumerable
<PartManager
> GetAddedPartManagers()
54 if (this._parentEngineContext
!= null)
56 return this._addedPartManagers
.ConcatAllowingNull(this._parentEngineContext
.GetAddedPartManagers());
58 return this._addedPartManagers
;
61 public IEnumerable
<PartManager
> GetRemovedPartManagers()
63 if (this._parentEngineContext
!= null)
65 return this._removedPartManagers
.ConcatAllowingNull(this._parentEngineContext
.GetRemovedPartManagers());
67 return this._removedPartManagers
;
70 public void Complete()
72 foreach (var partManager
in this._addedPartManagers
)
74 this._importEngine
.StartSatisfyingImports(partManager
, null);
77 foreach (var partManager
in this._removedPartManagers
)
79 this._importEngine
.StopSatisfyingImports(partManager
, null);