// FYI: VS SDK API for source control detection and support is really, really horrible. public static async Task<ISccBasicFileSystem> GetFileSystemManipulatorForEnvironment(Project project) { var dte = project.DTE; //if (!project.IsSourceControlled() && !dte.Solution.IsSourceControlled()) //{ // return new NonSccBasicFileSystem(); //} var detectedSccSystem = await DetectSccSystem(project); ISccBasicFileSystem result; switch (detectedSccSystem) { case "tfs": result = new TfsExeWrapper(project.GetDirectory(), dte.GetLogger()); break; case "git": result = new GitExeWrapper(project.GetDirectory(), dte.GetLogger()); break; case "hg": // not yet implemented //result = null; result = new NonSccBasicFileSystem(); break; case "svn": // not yet implemented //result = null; result = new NonSccBasicFileSystem(); break; case null: result = new NonSccBasicFileSystem(); break; default: // not implemented //result = null; result = new NonSccBasicFileSystem(); break; } return result; }
private static async Task<string> DetectSccSystem(Project project) { // Did I mention? VS SDK API for source control detection and support is really, really horrible. var tfs = new TfsExeWrapper(project.GetDirectory(), VsEnvironment.Dte.GetLogger()); if (await tfs.ItemIsUnderSourceControl(project.FullName)) return "tfs"; return //await DetectSccSystem(project.GetDirectory()) //?? await DetectSccSystem(project.DTE.Solution.GetDirectory()); }
private static async Task <string> DetectSccSystem(Project project) { // Did I mention? VS SDK API for source control detection and support is really, really horrible. var tfs = new TfsExeWrapper(project.GetDirectory(), VsEnvironment.Dte.GetLogger()); var projectFilePath = project.FullName; if (string.IsNullOrWhiteSpace(projectFilePath)) { return(null); } if (!projectFilePath.Contains("://") && File.Exists(projectFilePath)) { try { if (await tfs.ItemIsUnderSourceControl(projectFilePath)) { return("tfs"); } } catch { //var logger = VsEnvironment.Dte.GetLogger(); //logger.LogError( System.Diagnostics.Debug.WriteLine( "Something went wrong when checking to see if this file is under source control: " + projectFilePath, "Error"); var fileInfo = new FileInfo(projectFilePath); var sb = new StringBuilder(); sb.AppendLine("Exists: " + fileInfo.Exists); sb.AppendLine("IsReadOnly: " + fileInfo.IsReadOnly); sb.AppendLine("Length: " + fileInfo.Length); sb.AppendLine("Name: " + fileInfo.Name); sb.AppendLine("Attributes: " + fileInfo.Attributes.ToString()); //logger.LogError("File details ...\r\n" + sb.ToString()); System.Diagnostics.Debug.WriteLine(sb.ToString()); //throw; //return "tfs"; // whatever } } var sccdir = project.DTE.Solution.GetDirectory(); if (string.IsNullOrEmpty(sccdir)) { sccdir = project.GetDirectory(); } return(await DetectSccSystem(sccdir)); }
// FYI: VS SDK API for source control detection and support is really, really horrible. public static async Task <ISccBasicFileSystem> GetFileSystemManipulatorForEnvironment(Project project) { var dte = project.DTE; //if (!project.IsSourceControlled() && !dte.Solution.IsSourceControlled()) //{ // return new NonSccBasicFileSystem(); //} var detectedSccSystem = await DetectSccSystem(project); ISccBasicFileSystem result; switch (detectedSccSystem) { case "tfs": result = new TfsExeWrapper(project.GetDirectory(), dte.GetLogger()); break; case "git": result = new GitExeWrapper(project.GetDirectory(), dte.GetLogger()); break; case "hg": // not yet implemented //result = null; result = new NonSccBasicFileSystem(); break; case "svn": // not yet implemented //result = null; result = new NonSccBasicFileSystem(); break; case null: result = new NonSccBasicFileSystem(); break; default: // not implemented //result = null; result = new NonSccBasicFileSystem(); break; } return(result); }
private static async Task<string> DetectSccSystem(Project project) { // Did I mention? VS SDK API for source control detection and support is really, really horrible. var tfs = new TfsExeWrapper(project.GetDirectory(), VsEnvironment.Dte.GetLogger()); var projectFilePath = project.FullName; if (string.IsNullOrWhiteSpace(projectFilePath)) return null; if (!projectFilePath.Contains("://") && File.Exists(projectFilePath)) { try { if (await tfs.ItemIsUnderSourceControl(projectFilePath)) { return "tfs"; } } catch { //var logger = VsEnvironment.Dte.GetLogger(); //logger.LogError( System.Diagnostics.Debug.WriteLine( "Something went wrong when checking to see if this file is under source control: " + projectFilePath, "Error"); var fileInfo = new FileInfo(projectFilePath); var sb = new StringBuilder(); sb.AppendLine("Exists: " + fileInfo.Exists); sb.AppendLine("IsReadOnly: " + fileInfo.IsReadOnly); sb.AppendLine("Length: " + fileInfo.Length); sb.AppendLine("Name: " + fileInfo.Name); sb.AppendLine("Attributes: " + fileInfo.Attributes.ToString()); //logger.LogError("File details ...\r\n" + sb.ToString()); System.Diagnostics.Debug.WriteLine(sb.ToString()); //throw; //return "tfs"; // whatever } } var sccdir = project.DTE.Solution.GetDirectory(); if (string.IsNullOrEmpty(sccdir)) sccdir = project.GetDirectory(); return await DetectSccSystem(sccdir); }