public static void AssemblyInitialize(TestContext testContext) { UIThreadInvoker.Invoke(new Action(() => { // Load the package into the shell. IVsShell shellService = (IVsShell)VsIdeTestHostContext.ServiceProvider.GetService(typeof(SVsShell)); Guid packageGuid = new Guid(PackageGuids.GuidCodeMaidPackageString); IVsPackage package; shellService.IsPackageLoaded(ref packageGuid, out package); if (package == null) { shellService.LoadPackage(ref packageGuid, out package); } Assert.IsTrue(package is CodeMaidPackage); Package = (CodeMaidPackage)package; // Generate an empty solution. const string projectName = "IntegrationTests"; TestUtils.CreateEmptySolution(testContext.TestDir, projectName); Assert.AreEqual(0, TestUtils.ProjectCount()); // Generate an empty project. TestUtils.CreateProjectFromTemplate(projectName, "ConsoleApplication.zip", "CSharp"); Assert.AreEqual(1, TestUtils.ProjectCount()); // Capture the project for later use. Project = Package.IDE.Solution.Projects.Item(1); Assert.IsNotNull(Project); Assert.AreEqual(Project.Name, projectName); })); }
private static IVsPackage TryLoadPackage(IVsShell vsShell, Guid packageGuid) { IVsPackage package; if (vsShell.IsPackageLoaded(ref packageGuid, out package) == VSConstants.S_OK && package != null) return package; if (vsShell.LoadPackage(ref packageGuid, out package) == VSConstants.S_OK) return package; return null; }
public static MarkdownPackage ForceLoadPackage(IVsShell shell) { Guid packageGuid = new Guid(GuidList.guidMarkdownPackagePkgString); IVsPackage package; if (VSConstants.S_OK == shell.IsPackageLoaded(ref packageGuid, out package)) return package as MarkdownPackage; else if (ErrorHandler.Succeeded(shell.LoadPackage(ref packageGuid, out package))) return package as MarkdownPackage; return null; }
public static MarkdownPackage ForceLoadPackage(IVsShell shell) { Guid packageGuid = new Guid(GuidList.guidMarkdownPackagePkgString); IVsPackage package; if (VSConstants.S_OK == shell.IsPackageLoaded(ref packageGuid, out package)) { return(package as MarkdownPackage); } else if (ErrorHandler.Succeeded(shell.LoadPackage(ref packageGuid, out package))) { return(package as MarkdownPackage); } return(null); }
private static IVsPackage TryLoadPackage(IVsShell vsShell, Guid packageGuid) { IVsPackage package; if (vsShell.IsPackageLoaded(ref packageGuid, out package) == VSConstants.S_OK && package != null) { return(package); } if (vsShell.LoadPackage(ref packageGuid, out package) == VSConstants.S_OK) { return(package); } return(null); }
private static void LoadEDMPackage(IVsShell vsShell) { Debug.Assert(vsShell != null, "unexpected null value for vsShell"); IVsPackage package = null; if (vsShell != null) { var packageGuid = PackageConstants.guidEscherPkg; var hr = vsShell.IsPackageLoaded(ref packageGuid, out package); if (NativeMethods.Failed(hr) || package == null) { hr = vsShell.LoadPackage(ref packageGuid, out package); if (NativeMethods.Failed(hr)) { var msg = String.Format(CultureInfo.CurrentCulture, Resources.PackageLoadFailureExceptionMessage, hr); throw new InvalidOperationException(msg); } } } }
public void TestSourcetrailExtensionPackageGetsLoaded() { UIThreadInvoker.Invoke(new Action(() => { // Load the package into the shell. Assert.IsNotNull(VsIdeTestHostContext.ServiceProvider); IVsShell shellService = (IVsShell)VsIdeTestHostContext.ServiceProvider.GetService(typeof(SVsShell)); Guid packageGuid = new Guid(GuidList.guidSourcetrailExtensionPkgString); IVsPackage package; shellService.IsPackageLoaded(ref packageGuid, out package); if (package == null) { shellService.LoadPackage(ref packageGuid, out package); } Assert.IsNotNull(package); Assert.IsTrue(package is SourcetrailExtensionPackage); })); }
/// <summary> /// Adds the specified command filter implementation to the manager, /// with the specified explicit metadata. /// </summary> /// <param name="filter">The command filter instance, which does not need to /// be annotated with the <see cref="CommandFilterAttribute"/> attribute since /// it's provided explicitly.</param> /// <param name="metadata">Explicit metadata to use for the command filter, /// instead of reflecting the <see cref="CommandFilterAttribute"/>.</param> public void AddFilter(ICommandFilter filter, CommandFilterAttribute metadata) { Guard.NotNull(() => filter, filter); Guard.NotNull(() => metadata, metadata); var commandPackageGuid = new Guid(metadata.PackageId); var commandPackage = default(IVsPackage); vsShell.IsPackageLoaded(ref commandPackageGuid, out commandPackage); if (commandPackage == null) { ErrorHandler.ThrowOnFailure(vsShell.LoadPackage(ref commandPackageGuid, out commandPackage)); } var serviceProvider = commandPackage as IServiceProvider; if (serviceProvider == null) { tracer.Error(Strings.CommandManager.CommandPackageNotServiceProvider(commandPackageGuid)); return; } var mcs = serviceProvider.GetService <IMenuCommandService>(); if (mcs == null) { tracer.Error(Strings.CommandManager.NoMenuCommandService(commandPackageGuid)); return; } var groupId = new Guid(metadata.GroupId); var command = mcs.FindCommand(new CommandID(groupId, metadata.CommandId)); if (command == null) { tracer.Error(Strings.CommandManager.CommandNotFound(commandPackageGuid, groupId, metadata.CommandId)); return; } // \o/: for some reason this cast never works on VS2012, even with the proper assembly references :(. // So we resort to dynamic. // var command = as OleMenuCommand; dynamic dynCommand = command.AsDynamicReflection(); try { dynCommand.add_BeforeQueryStatus(new EventHandler((sender, args) => { try { filter.QueryStatus(new OleMenuCommandAdapter((OleMenuCommand)sender)); } catch (Exception e) { tracer.Error(Strings.CommandManager.FilterFailed(filter, e)); } })); } catch (RuntimeBinderException) { // The command may not be an OleMenuCommand and therefore it wouldn't have the BeforeQueryStatus. tracer.Error(Strings.CommandManager.CommandNotOle(commandPackageGuid, metadata.GroupId, metadata.CommandId)); } }