Skip to content

Commit

Permalink
Add "Delete file command", improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Oct 10, 2017
1 parent b2e9f91 commit 13150e2
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 65 deletions.
71 changes: 42 additions & 29 deletions TSVN/Helpers/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,47 +60,60 @@ public static List<string> GetPendingChanges()

public static string GetRepositoryRoot(string path = "")
{
// Try to found the current working folder, either by open document or by open solution
if (string.IsNullOrEmpty(path))
var svnInfo = string.Empty;

try
{
if (!string.IsNullOrEmpty(Dte.Solution.FileName))
// Try to found the current working folder, either by open document or by open solution
if (string.IsNullOrEmpty(path))
{
path = Path.GetDirectoryName(Dte.Solution.FullName);
if (!string.IsNullOrEmpty(Dte.Solution.FileName))
{
path = Path.GetDirectoryName(Dte.Solution.FullName);
}
else if (Dte.ActiveDocument != null)
{
path = Path.GetDirectoryName(Dte.ActiveDocument.FullName);
}
}
else if (Dte.ActiveDocument != null)

var proc = new Process
{
path = Path.GetDirectoryName(Dte.ActiveDocument.FullName);
}
}
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c cd /D \"{path}\" && \"{FileHelper.GetSvnExec()}\" info",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};
proc.Start();

var proc = new Process
{
StartInfo = new ProcessStartInfo
while (!proc.StandardOutput.EndOfStream)
{
FileName = "cmd.exe",
Arguments = $"/c cd /D \"{path}\" && \"{FileHelper.GetSvnExec()}\" info",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
var line = proc.StandardOutput.ReadLine();
LogHelper.Log($"SvnInfo: {line}");
svnInfo += line;
if (line?.StartsWith("Working Copy Root Path:") ?? false)
{
return line.Substring(24);
}
}
};
proc.Start();

while (!proc.StandardOutput.EndOfStream)
{
var line = proc.StandardOutput.ReadLine();
LogHelper.Log($"SvnInfo: {line}");
if (line?.StartsWith("Working Copy Root Path:") ?? false)
while (!proc.StandardError.EndOfStream)
{
return line.Substring(24);
var line = proc.StandardError.ReadLine();
svnInfo += line;
LogHelper.Log($"SvnInfo: {line}");
}
}

while (!proc.StandardError.EndOfStream)
return string.Empty;
}
catch (Exception e)
{
var line = proc.StandardError.ReadLine();
LogHelper.Log($"SvnInfo: {line}");
LogHelper.Log(svnInfo, e);
}

return string.Empty;
Expand Down
98 changes: 89 additions & 9 deletions TSVN/Helpers/LogHelper.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,101 @@
using System;
using Loggly;
using Loggly.Config;
using System;
using System.Diagnostics;
using System.Reflection;

