public void SetSite() { // Create the package IVsPackage package = new SccProvider() as IVsPackage; Assert.IsNotNull(package, "The object does not implement IVsPackage"); // Create a basic service provider OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices(); // Need to mock a service implementing IVsRegisterScciProvider, because the scc provider will register with it IVsRegisterScciProvider registerScciProvider = MockRegisterScciProvider.GetBaseRegisterScciProvider(); serviceProvider.AddService(typeof(IVsRegisterScciProvider), registerScciProvider, true); // Register solution events because the provider will try to subscribe to them MockSolution solution = new MockSolution(); serviceProvider.AddService(typeof(SVsSolution), solution as IVsSolution, true); // Register TPD service because the provider will try to subscribe to TPD IVsTrackProjectDocuments2 tpd = MockTrackProjectDocumentsProvider.GetTrackProjectDocuments() as IVsTrackProjectDocuments2; serviceProvider.AddService(typeof(SVsTrackProjectDocuments), tpd, true); // Site the package Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK"); // Unsite the package Assert.AreEqual(0, package.SetSite(null), "SetSite(null) did not return S_OK"); }
public static RcsType GetLoadedRcsType() { ThreadHelper.ThrowIfNotOnUIThread(); SccProvider provider = GetCurrentSccProvider(); return(GetRcsTypeFromSccProvider(provider)); }
public static void RegisterPrimarySourceControlProvider(RcsType rcsType) { int hr; Guid packageGuid = new Guid(); Guid sccProviderGuid = new Guid(); SccProvider providerToLoad = SccProvider.Unknown; bool enabled = false; switch (rcsType) { case RcsType.Subversion: { enabled = RegisterSubversionScc(out packageGuid, out sccProviderGuid, out providerToLoad); break; } case RcsType.Git: { enabled = RegisterGitScc(out packageGuid, out sccProviderGuid, out providerToLoad); break; } case RcsType.Mercurial: { enabled = RegisterMercurialScc(out packageGuid, out sccProviderGuid, out providerToLoad); break; } case RcsType.Perforce: { enabled = RegisterPerforceScc(out packageGuid, out sccProviderGuid, out providerToLoad); break; } } if (!enabled) { return; } SccProvider currentSccProvider = GetCurrentSccProvider(); if (providerToLoad == currentSccProvider) { return; } int installed; hr = _VsShell.IsPackageInstalled(ref packageGuid, out installed); Marshal.ThrowExceptionForHR(hr); if (installed == 0) { return; } hr = _VsRegisterScciProvider.RegisterSourceControlProvider(sccProviderGuid); Marshal.ThrowExceptionForHR(hr); }
public void UseToolWindow() { // Create the package SccProvider package = new SccProvider(); // Create a basic service provider OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices(); // Need to mock a service implementing IVsRegisterScciProvider, because the scc provider will register with it IVsRegisterScciProvider registerScciProvider = MockRegisterScciProvider.GetBaseRegisterScciProvider(); serviceProvider.AddService(typeof(IVsRegisterScciProvider), registerScciProvider, true); // Add site support to create and enumerate tool windows BaseMock uiShell = MockUiShellProvider.GetWindowEnumerator0(); serviceProvider.AddService(typeof(SVsUIShell), uiShell, false); // Register solution events because the provider will try to subscribe to them MockSolution solution = new MockSolution(); serviceProvider.AddService(typeof(SVsSolution), solution as IVsSolution, true); // Register TPD service because the provider will try to subscribe to TPD IVsTrackProjectDocuments2 tpd = MockTrackProjectDocumentsProvider.GetTrackProjectDocuments() as IVsTrackProjectDocuments2; serviceProvider.AddService(typeof(SVsTrackProjectDocuments), tpd, true); // Site the package Assert.AreEqual(0, ((IVsPackage)package).SetSite(serviceProvider), "SetSite did not return S_OK"); // Test that toolwindow can be created MethodInfo method = typeof(SccProvider).GetMethod("Exec_icmdViewToolWindow", BindingFlags.NonPublic | BindingFlags.Instance); object result = method.Invoke(package, new object[] { null, null }); // Test that toolwindow toolbar's command can be executed method = typeof(SccProvider).GetMethod("Exec_icmdToolWindowToolbarCommand", BindingFlags.NonPublic | BindingFlags.Instance); result = method.Invoke(package, new object[] { null, null }); // Toggle the toolwindow color back method = typeof(SccProvider).GetMethod("Exec_icmdToolWindowToolbarCommand", BindingFlags.NonPublic | BindingFlags.Instance); result = method.Invoke(package, new object[] { null, null }); // Get the window and test the dispose function SccProviderToolWindow window = (SccProviderToolWindow)package.FindToolWindow(typeof(SccProviderToolWindow), 0, true); method = typeof(SccProviderToolWindow).GetMethod("Dispose", BindingFlags.NonPublic | BindingFlags.Instance); result = method.Invoke(window, new object[] { true }); }
private static RcsType GetRcsTypeFromSccProvider(SccProvider provider) { switch (provider) { case SccProvider.AnkhSvn: case SccProvider.VisualSVN: return(RcsType.Subversion); case SccProvider.VisualStudioToolsForGit: case SccProvider.GitSourceControlProvider: return(RcsType.Git); case SccProvider.HgSccPackage: case SccProvider.VisualHG: return(RcsType.Mercurial); default: return(RcsType.Unknown); } }
private static RcsType GetRcsTypeFromSccProvider(SccProvider provider) { switch (provider) { case SccProvider.AnkhSvn: case SccProvider.VisualSVN: case SccProvider.VisualSVN_2019: return(RcsType.Subversion); case SccProvider.VisualStudioToolsForGit: case SccProvider.EasyGitIntegrationTools: case SccProvider.GitTools2019: return(RcsType.Git); case SccProvider.HgSccPackage: case SccProvider.VSHG: return(RcsType.Mercurial); default: return(RcsType.Unknown); } }
public void IsIVsPackage() { SccProvider package = new SccProvider(); Assert.IsNotNull(package as IVsPackage, "The object does not implement IVsPackage"); }
public void CreateInstance() { SccProvider package = new SccProvider(); }
public static RcsType GetLoadedRcsType() { SccProvider provider = GetCurrentSccProvider(); return(GetRcsTypeFromSccProvider(provider)); }
private static bool RegisterPerforceScc(out Guid packageGuid, out Guid sccProviderGuid, out SccProvider provider) { ThreadHelper.ThrowIfNotOnUIThread(); PerforceSccProvider perforceProvider = GetPerforceSccProvider(); if (perforceProvider == PerforceSccProvider.Default) { perforceProvider = GetDefaultPerforceSccProvider(); } switch (perforceProvider) { case PerforceSccProvider.Disabled: packageGuid = new Guid(); sccProviderGuid = new Guid(); provider = SccProvider.Unknown; return(false); case PerforceSccProvider.P4VS: packageGuid = GetSccInstalledPackageId(P4VSPackageIds); sccProviderGuid = new Guid(P4VSProviderId); provider = SccProvider.P4VS; return(true); case PerforceSccProvider.Default: default: throw new Exception(); } }
/// <returns>false if handling the scc provider is disabled for this Rcs type</returns> private static bool RegisterMercurialScc(out Guid packageGuid, out Guid sccProviderGuid, out SccProvider provider) { ThreadHelper.ThrowIfNotOnUIThread(); MercurialSccProvider mercurialProvider = GetMercurialSccProvider(); if (mercurialProvider == MercurialSccProvider.Default) { mercurialProvider = GetDefaultMercurialSccProvider(); } if (mercurialProvider == MercurialSccProvider.Disabled) { packageGuid = new Guid(); sccProviderGuid = new Guid(); provider = SccProvider.Unknown; return(false); } switch (mercurialProvider) { case MercurialSccProvider.HgSccPackage: { packageGuid = GetSccInstalledPackageId(HgSccPackagePackageIds); sccProviderGuid = new Guid(HgSccPackageSccProviderId); provider = SccProvider.HgSccPackage; return(true); } case MercurialSccProvider.VisualHG: { packageGuid = GetSccInstalledPackageId(VisualHGPackageIds); sccProviderGuid = new Guid(VisualHGSccProviderId); provider = SccProvider.VisualHG; return(true); } case MercurialSccProvider.VSHG: { packageGuid = GetSccInstalledPackageId(VSHGPackageIds); sccProviderGuid = new Guid(VSHGProviderId); provider = SccProvider.VSHG; return(true); } default: throw new Exception(); } }
/// <returns>false if handling the scc provider is disabled for this Rcs type</returns> private static bool RegisterSubversionScc(out Guid packageGuid, out Guid sccProviderGuid, out SccProvider provider) { ThreadHelper.ThrowIfNotOnUIThread(); SubversionSccProvider svnProvider = GetSubversionSccProvider(); if (svnProvider == SubversionSccProvider.Default) { svnProvider = GetDefaultSubversionSccProvider(); } if (svnProvider == SubversionSccProvider.Disabled) { packageGuid = new Guid(); sccProviderGuid = new Guid(); provider = SccProvider.Unknown; return(false); } switch (svnProvider) { case SubversionSccProvider.AnkhSVN: { packageGuid = GetSccInstalledPackageId(AnkhSvnPackageIds); sccProviderGuid = new Guid(AnkhSvnSccProviderId); provider = SccProvider.AnkhSvn; return(true); } case SubversionSccProvider.VisualSVN: { packageGuid = GetSccInstalledPackageId(VisualSvnPackageIds); sccProviderGuid = new Guid(VisualSvnSccProviderId); provider = SccProvider.VisualSVN; return(true); } default: throw new Exception(); } }
/// <returns>false if handling the scc provider is disabled for this Rcs type</returns> private static bool RegisterGitScc(out Guid packageGuid, out Guid sccProviderGuid, out SccProvider provider) { ThreadHelper.ThrowIfNotOnUIThread(); GitSccProvider gitProvider = GetGitSccProvider(); if (gitProvider == GitSccProvider.Default) { gitProvider = GetDefaultGitSccProvider(); } if (gitProvider == GitSccProvider.Disabled) { packageGuid = new Guid(); sccProviderGuid = new Guid(); provider = SccProvider.Unknown; return(false); } switch (gitProvider) { case GitSccProvider.VisualStudioToolsForGit: { packageGuid = GetSccInstalledPackageId(VSToolsForGitPackageIds); sccProviderGuid = new Guid(VSToolsForGitSccProviderId); provider = SccProvider.VisualStudioToolsForGit; return(true); } case GitSccProvider.EasyGitIntegrationTools: { packageGuid = GetSccInstalledPackageId(EasyGitIntegrationToolsPackageIds); sccProviderGuid = new Guid(EasyGitIntegrationToolsSccProviderId); provider = SccProvider.EasyGitIntegrationTools; return(true); } default: throw new Exception(); } }
public static void RegisterPrimarySourceControlProvider(RcsType rcsType) { ThreadHelper.ThrowIfNotOnUIThread(); AppHelper.Output(String.Format("Registering Primary Source Control Provider: {0}", rcsType.ToString())); int hr; Guid packageGuid = new Guid(); Guid sccProviderGuid = new Guid(); SccProvider providerToLoad = SccProvider.Unknown; bool enabled = false; switch (rcsType) { case RcsType.Subversion: { enabled = RegisterSubversionScc(out packageGuid, out sccProviderGuid, out providerToLoad); break; } case RcsType.Git: { enabled = RegisterGitScc(out packageGuid, out sccProviderGuid, out providerToLoad); break; } case RcsType.Mercurial: { enabled = RegisterMercurialScc(out packageGuid, out sccProviderGuid, out providerToLoad); break; } case RcsType.Perforce: { enabled = RegisterPerforceScc(out packageGuid, out sccProviderGuid, out providerToLoad); break; } } AppHelper.Output(String.Format("Provider to Load: {0}, Enabled: {1}", providerToLoad.ToString(), enabled)); if (!enabled) { return; } SccProvider currentSccProvider = GetCurrentSccProvider(); AppHelper.Output(String.Format("Current Provider: {0}", currentSccProvider.ToString())); if (providerToLoad == currentSccProvider) { return; } var installed = IsSccPackageInstalled(packageGuid); AppHelper.Output(String.Format("Provider {0} installed: {1}", providerToLoad.ToString(), installed)); if (!installed) { return; } hr = _VsRegisterScciProvider.RegisterSourceControlProvider(sccProviderGuid); Marshal.ThrowExceptionForHR(hr); AppHelper.Output(String.Format("Provider {0} registered (providerGuid: {1})", providerToLoad.ToString(), sccProviderGuid.ToString())); }
/// <returns>false if handling the scc provider is disabled for this Rcs type</returns> private static bool RegisterGitScc(out Guid packageGuid, out Guid sccProviderGuid, out SccProvider provider) { GitSccProvider gitProvider = GetGitSccProvider(); if (gitProvider == GitSccProvider.Default) { gitProvider = GetDefaultGitSccProvider(); } if (gitProvider == GitSccProvider.Disabled) { packageGuid = new Guid(); sccProviderGuid = new Guid(); provider = SccProvider.Unknown; return(false); } switch (gitProvider) { case GitSccProvider.VisualStudioToolsForGit: { packageGuid = new Guid(VSToolsForGitPackagedId); sccProviderGuid = new Guid(VSToolsForGitSccProviderId); provider = SccProvider.VisualStudioToolsForGit; return(true); } case GitSccProvider.GitSourceControlProvider: { packageGuid = new Guid(GitScpPackagedId); sccProviderGuid = new Guid(GitScpSccProviderId); provider = SccProvider.GitSourceControlProvider; return(true); } default: throw new Exception(); } }
private static RcsType GetRcsTypeFromSccProvider(SccProvider provider) { switch (provider) { case SccProvider.AnkhSvn: case SccProvider.VisualSVN: return RcsType.Subversion; case SccProvider.VisualStudioToolsForGit: case SccProvider.GitSourceControlProvider: return RcsType.Git; case SccProvider.HgSccPackage: case SccProvider.VisualHG: return RcsType.Mercurial; default: return RcsType.Unknown; } }