Created
January 5, 2012 20:06
-
-
Save pranavkm/1566979 to your computer and use it in GitHub Desktop.
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
using System; | |
using EnvDTE; | |
namespace NuGet.VisualStudio | |
{ | |
public static class VsVersionHelper | |
{ | |
private static readonly Lazy<int> _vsMajorVersion = new Lazy<int>(GetMajorVsVersion); | |
private static bool _isVS2010; | |
public static int VsMajorVersion | |
{ | |
get { return _vsMajorVersion.Value; } | |
} | |
public static bool IsVisualStudio2010 | |
{ | |
get { return VsMajorVersion == 10; } | |
} | |
private static int GetMajorVsVersion() | |
{ | |
DTE dte = ServiceLocator.GetInstance<DTE>(); | |
string vsVersion = dte.Version; | |
return vsVersion.StartsWith("10", StringComparison.OrdinalIgnoreCase) ? 10 : 11; | |
} | |
} | |
} | |
public IFileSystem GetFileSystem(string path, SourceControlBindings binding) | |
{ | |
// Return null if this this binding isn't for us then return null | |
if (ProviderConstants.SupportedVsVersion != VsVersionHelper.VsMajorVersion || | |
String.IsNullOrEmpty(binding.ProviderName) || | |
!binding.ProviderName.Equals(TfsProviderName, StringComparison.OrdinalIgnoreCase)) | |
{ | |
return null; | |
} | |
return GetFileSystemInternal(path, binding); | |
} | |
private static IFileSystem GetFileSystemInternal(string path, SourceControlBindings binding) | |
{ | |
TfsTeamProjectCollection projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(binding.ServerName)); | |
var versionControl = projectCollection.GetService<VersionControlServer>(); | |
Workspace workspace = versionControl.TryGetWorkspace(binding.LocalBinding); | |
return new TfsFileSystem(workspace, path); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment