forked from rubberduck-vba/Rubberduck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add non-disposal decorators for com wrappers
This adds decorators for several com wrapper types that suppress disposal attempts on them. This is relevant in two places. First, the wrappers handed out by the ProjectsRepository are references to cashed wrappers; only the repository itself should be allowed to dispose the instances when it clears its cache. Second, disposal of the com wrappers bound in CW is non-deterministic. In order to avoid running into concurrency issues on shutdown, CW should not be allowed to dispose the wrappers. This will than happen deterministically when disposing the com safe.
- Loading branch information
Showing
10 changed files
with
608 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Rubberduck.VBEEditor/ComManagement/NonDisposalDecorators/AddInNonDisposalDecorator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections.Generic; | ||
using Rubberduck.VBEditor.SafeComWrappers.Abstract; | ||
|
||
namespace Rubberduck.VBEditor.ComManagement.NonDisposalDecorators | ||
{ | ||
public class AddInNonDisposalDecorator<T> : NonDisposalDecoratorBase<T>, IAddIn | ||
where T : IAddIn | ||
{ | ||
public AddInNonDisposalDecorator(T addIn) | ||
: base(addIn) | ||
{ } | ||
|
||
public bool Equals(IAddIn other) | ||
{ | ||
return WrappedItem.Equals(other); | ||
} | ||
|
||
public string ProgId => WrappedItem.ProgId; | ||
|
||
public string Guid => WrappedItem.Guid; | ||
|
||
public string Description | ||
{ | ||
get => WrappedItem.Description; | ||
set => WrappedItem.Description = value; | ||
} | ||
|
||
public bool Connect | ||
{ | ||
get => WrappedItem.Connect; | ||
set => WrappedItem.Connect = value; | ||
} | ||
|
||
public object Object | ||
{ | ||
get => WrappedItem.Object; | ||
set => WrappedItem.Object = value; | ||
} | ||
|
||
public IVBE VBE => WrappedItem.VBE; | ||
|
||
public IAddIns Collection => WrappedItem.Collection; | ||
|
||
public IReadOnlyDictionary<CommandBarSite, CommandBarLocation> CommandBarLocations => WrappedItem.CommandBarLocations; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
Rubberduck.VBEEditor/ComManagement/NonDisposalDecorators/CommandBarsNonDisposalDecorator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Rubberduck.VBEditor.SafeComWrappers; | ||
using Rubberduck.VBEditor.SafeComWrappers.Abstract; | ||
|
||
namespace Rubberduck.VBEditor.ComManagement.NonDisposalDecorators | ||
{ | ||
public class CommandBarsNonDisposalDecorator<T> : NonDisposalDecoratorBase<T>, ICommandBars | ||
where T : ICommandBars | ||
{ | ||
public CommandBarsNonDisposalDecorator(T commandBars) | ||
: base(commandBars) | ||
{ } | ||
|
||
public IEnumerator<ICommandBar> GetEnumerator() | ||
{ | ||
return WrappedItem.GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return ((IEnumerable) WrappedItem).GetEnumerator(); | ||
} | ||
|
||
public int Count => WrappedItem.Count; | ||
|
||
public ICommandBar this[object index] => WrappedItem[index]; | ||
|
||
public ICommandBar Add(string name) | ||
{ | ||
return WrappedItem.Add(name); | ||
} | ||
|
||
public ICommandBar Add(string name, CommandBarPosition position) | ||
{ | ||
return WrappedItem.Add(name, position); | ||
} | ||
|
||
public ICommandBarControl FindControl(int id) | ||
{ | ||
return WrappedItem.FindControl(id); | ||
} | ||
|
||
public ICommandBarControl FindControl(ControlType type, int id) | ||
{ | ||
return WrappedItem.FindControl(type, id); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Rubberduck.VBEEditor/ComManagement/NonDisposalDecorators/NonDisposalDecoratorBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Rubberduck.VBEditor.SafeComWrappers.Abstract; | ||
|
||
namespace Rubberduck.VBEditor.ComManagement.NonDisposalDecorators | ||
{ | ||
/// <summary> | ||
/// Decorator for SafeComWrappers to safely hand out references that must not be disposed | ||
/// </summary> | ||
/// <typeparam name="T">Concrete type of the safe com wrapper to decorate</typeparam> | ||
public class NonDisposalDecoratorBase<T> : ISafeComWrapper | ||
where T :ISafeComWrapper | ||
{ | ||
protected readonly T WrappedItem; | ||
|
||
public NonDisposalDecoratorBase(T wrappedItem) | ||
{ | ||
WrappedItem = wrappedItem; | ||
} | ||
|
||
public object Target => WrappedItem.Target; | ||
public bool IsWrappingNullReference => WrappedItem.IsWrappingNullReference; | ||
public void Dispose() | ||
{ | ||
//Do nothing | ||
} | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
Rubberduck.VBEEditor/ComManagement/NonDisposalDecorators/VBComponentNonDisposalDecorator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using Rubberduck.VBEditor.SafeComWrappers; | ||
using Rubberduck.VBEditor.SafeComWrappers.Abstract; | ||
|
||
namespace Rubberduck.VBEditor.ComManagement.NonDisposalDecorators | ||
{ | ||
public class VBComponentNonDisposalDecorator<T> : NonDisposalDecoratorBase<T>, IVBComponent | ||
where T : IVBComponent | ||
{ | ||
public VBComponentNonDisposalDecorator(T component) | ||
: base(component) | ||
{ } | ||
|
||
public bool Equals(IVBComponent other) | ||
{ | ||
return WrappedItem.Equals(other); | ||
} | ||
|
||
public ComponentType Type => WrappedItem.Type; | ||
|
||
public bool HasCodeModule => WrappedItem.HasCodeModule; | ||
|
||
public ICodeModule CodeModule => WrappedItem.CodeModule; | ||
|
||
public IVBE VBE => WrappedItem.VBE; | ||
|
||
public IVBComponents Collection => WrappedItem.Collection; | ||
|
||
public IProperties Properties => WrappedItem.Properties; | ||
|
||
public IControls Controls => WrappedItem.Controls; | ||
|
||
public IControls SelectedControls => WrappedItem.SelectedControls; | ||
|
||
public bool IsSaved => WrappedItem.IsSaved; | ||
|
||
public bool HasDesigner => WrappedItem.HasDesigner; | ||
|
||
public bool HasOpenDesigner => WrappedItem.HasOpenDesigner; | ||
|
||
public string DesignerId => WrappedItem.DesignerId; | ||
|
||
public string Name | ||
{ | ||
get => WrappedItem.Name; | ||
set => WrappedItem.Name = value; | ||
} | ||
|
||
public IWindow DesignerWindow() | ||
{ | ||
return WrappedItem.DesignerWindow(); | ||
} | ||
|
||
public void Activate() | ||
{ | ||
WrappedItem.Activate(); | ||
} | ||
|
||
public void Export(string path) | ||
{ | ||
WrappedItem.Export(path); | ||
} | ||
|
||
public string ExportAsSourceFile(string folder, bool isTempFile = false, bool specialCaseDocumentModules = true) | ||
{ | ||
return WrappedItem.ExportAsSourceFile(folder, isTempFile, specialCaseDocumentModules); | ||
} | ||
|
||
public int FileCount => WrappedItem.FileCount; | ||
|
||
public string GetFileName(short index) | ||
{ | ||
return WrappedItem.GetFileName(index); | ||
} | ||
|
||
public IVBProject ParentProject => WrappedItem.ParentProject; | ||
|
||
public int ContentHash() | ||
{ | ||
return WrappedItem.ContentHash(); | ||
} | ||
|
||
public QualifiedModuleName QualifiedModuleName => WrappedItem.QualifiedModuleName; | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
Rubberduck.VBEEditor/ComManagement/NonDisposalDecorators/VBComponentsNonDisposalDecorator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Rubberduck.VBEditor.Events; | ||
using Rubberduck.VBEditor.SafeComWrappers; | ||
using Rubberduck.VBEditor.SafeComWrappers.Abstract; | ||
|
||
namespace Rubberduck.VBEditor.ComManagement.NonDisposalDecorators | ||
{ | ||
public class VBComponentsNonDisposalDecorator<T> : NonDisposalDecoratorBase<T>, IVBComponents | ||
where T : IVBComponents | ||
{ | ||
public VBComponentsNonDisposalDecorator(T components) | ||
: base(components) | ||
{ } | ||
|
||
public void AttachEvents() | ||
{ | ||
WrappedItem.AttachEvents(); | ||
} | ||
|
||
public void DetachEvents() | ||
{ | ||
WrappedItem.DetachEvents(); | ||
} | ||
|
||
public IEnumerator<IVBComponent> GetEnumerator() | ||
{ | ||
return WrappedItem.GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return ((IEnumerable) WrappedItem).GetEnumerator(); | ||
} | ||
|
||
public int Count => WrappedItem.Count; | ||
|
||
public event EventHandler<ComponentEventArgs> ComponentAdded | ||
{ | ||
add => WrappedItem.ComponentAdded += value; | ||
remove => WrappedItem.ComponentAdded -= value; | ||
} | ||
|
||
public event EventHandler<ComponentEventArgs> ComponentRemoved | ||
{ | ||
add => WrappedItem.ComponentRemoved += value; | ||
remove => WrappedItem.ComponentRemoved -= value; | ||
} | ||
|
||
public event EventHandler<ComponentRenamedEventArgs> ComponentRenamed | ||
{ | ||
add => WrappedItem.ComponentRenamed += value; | ||
remove => WrappedItem.ComponentRenamed -= value; | ||
} | ||
|
||
public event EventHandler<ComponentEventArgs> ComponentSelected | ||
{ | ||
add => WrappedItem.ComponentSelected += value; | ||
remove => WrappedItem.ComponentSelected -= value; | ||
} | ||
|
||
public event EventHandler<ComponentEventArgs> ComponentActivated | ||
{ | ||
add => WrappedItem.ComponentActivated += value; | ||
remove => WrappedItem.ComponentActivated -= value; | ||
} | ||
|
||
public event EventHandler<ComponentEventArgs> ComponentReloaded | ||
{ | ||
add => WrappedItem.ComponentReloaded += value; | ||
remove => WrappedItem.ComponentReloaded -= value; | ||
} | ||
|
||
public IVBComponent this[object index] => WrappedItem[index]; | ||
|
||
public IVBE VBE => WrappedItem.VBE; | ||
|
||
public IVBProject Parent => WrappedItem.Parent; | ||
|
||
public void Remove(IVBComponent item) | ||
{ | ||
WrappedItem.Remove(item); | ||
} | ||
|
||
public IVBComponent Add(ComponentType type) | ||
{ | ||
return WrappedItem.Add(type); | ||
} | ||
|
||
public IVBComponent Import(string path) | ||
{ | ||
return WrappedItem.Import(path); | ||
} | ||
|
||
public IVBComponent AddCustom(string progId) | ||
{ | ||
return WrappedItem.AddCustom(progId); | ||
} | ||
|
||
public IVBComponent ImportSourceFile(string path) | ||
{ | ||
return WrappedItem.ImportSourceFile(path); | ||
} | ||
|
||
public void RemoveSafely(IVBComponent component) | ||
{ | ||
WrappedItem.RemoveSafely(component); | ||
} | ||
|
||
public bool Equals(IVBComponents other) | ||
{ | ||
return WrappedItem.Equals(other); | ||
} | ||
} | ||
} |
Oops, something went wrong.