Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
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
25 changes: 0 additions & 25 deletions src/GitHub.VisualStudio/Base/PackageBase.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/GitHub.VisualStudio/GitHub.VisualStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@
<Compile Include="Menus\AddConnection.cs" />
<Compile Include="Menus\CopyLink.cs" />
<Compile Include="Menus\MenuProvider.cs" />
<Compile Include="Base\PackageBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helpers\Browser.cs" />
<Compile Include="Settings\Constants.cs" />
Expand Down
83 changes: 62 additions & 21 deletions src/GitHub.VisualStudio/GitHubPackage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.ComponentModel.Composition;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using GitHub.Extensions;
using GitHub.Models;
Expand All @@ -12,54 +14,94 @@
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Octokit;
using System.Linq;

namespace GitHub.VisualStudio
{
/// <summary>
/// This is the class that implements the package exposed by this assembly.
///
/// The minimum requirement for a class to be considered a valid package for Visual Studio
/// is to implement the IVsPackage interface and register itself with the shell.
/// This package uses the helper classes defined inside the Managed Package Framework (MPF)
/// to do it: it derives from the Package class that provides the implementation of the
/// IVsPackage interface and uses the registration attributes defined in the framework to
/// register itself and its components with the shell.
/// </summary>
// This attribute tells the PkgDef creation utility (CreatePkgDef.exe) that this class is
// a package.
[PackageRegistration(UseManagedResourcesOnly = true)]
// This attribute is used to register the information needed to show this package
// in the Help/About dialog of Visual Studio.
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid(GuidList.guidGitHubPkgString)]
//[ProvideBindingPath]
[ProvideMenuResource("Menus.ctmenu", 1)]
//[ProvideAutoLoad(UIContextGuids.NoSolution)]
// this is the Git service GUID, so we load whenever it loads
[ProvideAutoLoad("11B8E6D7-C08B-4385-B321-321078CDD1F8")]
[ProvideToolWindow(typeof(GitHubPane), Orientation = ToolWindowOrientation.Right, Style = VsDockStyle.Tabbed, Window = EnvDTE.Constants.vsWindowKindSolutionExplorer)]
[ProvideOptionPage(typeof(OptionsPage), "GitHub for Visual Studio", "General", 0, 0, supportsAutomation: true)]
public class GitHubPackage : PackageBase
public class GitHubPackage : Package
{
// list of assemblies to be loaded from the extension installation path
static readonly string[] ourAssemblies =
{
"GitHub.Api",
"GitHub.App",
"GitHub.CredentialManagement",
"GitHub.Exports",
"GitHub.Exports.Reactive",
"GitHub.Extensions",
"GitHub.Extensions.Reactive",
"GitHub.UI",
"GitHub.UI.Reactive",
"GitHub.VisualStudio",
"GitHub.TeamFoundation",
"GitHub.TeamFoundation.14",
"GitHub.TeamFoundation.15",
"GitHub.VisualStudio.UI",
"System.Windows.Interactivity"
};

readonly IServiceProvider serviceProvider;

public GitHubPackage()
{
serviceProvider = this;
}

public GitHubPackage(IServiceProvider serviceProvider)
: base(serviceProvider)
{
this.serviceProvider = serviceProvider;
}


protected override void Initialize()
{
AppDomain.CurrentDomain.AssemblyResolve += LoadAssemblyFromRunDir;

base.Initialize();

var menus = ServiceProvider.GetExportedValue<IMenuProvider>();
var menus = serviceProvider.GetExportedValue<IMenuProvider>();
foreach (var menu in menus.Menus)
ServiceProvider.AddTopLevelMenuItem(menu.Guid, menu.CmdId, (s, e) => menu.Activate());
serviceProvider.AddTopLevelMenuItem(menu.Guid, menu.CmdId, (s, e) => menu.Activate());

foreach (var menu in menus.DynamicMenus)
ServiceProvider.AddDynamicMenuItem(menu.Guid, menu.CmdId, menu.CanShow, menu.Activate);
serviceProvider.AddDynamicMenuItem(menu.Guid, menu.CmdId, menu.CanShow, menu.Activate);
}

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods")]
static Assembly LoadAssemblyFromRunDir(object sender, ResolveEventArgs e)
{
try
{
var name = new AssemblyName(e.Name);
if (!ourAssemblies.Contains(name.Name))
return null;
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filename = Path.Combine(path, name.Name + ".dll");
if (!File.Exists(filename))
return null;
return Assembly.LoadFrom(filename);
}
catch (Exception ex)
{
var log = string.Format(CultureInfo.CurrentCulture,
"Error occurred loading {0} from {1}.{2}{3}{4}",
e.Name,
Assembly.GetExecutingAssembly().Location,
Environment.NewLine,
ex,
Environment.NewLine);
VsOutputLogger.Write(log);
}
return null;
}
}

Expand All @@ -70,7 +112,6 @@ public class GHClient : GitHubClient
public GHClient(IProgram program)
: base(program.ProductHeader)
{

}
}
}
54 changes: 0 additions & 54 deletions src/common/SharedDictionaryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,11 @@ namespace GitHub.VisualStudio.Helpers
{
public class SharedDictionaryManager : ResourceDictionary
{
static readonly string[] ourAssemblies =
{
"GitHub.Api",
"GitHub.App",
"GitHub.CredentialManagement",
"GitHub.Exports",
"GitHub.Exports.Reactive",
"GitHub.Extensions",
"GitHub.Extensions.Reactive",
"GitHub.UI",
"GitHub.UI.Reactive",
"GitHub.VisualStudio",
"GitHub.TeamFoundation",
"GitHub.TeamFoundation.14",
"GitHub.TeamFoundation.15",
"GitHub.VisualStudio.UI"
};

readonly static int VSVersion;
static SharedDictionaryManager()
{
AppDomain.CurrentDomain.AssemblyResolve += LoadAssemblyFromRunDir;
var asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName.StartsWith("Microsoft.TeamFoundation", StringComparison.Ordinal));
VSVersion = asm?.GetName().Version.Major ?? 14;
}

public SharedDictionaryManager()
{
currentTheme = Colors.DetectTheme();
}

[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods")]
static Assembly LoadAssemblyFromRunDir(object sender, ResolveEventArgs e)
{
try
{
var name = new AssemblyName(e.Name);
if (!ourAssemblies.Contains(name.Name))
return null;
// This assembly should only be loaded in the matching VS version
if (name.Name.StartsWith("GitHub.TeamFoundation", StringComparison.Ordinal))
{
if (!String.Equals("GitHub.TeamFoundation." + VSVersion, name.Name, StringComparison.Ordinal))
return null;
}
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filename = Path.Combine(path, name.Name + ".dll");
if (!File.Exists(filename))
return null;
return Assembly.LoadFrom(filename);
}
catch (Exception ex)
{
var log = string.Format(CultureInfo.CurrentCulture, "Error occurred loading {0} from {1}.{2}{3}{4}", e.Name, Assembly.GetExecutingAssembly().Location, Environment.NewLine, ex, Environment.NewLine);
VsOutputLogger.Write(log);
}
return null;
}

#region ResourceDictionaryImplementation
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
string currentTheme;
Expand Down