Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare improvements [v1.0.3.19] #18

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# shelvesetcomparer
A visual studio extension that allow users to compere contents of two shelvesets.

If the same file path cannot be found, the relative path is checked to allow comparison of shelvesets targeting different branches, e.g. $/BranchA/path/to/file1 with $/BranchB/path/to/file1
Binary file not shown.
113 changes: 113 additions & 0 deletions ShelvesetComparer/Base/TeamExplorerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// <copyright file="TeamExplorerExtensions.cs" company="https://github.com/dprZoft/shelvesetcomparer">
// Copyright https://github.com/hamidshahid/shelvesetcomparer.
// Copyright https://github.com/rajeevboobna/shelvesetcomparer.
// Copyright https://github.com/dprZoft/shelvesetcomparer, 2021.
// All Rights Reserved.
// This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html).
// This is sample code only, do not use in production environments.
// </copyright>

using Microsoft.TeamFoundation.Controls;
using Microsoft.TeamFoundation.VersionControl.Client;
using System;
using System.Linq;

namespace WiredTechSolutions.ShelvesetComparer
{
public static class TeamExplorerExtensions
{
public static Guid ShowNotification(this ITeamExplorer teamExplorer, string message, NotificationType type)
{
if (null != teamExplorer)
{
Guid guid = Guid.NewGuid();
teamExplorer.ShowNotification(message, type, NotificationFlags.None, null, guid);
return guid;
}

return Guid.Empty;
}

public static ITeamExplorerPage NavigateToShelvesetDetails(this ITeamExplorer teamExplorer, Shelveset shelveset)
{
if (null != teamExplorer)
{
return teamExplorer.NavigateToPage(new Guid(TeamExplorerPageIds.ShelvesetDetails), shelveset);
}

return null;
}

public static ITeamExplorerPage NavigateToShelvesetComparer(this ITeamExplorer teamExplorer)
{
try
{
if (teamExplorer != null)
{
ShelvesetComparer.Instance.TraceOutput($"Open TeamExplorer ShelvesetComparer page.");
return teamExplorer.NavigateToPage(new Guid(ShelvesetComparerPage.PageId), null);
}
}
catch (Exception ex)
{
teamExplorer?.ShowNotification(ex.Message, NotificationType.Error);
if (teamExplorer == null)
{
ShelvesetComparer.Instance?.OutputPaneWriteLine($"Exception while opening ShelvesetComparer page and TeamExplorer is null: {ex}");
}
}

return null;
}

public static ShelvesetComparerPage GetCurrentPageAsShelvesetComparerPage(this ITeamExplorer teamExplorer)
{
return teamExplorer.CurrentPageOrUndockedGetExtensibilityService<ShelvesetComparerPage>();
}

public static TService CurrentPageOrUndockedGetExtensibilityService<TService>(this ITeamExplorer teamExplorer) where TService : class
{
return teamExplorer.CurrentPageOrUndockedGetExtensibilityService<TService, TService>();
}

public static TOut CurrentPageOrUndockedGetExtensibilityService<TService, TOut>(this ITeamExplorer teamExplorer) where TOut : class
{
if (teamExplorer == null)
{
return null;
}

var result = teamExplorer?.CurrentPage.GetExtensibilityService<TService, TOut>();
if (result == null)
{
// try undocked pages
if (teamExplorer is ITeamExplorerUndockedPageManager undockedManager)
{
var undocked = undockedManager.UndockedPages;
if (undocked.Any())
{
result = undocked.Select(p => p.GetExtensibilityService<TService, TOut>())
.FirstOrDefault(bp => bp != null);
}
}
}

return result;
}

public static TService GetExtensibilityService<TService>(this ITeamExplorerPage page) where TService : class
{
return GetExtensibilityService<TService, TService>(page);
}

public static TOut GetExtensibilityService<TService, TOut>(this ITeamExplorerPage page) where TOut : class
{
if (page == null)
{
return null;
}

return page.GetExtensibilityService(typeof(TService)) as TOut;
}
}
}
11 changes: 9 additions & 2 deletions ShelvesetComparer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// <copyright file="AssemblyInfo.cs" company="http://shelvesetcomparer.codeplex.com">Copyright http://shelvesetcomparer.codeplex.com. All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.) This is sample code only, do not use in production environments.</copyright>

