This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathTeamExplorerServiceHolder.cs
More file actions
95 lines (83 loc) · 3.43 KB
/
TeamExplorerServiceHolder.cs
File metadata and controls
95 lines (83 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.ComponentModel.Composition;
using GitHub.Extensions;
using GitHub.Services;
using Microsoft.TeamFoundation.Controls;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Threading;
namespace GitHub.VisualStudio.Base
{
[Export(typeof(ITeamExplorerServiceHolder))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class TeamExplorerServiceHolder : ITeamExplorerServiceHolder
{
IServiceProvider serviceProvider;
/// <summary>
/// This class relies on IVSGitExt that provides information when VS switches repositories.
/// </summary>
/// <param name="gitExt">Used for monitoring the active repository.</param>
[ImportingConstructor]
TeamExplorerServiceHolder(ITeamExplorerContext teamExplorerContext) :
this(teamExplorerContext, ThreadHelper.JoinableTaskContext)
{
}
/// <summary>
/// This constructor can be used for unit testing.
/// </summary>
/// <param name="gitService">Used for monitoring the active repository.</param>
/// <param name="joinableTaskContext">Used for switching to the Main thread.</param>
public TeamExplorerServiceHolder(ITeamExplorerContext teamExplorerContext, JoinableTaskContext joinableTaskContext)
{
JoinableTaskCollection = joinableTaskContext.CreateCollection();
JoinableTaskCollection.DisplayName = nameof(TeamExplorerServiceHolder);
JoinableTaskFactory = joinableTaskContext.CreateFactory(JoinableTaskCollection);
TeamExplorerContext = teamExplorerContext;
}
// set by the sections when they get initialized
public IServiceProvider ServiceProvider
{
get { return serviceProvider; }
set
{
if (serviceProvider == value)
return;
serviceProvider = value;
if (serviceProvider == null)
return;
}
}
/// <summary>
/// Clears the current ServiceProvider if it matches the one that is passed in.
/// This is usually called on Dispose, which might happen after another section
/// has changed the ServiceProvider to something else, which is why we require
/// the parameter to match.
/// </summary>
/// <param name="provider">If the current ServiceProvider matches this, clear it</param>
public void ClearServiceProvider(IServiceProvider provider)
{
Guard.ArgumentNotNull(provider, nameof(provider));
if (serviceProvider != provider)
return;
ServiceProvider = null;
}
public IGitAwareItem HomeSection
{
get
{
if (ServiceProvider == null)
return null;
var page = PageService;
if (page == null)
return null;
return page.GetSection(new Guid(TeamExplorer.Home.GitHubHomeSection.GitHubHomeSectionId)) as IGitAwareItem;
}
}
ITeamExplorerPage PageService
{
get { return ServiceProvider.GetServiceSafe<ITeamExplorerPage>(); }
}
public JoinableTaskCollection JoinableTaskCollection { get; }
public JoinableTaskFactory JoinableTaskFactory { get; }
public ITeamExplorerContext TeamExplorerContext { get; }
}
}