Repository navigation
Expand file tree
/
Copy pathVsFileSystemProvider.cs
More file actions
106 lines (91 loc) · 3.67 KB
/
Copy pathVsFileSystemProvider.cs
File metadata and controls
106 lines (91 loc) · 3.67 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
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.ComponentModel.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.ComponentModelHost;
namespace NuGet.VisualStudio
{
[Export(typeof(IFileSystemProvider))]
public class VsFileSystemProvider : IFileSystemProvider
{
private readonly DTE _dte;
private readonly IComponentModel _componentModel;
private readonly ISettings _settings;
public VsFileSystemProvider()
: this(ServiceLocator.GetInstance<DTE>(),
ServiceLocator.GetGlobalService<SComponentModel, IComponentModel>(),
ServiceLocator.GetInstance<ISettings>())
{
}
public VsFileSystemProvider(DTE dte, IComponentModel componentModel, ISettings settings)
{
if (dte == null)
{
throw new ArgumentNullException("dte");
}
if (componentModel == null)
{
throw new ArgumentNullException("componentModel");
}
if (settings == null)
{
throw new ArgumentNullException("settings");
}
_componentModel = componentModel;
_dte = dte;
_settings = settings;
}
public IFileSystem GetFileSystem(string path)
{
return GetFileSystem(path, ignoreSourceControlSetting: false);
}
public IFileSystem GetFileSystem(string path, bool ignoreSourceControlSetting)
{
if (!ignoreSourceControlSetting && _settings.IsSourceControlDisabled())
{
return new PhysicalFileSystem(path);
}
var providers = _componentModel.GetExtensions<ISourceControlFileSystemProvider>();
// Get the repository path
IFileSystem fileSystem = null;
var sourceControl = (SourceControl2)_dte.SourceControl;
if (providers.Any() && sourceControl != null)
{
SourceControlBindings binding = null;
try
{
// Get the binding for this solution
binding = sourceControl.GetBindings(_dte.Solution.FullName);
}
catch (NotImplementedException)
{
// Some source control providers don't bother to implement this.
// TFS might be the only one using it
}
if (binding != null)
{
fileSystem = providers.Select(provider => GetFileSystemFromProvider(provider, path, binding))
.FirstOrDefault(fs => fs != null);
}
}
return fileSystem ?? new PhysicalFileSystem(path);
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We should never fail")]
private static IFileSystem GetFileSystemFromProvider(ISourceControlFileSystemProvider provider, string path, SourceControlBindings binding)
{
try
{
return provider.GetFileSystem(path, binding);
}
catch (Exception exception)
{
ExceptionHelper.WriteToActivityLog(exception);
// Ignore exceptions that can happen when some binaries are missing. e.g. TfsSourceControlFileSystemProvider
// would throw a jitting error if TFS is not installed
}
return null;
}
}
}