namespace SamirBoulema.TSVN.Helpers
{

public static class LogHelper
{
public static void Initialize(IServiceProvider serviceProvider, string name)
{
Logger.Initialize(serviceProvider, name);
}
private static ILogglyClient _client;
private const string CustomerToken = "4a0f1123-41cd-4f9a-bca0-835914aa51d3";
private const string ApplicationName = "TSVN";

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

public static ILogglyClient GetClient()
{
var config = LogglyConfig.Instance;
config.CustomerToken = CustomerToken;
config.ApplicationName = ApplicationName;

config.Transport.EndpointHostname = "logs-01.loggly.com";
config.Transport.EndpointPort = 443;
config.Transport.LogTransport = LogTransport.Https;

var ct = new ApplicationNameTag();
ct.Formatter = "application-{0}";
config.TagConfig.Tags.Add(ct);

return new LogglyClient();
}

public static void Log(Exception e)
{
if (_client == null)
{
_client = GetClient();
}

var logEvent = new LogglyEvent();
logEvent.Data.Add("version", GetExecutingAssemblyVersion());
logEvent.Data.Add("exception", e);
_client.Log(logEvent);
}

public static void Log(Exception e, object context)
{
if (_client == null)
{
_client = GetClient();
}

var logEvent = new LogglyEvent();
logEvent.Data.Add("version", GetExecutingAssemblyVersion());
logEvent.Data.Add("exception", e);
logEvent.Data.Add("context", context);
_client.Log(logEvent);
}

public static void Log(string message, Exception e)
{
if (_client == null)
{
_client = GetClient();
}

var logEvent = new LogglyEvent();
logEvent.Data.Add("version", GetExecutingAssemblyVersion());
logEvent.Data.Add("message", message);
logEvent.Data.Add("exception", e);
_client.Log(logEvent);
}
}

public static void Log(object log)
{
if (_client == null)
{
_client = GetClient();
}

var logEvent = new LogglyEvent();
logEvent.Data.Add("version", GetExecutingAssemblyVersion());
logEvent.Data.Add("message", log);
_client.Log(logEvent);
}

private static Version GetExecutingAssemblyVersion()
{
var ver = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);

// read what's defined in [assembly: AssemblyFileVersion("1.2.3.4")]
return new Version(ver.ProductMajorPart, ver.ProductMinorPart, ver.ProductBuildPart, ver.ProductPrivatePart);
}
}
}
1 change: 1 addition & 0 deletions TSVN/PkgCmdID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ static class PkgCmdIdList
public const uint DiffPreviousCommand = 0x0610;
public const uint RevertFileCommand = 0x0611;
public const uint AddFileCommand = 0x0612;
public const uint DeleteFileCommand = 0x0613;
};
}
Binary file modified TSVN/Resources/octicons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified TSVN/Resources/octicons.pxd
Binary file not shown.
9 changes: 9 additions & 0 deletions TSVN/TSVN.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
<HintPath>..\packages\EnvDTE.8.0.1\lib\net10\EnvDTE.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Loggly, Version=4.6.1.45, Culture=neutral, PublicKeyToken=aea0e3c965ace843, processorArchitecture=MSIL">
<HintPath>..\packages\loggly-csharp.4.6.1.45\lib\net45\Loggly.dll</HintPath>
</Reference>
<Reference Include="Loggly.Config, Version=4.6.1.45, Culture=neutral, PublicKeyToken=aea0e3c965ace843, processorArchitecture=MSIL">
<HintPath>..\packages\loggly-csharp-config.4.6.1.45\lib\net45\Loggly.Config.dll</HintPath>
</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>
Expand Down Expand Up @@ -157,6 +163,9 @@
<HintPath>..\packages\Microsoft.VisualStudio.Validation.14.1.111\lib\net45\Microsoft.VisualStudio.Validation.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
Expand Down
12 changes: 11 additions & 1 deletion TSVN/TSVN.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@
</Strings>
</Button>

<Button guid="guidTSVNCmdSet" id="deleteFileCommand" priority="0x0600" type="Button">
<Parent guid="guidTSVNCmdSet" id="fourthContextMenuGroup" />
<Icon guid="guidImages" id="delete" />
<Strings>
<ButtonText>Delete</ButtonText>
</Strings>
</Button>

<Button guid="guidTSVNPackageCmdSet" id="cmdidTSVNToolWindowCommand" priority="0x0100" type="Button">
<Parent guid="guidTSVNCmdSet" id="TSVNWindowMenuGroup" />
<Icon guid="guidImages" id="showChanges" />
Expand All @@ -362,7 +370,7 @@

<!--Menu icons-->
<Bitmaps>
<Bitmap guid="guidImages" href="Resources\octicons.png" usedList="showChanges, pull, push, showLog, revert, branch, merge, differences, blame, repo, resolve, sync, commit, disk, switch, cleanup, stash, fetch, add, properties" />
<Bitmap guid="guidImages" href="Resources\octicons.png" usedList="showChanges, pull, push, showLog, revert, branch, merge, differences, blame, repo, resolve, sync, commit, disk, switch, cleanup, stash, fetch, add, properties, delete" />
</Bitmaps>
</Commands>

Expand All @@ -388,6 +396,7 @@
<IDSymbol name="fetch" value="18" />
<IDSymbol name="add" value="19" />
<IDSymbol name="properties" value="20" />
<IDSymbol name="delete" value="21" />
</GuidSymbol>

<GuidSymbol name="guidTSVNPkg" value="{f2e68d5a-c95e-4d53-bbc6-072ff3ed9c53}" />
Expand Down Expand Up @@ -452,6 +461,7 @@
<IDSymbol name="diffPreviousCommand" value="0x0610" />
<IDSymbol name="revertFileCommand" value="0x0611" />
<IDSymbol name="addFileCommand" value="0x0612" />
<IDSymbol name="deleteFileCommand" value="0x0613" />