using System;
using System.Reflection;
using System.Resources;
Expand All @@ -16,5 +17,11 @@
[assembly: CLSCompliant(false)]
[assembly: NeutralResourcesLanguage("en-US")]

[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
#if DEBUG
[assembly: AssemblyConfiguration("DEBUG")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif

[assembly: AssemblyVersion("1.0.3.19")]
[assembly: AssemblyFileVersion("1.0.3.19")]
30 changes: 30 additions & 0 deletions ShelvesetComparer/ServiceProviderExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// <copyright file="ServiceProviderExtension.cs" company="https://github.com/dprZoft/shelvesetcomparer">
// Copyright https://github.com/dprZoft/shelvesetcomparer, 2021. All Rights Reserved.
// This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html).
// This is sample code only, do not use in production environments.
// </copyright>

using System;

namespace WiredTechSolutions.ShelvesetComparer
{
public static class ServiceProviderExtension
{
public static TService GetService<TService>(this IServiceProvider serviceProvider) where TService : class
{
return serviceProvider.GetService<TService, TService>();
}

public static TOut GetService<TService, TOut>(this IServiceProvider serviceProvider) where TOut : class
{
var service = serviceProvider.GetService(typeof(TService));
if (service == null)
{
throw new InvalidOperationException($"Internal error: Service '{typeof(TService).Name}' is not available");
}

return service as TOut
?? throw new InvalidCastException($"Internal error: Cannot cast '{typeof(TService).Name}' to '{typeof(TOut).Name}'");
}
}
}
93 changes: 66 additions & 27 deletions ShelvesetComparer/ShelvesetComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ private ShelvesetComparer(Package package)
{
if (package == null)
{
throw new ArgumentNullException("package");
throw new ArgumentNullException(nameof(package));
}

this.package = package;
#if DEBUG
this.OutputPaneWriteLine("Loading ..");
#endif

OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
OleMenuCommandService commandService = this.ServiceProvider.GetService<IMenuCommandService, OleMenuCommandService>();
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, ShelvesetComparerResuldId);
Expand All @@ -54,6 +57,8 @@ private ShelvesetComparer(Package package)
menuItem = new MenuCommand(this.ShelvesetComparerTeamExplorerViewIdMenuItemCallback, menuCommandID);
commandService.AddCommand(menuItem);
}

TraceOutput("Package initialized.");
}

/// <summary>
Expand Down Expand Up @@ -85,6 +90,9 @@ public static void Initialize(Package package)
Instance = new ShelvesetComparer(package);
}

/// <summary>
/// Open and show ShelvesetComparer result window.
/// </summary>
public void ShowComparisonWindow()
{
ToolWindowPane window = package.FindToolWindow(typeof(ShelvesetComparerToolWindow), 0, true);
Expand All @@ -98,28 +106,22 @@ public void ShowComparisonWindow()
}

/// <summary>
/// Menu item callback for "Team - Results view" item.
///
/// This function is the callback used to execute the command when the menu item is clicked.
/// See the constructor to see how the menu item is associated with this function using
/// OleMenuCommandService service and MenuCommand class.
/// </summary>
/// <param name="sender">Event sender.</param>
/// <param name="e">Event args.</param>
private void ShelvesetComparerResuldIdMenuItemCallback(object sender, EventArgs e)
{
this.ShowToolWindow(sender, e);
}

/// <summary>
/// This function is called when the user clicks the menu item that shows the tool window.
/// </summary>
/// <param name="sender">The sender object</param>
/// <param name="e">Event arguments</param>
private void ShowToolWindow(object sender, EventArgs e)
{
this.ShowComparisonWindow();
}

/// <summary>
/// Menu item callback for "Team - Select view" item.
///
/// This function is the callback used to execute the command when the menu item is clicked.
/// See the constructor to see how the menu item is associated with this function using
/// OleMenuCommandService service and MenuCommand class.
Expand All @@ -128,28 +130,65 @@ private void ShowToolWindow(object sender, EventArgs e)
/// <param name="e">Event args.</param>
private void ShelvesetComparerTeamExplorerViewIdMenuItemCallback(object sender, EventArgs e)
{
try
NavigateToShelvestComparerPage();
}

