Skip to content

Commit

Permalink
Add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed May 18, 2017
1 parent 6ee84a5 commit b2e9f91
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 47 deletions.
9 changes: 8 additions & 1 deletion TSVN/Helpers/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,23 @@ public static string GetRepositoryRoot(string path = "")
while (!proc.StandardOutput.EndOfStream)
{
var line = proc.StandardOutput.ReadLine();
LogHelper.Log($"SvnInfo: {line}");
if (line?.StartsWith("Working Copy Root Path:") ?? false)
{
return line.Substring(24);
}
}

while (!proc.StandardError.EndOfStream)
{
var line = proc.StandardError.ReadLine();
LogHelper.Log($"SvnInfo: {line}");
}

return string.Empty;
}

private static void StartProcess(string application, string args)
public static void StartProcess(string application, string args)
{
try
{
Expand Down
24 changes: 19 additions & 5 deletions TSVN/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,38 @@ public static class FileHelper

public static string GetTortoiseSvnProc()
{
return (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\TortoiseSVN", "ProcPath", @"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe");
var path = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\TortoiseSVN", "ProcPath", @"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe");
LogHelper.Log($"TortoiseSvnProc: {path}");
return path;
}

public static string GetSvnExec()
{
return GetTortoiseSvnProc().Replace("TortoiseProc.exe", "svn.exe");
var path = GetTortoiseSvnProc().Replace("TortoiseProc.exe", "svn.exe");
LogHelper.Log($"SvnExec: {path}, exists: {File.Exists(path)}");
return path;
}

public static void SaveAllFiles()
{
Dte.ExecuteCommand("File.SaveAll");
}

/// <summary>
/// Get the path of the file on which to act upon.
/// This can be different depending on where the TSVN context menu was used
/// </summary>
/// <returns>File path</returns>
public static string GetPath()
{
return Dte.SelectedItems.Item(1).ProjectItem == null
? Path.GetDirectoryName(Dte.SelectedItems.Item(1).Project.FullName)
: Dte.SelectedItems.Item(1).ProjectItem.FileNames[0];
if (Dte.SelectedItems.Item(1).ProjectItem != null)
{
// Context menu in the Solution Explorer
return Dte.SelectedItems.Item(1).ProjectItem.FileNames[0];
}

// Context menu in the Code Editor
return Path.GetDirectoryName(Dte.SelectedItems.Item(1).Project.FullName);
}
}
}
21 changes: 21 additions & 0 deletions TSVN/Helpers/LogHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace SamirBoulema.TSVN.Helpers
{

public static class LogHelper
{
public static void Initialize(IServiceProvider serviceProvider, string name)
{
Logger.Initialize(serviceProvider, name);
}

public static void Log(string message)
{
#if DEBUG
Logger.Log(message);
#endif
}
}

}
7 changes: 7 additions & 0 deletions TSVN/TSVN.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<HintPath>..\packages\EnvDTE.8.0.1\lib\net10\EnvDTE.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.ApplicationInsights, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.ApplicationInsights.2.0.1\lib\net46\Microsoft.ApplicationInsights.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.CoreUtility, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.VisualStudio.CoreUtility.14.3.25407\lib\net45\Microsoft.VisualStudio.CoreUtility.dll</HintPath>
Expand Down Expand Up @@ -172,12 +175,16 @@
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="UIAutomationTypes" />
<Reference Include="VsixLogger, Version=1.1.44.0, Culture=neutral, PublicKeyToken=29d32695dc822296, processorArchitecture=MSIL">
<HintPath>..\packages\VsixLogger.1.1.44.0\lib\net45\VsixLogger.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Guids.cs" />
<Compile Include="Helpers\CommandHelper.cs" />
<Compile Include="Helpers\FileHelper.cs" />
<Compile Include="Helpers\LogHelper.cs" />
<Compile Include="Models\TSVNTreeViewItem.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down
66 changes: 28 additions & 38 deletions TSVN/TSVNPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ protected override void Initialize()

_tortoiseProc = FileHelper.GetTortoiseSvnProc();

LogHelper.Initialize(this, "TSVN");

// Add our command handlers for menu (commands must exist in the .vsct file)
var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (null == mcs) return;
Expand Down Expand Up @@ -91,18 +93,6 @@ protected override void Initialize()
}
#endregion