<!--Windows Menu-->
<IDSymbol name="TSVNWindowMenu" value="0x2000"/>
Expand Down
10 changes: 9 additions & 1 deletion TSVN/TSVNPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override void Initialize()

_tortoiseProc = FileHelper.GetTortoiseSvnProc();

LogHelper.Initialize(this, "TSVN");
Logger.Initialize(this, "TSVN");

// Add our command handlers for menu (commands must exist in the .vsct file)
var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
Expand Down Expand Up @@ -72,6 +72,7 @@ protected override void Initialize()
mcs.AddCommand(CreateCommand(DiffPreviousCommand, PkgCmdIdList.DiffPreviousCommand));
mcs.AddCommand(CreateCommand(RevertFileCommand, PkgCmdIdList.RevertFileCommand));
mcs.AddCommand(CreateCommand(AddFileCommand, PkgCmdIdList.AddFileCommand));
mcs.AddCommand(CreateCommand(DeleteFileCommand, PkgCmdIdList.DeleteFileCommand));

var tsvnMenu = CreateCommand(null, PkgCmdIdList.TSvnMenu);
var tsvnContextMenu = CreateCommand(null, PkgCmdIdList.TSvnContextMenu);
Expand Down Expand Up @@ -311,6 +312,13 @@ private void BlameCommand(object sender, EventArgs e)
if (string.IsNullOrEmpty(_currentFilePath)) return;
CommandHelper.StartProcess(_tortoiseProc, $"/command:blame /path:\"{_currentFilePath}\" /line:{currentLineIndex}");
}

private void DeleteFileCommand(object sender, EventArgs e)
{
_currentFilePath = FileHelper.GetPath();
if (string.IsNullOrEmpty(_currentFilePath)) return;
CommandHelper.StartProcess(_tortoiseProc, $"/command:remove /path:\"{_currentFilePath}\"");
}
#endregion
}
}
3 changes: 3 additions & 0 deletions TSVN/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EnvDTE" version="8.0.1" targetFramework="net461" />
<package id="loggly-csharp" version="4.6.1.45" targetFramework="net461" />
<package id="loggly-csharp-config" version="4.6.1.45" 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" />
Expand All @@ -20,6 +22,7 @@
<package id="Microsoft.VisualStudio.Utilities" version="14.3.25407" targetFramework="net461" />
<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="Newtonsoft.Json" version="6.0.8" targetFramework="net461" />
<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" />
Expand Down
52 changes: 27 additions & 25 deletions TSVN/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
<?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.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>
<License>Resources\License.txt</License>
<GettingStartedGuide>https://github.com/sboulema/TSVN/blob/master/README.md</GettingStartedGuide>
<ReleaseNotes>https://github.com/sboulema/TSVN/releases</ReleaseNotes>
<Icon>Resources\Package.ico</Icon>
<PreviewImage>Resources\tortoisesvn.png</PreviewImage>
<Tags>SVN, Source control, Tortoise, repository</Tags>
</Metadata>
<Installation InstalledByMsi="false">
<InstallationTarget Id="Microsoft.VisualStudio.Pro" Version="[12.0,16.0)" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
<Dependency Id="Microsoft.VisualStudio.MPF.12.0" DisplayName="Visual Studio MPF 12.0" d:Source="Installed" Version="12.0" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0.25904.2,16.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Metadata>
<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>
<License>Resources\License.txt</License>
<GettingStartedGuide>https://github.com/sboulema/TSVN/blob/master/README.md</GettingStartedGuide>
<ReleaseNotes>https://github.com/sboulema/TSVN/releases</ReleaseNotes>
<Icon>Resources\Package.ico</Icon>
<PreviewImage>Resources\tortoisesvn.png</PreviewImage>
<Tags>SVN, Source control, Tortoise, repository</Tags>
</Metadata>
<Installation InstalledByMsi="false">
<InstallationTarget Id="Microsoft.VisualStudio.Pro" Version="[12.0,16.0)" />
<InstallationTarget Version="[12.0,16.0)" Id="Microsoft.VisualStudio.Community" />
<InstallationTarget Version="[12.0,16.0)" Id="Microsoft.VisualStudio.Enterprise" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
<Dependency Id="Microsoft.VisualStudio.MPF.12.0" DisplayName="Visual Studio MPF 12.0" d:Source="Installed" Version="12.0" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0.25904.2,16.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
</PackageManifest>
Loading

0 comments on commit 13150e2

Please sign in to comment.