/// <summary>
/// Open ShelvesetComparer select page in TeamExplorer
/// </summary>
public void NavigateToShelvestComparerPage()
{
var teamExplorer = ServiceProvider.GetService<ITeamExplorer>();
teamExplorer.NavigateToShelvesetComparer();
}

/// <summary>
/// Write trace to output (only if trace is enabled)
/// </summary>
public void TraceOutput(string text)
{
#if TRACE
OutputPaneWriteLine(text);
#endif
}

/// <summary>
/// Write to own output pane in output window with optional DateTime prefix and activate pane afterwards.
/// </summary>
public void OutputPaneWriteLine(string text, bool prefixDateTime = true)
{
OutputPaneWriteLine(this.ServiceProvider, text, prefixDateTime);
}

/// <summary>
/// Write text with optional DateTime prefix to own output pane (create if not existing) and activate pane afterwards.
/// </summary>
public static void OutputPaneWriteLine(IServiceProvider serviceProvider, string text, bool prefixDateTime = true)
{
var outWindow = serviceProvider.GetService<SVsOutputWindow, IVsOutputWindow>();
if (outWindow == null)
{
ITeamExplorer teamExplorer = GetService<ITeamExplorer>();
if (teamExplorer != null)
{
teamExplorer.NavigateToPage(new Guid(ShelvesetComparerPage.PageId), null);
}
return;
}
catch (Exception ex)

// randomly generated GUID to identify the "Shelveset Comparer" output window pane
const string c_ExtensionOutputWindowGuid = "{38BFBA25-8AB3-4F8E-B992-930E403AA281}";
Guid paneGuid = new Guid(c_ExtensionOutputWindowGuid);
IVsOutputWindowPane generalPane = null;
outWindow.GetPane(ref paneGuid, out generalPane);
if (generalPane == null)
{
//this.ShowNotification(ex.Message, NotificationType.Error);
// the pane doesn't already exist
outWindow.CreatePane(ref paneGuid, Resources.ToolWindowTitle, Convert.ToInt32(true), Convert.ToInt32(true));
outWindow.GetPane(ref paneGuid, out generalPane);
}
}

public T GetService<T>()
{
if (this.ServiceProvider != null)
if (prefixDateTime)
{
return (T)this.ServiceProvider.GetService(typeof(T));
text = $"{DateTime.Now:G} {text}";
}

return default(T);
generalPane.OutputString(text + Environment.NewLine);
generalPane.Activate();
}
}
}
16 changes: 14 additions & 2 deletions ShelvesetComparer/ShelvesetComparer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;StubbingWithoutServer</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand All @@ -60,18 +61,23 @@
<Compile Include="Base\TeamExplorerBaseNavigationLink.cs" />
<Compile Include="Base\TeamExplorerBasePage.cs" />
<Compile Include="Base\TeamExplorerBaseSection.cs" />
<Compile Include="Base\TeamExplorerExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="ServiceProviderExtension.cs" />
<Compile Include="ShelvesetComparer.cs" />
<Compile Include="ShelvesetComparerPackage.cs" />
<Compile Include="TeamExplorer\SelectShelvesetSection.cs" />
<Compile Include="TeamExplorer\ShelvesetComparerNavigationLink.cs" />
<Compile Include="TeamExplorer\ShelvesetComparerNavigationLinkItem.cs" />
<Compile Include="TeamExplorer\ShelvesetComparerPage.cs" />
<Compile Include="ViewModel\IPendingChange.cs" />
<Compile Include="ViewModel\PendingChangeFacade.cs" />
<Compile Include="ViewModel\PendingChangeFacadeStub.cs" />
<Compile Include="ViewModel\ShelvesetViewModel.cs" />
<Compile Include="TeamExplorer\ShelvesetsContext.cs" />
<Compile Include="ViewExtensions\UserControlMaxHeightMultiValueConverter.cs" />
Expand All @@ -92,6 +98,12 @@
<MergeWithCTO>true</MergeWithCTO>
<ManifestResourceName>VSPackage</ManifestResourceName>
</EmbeddedResource>
<Content Include="..\LICENSE">
<Link>LICENSE</Link>
</Content>
<None Include="..\README.md">
<Link>README.md</Link>
</None>
<None Include="app.config" />
<None Include="packages.config" />
<Content Include="Resources\License.rtf">
Expand Down
Loading