private static void StartProcess(string application, string args)
{
try
{
Process.Start(application, args);
}
catch (Exception)
{
MessageBox.Show("TortoiseSVN not found. Did you install TortoiseSVN?", "TortoiseSVN not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private static OleMenuCommand CreateCommand(EventHandler handler, uint commandId)
{
var menuCommandId = new CommandID(GuidList.guidTSVNCmdSet, (int)commandId);
Expand All @@ -120,83 +110,83 @@ private void ShowChangesCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
StartProcess(_tortoiseProc, $"/command:repostatus /path:\"{_solutionDir}\" /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:repostatus /path:\"{_solutionDir}\" /closeonend:0");
}

private void UpdateCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
Dte.ExecuteCommand("File.SaveAll", string.Empty);
StartProcess(_tortoiseProc, $"/command:update /path:\"{_solutionDir}\" /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:update /path:\"{_solutionDir}\" /closeonend:0");
}

private void UpdateFileCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
Dte.ActiveDocument?.Save();
StartProcess(_tortoiseProc, $"/command:update /path:\"{_currentFilePath}\" /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:update /path:\"{_currentFilePath}\" /closeonend:0");
}

private void UpdateToRevisionCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
Dte.ExecuteCommand("File.SaveAll", string.Empty);
StartProcess(_tortoiseProc, $"/command:update /path:\"{_solutionDir}\" /rev /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:update /path:\"{_solutionDir}\" /rev /closeonend:0");
}

private void UpdateToRevisionFileCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
Dte.ActiveDocument?.Save();
StartProcess(_tortoiseProc, $"/command:update /path:\"{_currentFilePath}\" /rev /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:update /path:\"{_currentFilePath}\" /rev /closeonend:0");
}

private void PropertiesCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
StartProcess(_tortoiseProc, $"/command:properties /path:\"{_currentFilePath}\" /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:properties /path:\"{_currentFilePath}\" /closeonend:0");
}

private void CommitCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
Dte.ExecuteCommand("File.SaveAll", string.Empty);
StartProcess(_tortoiseProc, $"/command:commit /path:\"{_solutionDir}\" /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:commit /path:\"{_solutionDir}\" /closeonend:0");
}

private void CommitFileCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
Dte.ActiveDocument?.Save();
StartProcess(_tortoiseProc, $"/command:commit /path:\"{_currentFilePath}\" /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:commit /path:\"{_currentFilePath}\" /closeonend:0");
}

private void ShowLogCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
StartProcess(_tortoiseProc, $"/command:log /path:\"{_solutionDir}\" /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:log /path:\"{_solutionDir}\" /closeonend:0");
}

private void ShowLogFileCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
StartProcess(_tortoiseProc, $"/command:log /path:\"{_currentFilePath}\" /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:log /path:\"{_currentFilePath}\" /closeonend:0");
}

private void CreatePatchCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
StartProcess(_tortoiseProc, $"/command:createpatch /path:\"{_solutionDir}\" /noview /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:createpatch /path:\"{_solutionDir}\" /noview /closeonend:0");
}

private void ApplyPatchCommand(object sender, EventArgs e)
Expand All @@ -213,29 +203,29 @@ private void ApplyPatchCommand(object sender, EventArgs e)
var result = openFileDialog.ShowDialog();
if (result != DialogResult.OK) return;

StartProcess("TortoiseMerge.exe", $"/diff:\"{openFileDialog.FileName}\" /patchpath:\"{_solutionDir}\"");
CommandHelper.StartProcess("TortoiseMerge.exe", $"/diff:\"{openFileDialog.FileName}\" /patchpath:\"{_solutionDir}\"");
}

private void RevertCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
StartProcess(_tortoiseProc, $"/command:revert /path:\"{_solutionDir}\" /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:revert /path:\"{_solutionDir}\" /closeonend:0");
}

private void RevertFileCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
StartProcess(_tortoiseProc, $"/command:revert /path:\"{_currentFilePath}\" /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:revert /path:\"{_currentFilePath}\" /closeonend:0");
}

private void AddFileCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
Dte.ActiveDocument?.Save();
StartProcess(_tortoiseProc, $"/command:add /path:\"{_currentFilePath}\" /closeonend:0");
CommandHelper.StartProcess(_tortoiseProc, $"/command:add /path:\"{_currentFilePath}\" /closeonend:0");
}

private void DiskBrowserCommand(object sender, EventArgs e)
Expand All @@ -248,78 +238,78 @@ private void DiskBrowserFileCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
StartProcess("explorer.exe", _currentFilePath);
CommandHelper.StartProcess("explorer.exe", _currentFilePath);
}

private void RepoBrowserCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
StartProcess(_tortoiseProc, $"/command:repobrowser /path:\"{_solutionDir}\"");
CommandHelper.StartProcess(_tortoiseProc, $"/command:repobrowser /path:\"{_solutionDir}\"");
}

