internal void EnlistAndCheckout(IVsHierarchy vsHierarchy, string pszProjectMk) { string slnProjectMk; if (!_trueNameMap.TryGetValue(pszProjectMk, out slnProjectMk)) { slnProjectMk = pszProjectMk; } SccSvnOrigin origin; if (!_originMap.TryGetValue(slnProjectMk, out origin)) { return; } if (string.IsNullOrEmpty(origin.SvnUri)) { return; } IVsSolution sol = GetService <IVsSolution>(typeof(SVsSolution)); if (sol == null) { return; } IVsProjectFactory factory; if (!VSErr.Succeeded(sol.GetProjectFactory(0, null, pszProjectMk, out factory))) { return; } IVsSccProjectEnlistmentFactory enlistFactory = factory as IVsSccProjectEnlistmentFactory; if (enlistFactory == null) { return; } string enlistPath, enlistPathUNC; if (!VSErr.Succeeded(enlistFactory.GetDefaultEnlistment(pszProjectMk, out enlistPath, out enlistPathUNC))) { return; } uint flags; int hr; // Website projects return E_NOTIMPL on these methods if (!VSErr.Succeeded(hr = enlistFactory.GetEnlistmentFactoryOptions(out flags))) { if (hr != VSErr.E_NOTIMPL) { return; } flags = 0; } if (!VSErr.Succeeded(hr = enlistFactory.OnBeforeEnlistmentCreate(pszProjectMk, enlistPath, enlistPathUNC))) { return; } Uri projectUri; if (!Uri.TryCreate(origin.SvnUri, UriKind.Absolute, out projectUri)) { Uri relativeUri; if (!Uri.TryCreate(origin.SvnUri, UriKind.Relative, out relativeUri)) { return; } // We have a Uri relative from the solution file if (StatusCache == null) { return; } SvnItem slnDirItem = StatusCache[SolutionDirectory]; if (!slnDirItem.IsVersioned || slnDirItem.Uri == null) { return; } projectUri = new Uri(slnDirItem.Uri, relativeUri); } GetService <IProgressRunner>().RunModal(Resources.CheckingOutProject, delegate(object sender, ProgressWorkerArgs e) { e.Client.CheckOut(projectUri, SvnTools.GetNormalizedFullPath(enlistPathUNC)); }); if (!VSErr.Succeeded(hr = enlistFactory.OnAfterEnlistmentCreate(pszProjectMk, enlistPath, enlistPathUNC))) { return; } SccTranslatePathInfo tpi = new SccTranslatePathInfo(slnProjectMk, enlistPath, enlistPathUNC); _translationMap[tpi.SolutionPath] = tpi; if (tpi.SolutionPath != tpi.EnlistmentUNCPath) { _trueNameMap[tpi.EnlistmentUNCPath] = tpi.SolutionPath; } }
void EnsureEnlistment(string slnProjectName, string pszProjectMk, SccSvnOrigin origin) { SccTranslatePathInfo tpi; if (TryGetTranslation(slnProjectName, out tpi)) { return; // We have existing local data } IVsSolution sol = GetService <IVsSolution>(typeof(SVsSolution)); if (sol == null) { return; } IVsProjectFactory factory; if (!VSErr.Succeeded(sol.GetProjectFactory(0, null, pszProjectMk, out factory))) { return; } IVsSccProjectEnlistmentFactory enlistFactory = factory as IVsSccProjectEnlistmentFactory; if (enlistFactory == null) { return; } string enlistPath, enlistPathUNC; if (!VSErr.Succeeded(enlistFactory.GetDefaultEnlistment(pszProjectMk, out enlistPath, out enlistPathUNC))) { return; } // ### We should now proceed with the editing operations as documented // ### in IVsSccEnlistmentPathTranslation.idl // ### But since we don't have per user settings yet we currently just // ### pass the defaults as that happens to be the same behavior as // ### before if (IsSafeSccPath(pszProjectMk) && !string.IsNullOrEmpty(SolutionSettings.ProjectRoot) /*&& (SvnItem.IsBelowRoot(pszProjectMk, SolutionSettings.ProjectRoot) || string.IsNullOrEmpty(origin.SvnUri))*/ && StatusCache != null && StatusCache[pszProjectMk].Exists) { int pfValidEnlistment; string chosenUNC; // We have a website that has a default location below our project root or without a Svn Uri // At least for now we should default to enlist at that location to make // sure we don't break backwards compatibility string suffix = ".sccEnlistAttemptLocation"; if (VSErr.Succeeded(enlistFactory.ValidateEnlistmentEdit(0, slnProjectName, pszProjectMk + suffix, out chosenUNC, out pfValidEnlistment)) && pfValidEnlistment != 0 && chosenUNC.EndsWith(suffix)) { enlistPath = pszProjectMk; enlistPathUNC = chosenUNC.Substring(0, chosenUNC.Length - suffix.Length); } } string slnProjectMk; // Maybe we already translated the path? if (!_trueNameMap.TryGetValue(pszProjectMk, out slnProjectMk)) { slnProjectMk = pszProjectMk; } tpi = new SccTranslatePathInfo(slnProjectMk, enlistPath, CalculateTruePath(enlistPathUNC)); _translationMap[slnProjectMk] = tpi; if (enlistPathUNC != slnProjectMk) { _trueNameMap[enlistPathUNC] = slnProjectMk; } }