private void RepoBrowserFileCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
StartProcess(_tortoiseProc, $"/command:repobrowser /path:\"{_currentFilePath}\"");
CommandHelper.StartProcess(_tortoiseProc, $"/command:repobrowser /path:\"{_currentFilePath}\"");
}

private void BranchCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
StartProcess(_tortoiseProc, $"/command:copy /path:\"{_solutionDir}\"");
CommandHelper.StartProcess(_tortoiseProc, $"/command:copy /path:\"{_solutionDir}\"");
}

private void SwitchCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
StartProcess(_tortoiseProc, $"/command:switch /path:\"{_solutionDir}\"");
CommandHelper.StartProcess(_tortoiseProc, $"/command:switch /path:\"{_solutionDir}\"");
}

private void MergeCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
StartProcess(_tortoiseProc, $"/command:merge /path:\"{_solutionDir}\"");
CommandHelper.StartProcess(_tortoiseProc, $"/command:merge /path:\"{_solutionDir}\"");
}

private void MergeFileCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
StartProcess(_tortoiseProc, $"/command:merge /path:\"{_currentFilePath}\"");
CommandHelper.StartProcess(_tortoiseProc, $"/command:merge /path:\"{_currentFilePath}\"");
}

private void CleanupCommand(object sender, EventArgs e)
{
_solutionDir = CommandHelper.GetRepositoryRoot();
if (string.IsNullOrEmpty(_solutionDir)) return;
StartProcess(_tortoiseProc, $"/command:cleanup /path:\"{_solutionDir}\"");
CommandHelper.StartProcess(_tortoiseProc, $"/command:cleanup /path:\"{_solutionDir}\"");
}

private void DifferencesCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
StartProcess(_tortoiseProc, $"/command:diff /path:\"{_currentFilePath}\"");
CommandHelper.StartProcess(_tortoiseProc, $"/command:diff /path:\"{_currentFilePath}\"");
}

private void DiffPreviousCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
StartProcess(_tortoiseProc, $"/command:prevdiff /path:\"{_currentFilePath}\"");
CommandHelper.StartProcess(_tortoiseProc, $"/command:prevdiff /path:\"{_currentFilePath}\"");
}

private void BlameCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
var currentLineIndex = ((TextDocument) Dte.ActiveDocument?.Object(string.Empty))?.Selection.CurrentLine ?? 0;
if (string.IsNullOrEmpty(_currentFilePath)) return;
StartProcess(_tortoiseProc, $"/command:blame /path:\"{_currentFilePath}\" /line:{currentLineIndex}");
CommandHelper.StartProcess(_tortoiseProc, $"/command:blame /path:\"{_currentFilePath}\" /line:{currentLineIndex}");
}
#endregion
}
Expand Down
2 changes: 2 additions & 0 deletions TSVN/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EnvDTE" version="8.0.1" targetFramework="net461" />
<package id="Microsoft.ApplicationInsights" version="2.0.1" targetFramework="net461" />
<package id="Microsoft.VisualStudio.CoreUtility" version="14.3.25407" targetFramework="net461" />
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6070" targetFramework="net45" />
<package id="Microsoft.VisualStudio.Shell.Immutable.10.0" version="10.0.30319" targetFramework="net461" />
Expand All @@ -20,6 +21,7 @@
<package id="Microsoft.VisualStudio.Validation" version="14.1.111" targetFramework="net461" />
<package id="Microsoft.VSSDK.BuildTools" version="15.0.26201" targetFramework="net461" developmentDependency="true" />
<package id="stdole" version="7.0.3301" targetFramework="net461" />
<package id="VsixLogger" version="1.1.44.0" targetFramework="net461" />
<package id="VSSDK.DTE" version="7.0.4" targetFramework="net45" />
<package id="VSSDK.GraphModel" version="12.0.4" targetFramework="net461" />
<package id="VSSDK.IDE" version="7.0.4" targetFramework="net45" />
Expand Down
2 changes: 1 addition & 1 deletion TSVN/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="07fd7462-cd4b-433b-9ab5-8ad3ad87bc65" Version="3.7" Language="en-US" Publisher="Samir L. Boulema" />
<Identity Id="07fd7462-cd4b-433b-9ab5-8ad3ad87bc65" Version="3.8" Language="en-US" Publisher="Samir L. Boulema" />
<DisplayName>TSVN</DisplayName>
<Description>Control TortoiseSVN from within Visual Studio</Description>
<MoreInfo>https://visualstudiogallery.msdn.microsoft.com/64bfec35-0ac1-48bc-b9d0-921ecb803e53</MoreInfo>
Expand Down
Loading

0 comments on commit b2e9f91

Please sign in to comment.