public void Initialize()
 {
     this.mockExtension = new Mock<IInstalledExtension>();
     this.extension = mockExtension.Object;
     this.reader = new Mock<ISchemaReader>().Object;
     this.resource = new Mock<ISchemaResource>().Object;
     this.target = new InstalledToolkitInfo(this.extension, this.reader, this.resource);
 }
        private static ISchemaResource AsSchemaResource(IInstalledExtension extension)
        {
            Guard.NotNull(() => extension, extension);

            var content = extension.Content
                .SingleOrDefault(c => c.ContentTypeName.Equals(InstalledToolkitInfo.PatternModelCustomExtensionName, StringComparison.OrdinalIgnoreCase));

            return content != null ? new SchemaResource(extension.InstallPath, content) : null;
        }
예제 #3
0
        public InstalledExtension(IInstalledExtension extension)
        {
            this._installedExtension = extension;

            this.Name = extension.Header.LocalizedName ?? extension.Header.Name;
            this.Id = extension.Header.Identifier;
            this.Description = extension.Header.LocalizedDescription ?? extension.Header.Description;

            this.SmallThumbnailImage = this.MediumThumbnailImage = this.LoadIcon(extension.Header.Icon);
            this.PreviewImage = this.LoadBitmap(extension.Header.PreviewImage);
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InstalledToolkitInfo"/> class.
        /// </summary>
        /// <param name="extension">The extension.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="resource">The resource.</param>
        public InstalledToolkitInfo(IInstalledExtension extension, ISchemaReader reader, ISchemaResource resource)
        {
            Guard.NotNull(() => extension, extension);
            Guard.NotNull(() => reader, reader);
            Guard.NotNull(() => resource, resource);

            this.Extension = extension;
            this.reader = reader;
            this.resource = resource;
            this.PatternIconPath = null;
            this.ToolkitIconPath = GetIconFromExtension(extension);
        }
예제 #5
0
        public void Install(IVsExtensionManager manager, IInstalledExtension currentExtention, IInstallableExtension updatedExtension)
        {
            manager.Disable(currentExtention);
            manager.Uninstall(currentExtention);
            manager.Install(updatedExtension, false);

            var newlyInstalledVersion = manager.GetInstalledExtension(updatedExtension.Header.Identifier);
            if (newlyInstalledVersion.IsNotNull())
            {
                manager.Enable(newlyInstalledVersion);
            }
        }
        private static InstalledToolkitInfo TryCreateRegistration(ISchemaReader reader, IInstalledExtension extension)
        {
            try
            {
                var resource = AsSchemaResource(extension);

                return new InstalledToolkitInfo(extension, reader, resource);
            }
            catch (Exception ex)
            {
                if (Microsoft.VisualStudio.ErrorHandler.IsCriticalException(ex))
                    throw;

                tracer.Warn(Resources.InstalledToolkitAdapter_FailedToCreateRegistration, extension.InstallPath);
                return null;
            }
        }
예제 #7
0
        private static string SetDefaultPath()
        {
            IVsExtensionManager manager = ServiceProvider.GetService(typeof(SVsExtensionManager)) as IVsExtensionManager;

            if (manager == null)
            {
                // This will be used for testing
                packagePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                return(packagePath);
            }

            IInstalledExtension extension = manager.GetInstalledExtension(ServiceFactoryPackageExtensionId);

            Debug.Assert(extension != null, "We could not find " + ServiceFactoryPackageExtensionId + " or package not installed.");

            packagePath = extension.InstallPath;
            return(packagePath);
        }
예제 #8
0
        private static bool CheckForUpdateWithReflection(IInstalledExtension extension, out IInstallableExtension update)
        {
            var _repository = serviceProvider.Get <IVsExtensionRepository>();

            update = null;
            var extensionRepositoryService = serviceProvider.Get <IVsExtensionRepository>();
            var methodInfo = extensionRepositoryService.GetType().GetMethod("GetRepositories");

            if (methodInfo != null)
            {
                IEnumerable <IInstalledExtension> extensionsToCheck = new List <IInstalledExtension> {
                    extension
                };
                var repositories = methodInfo.Invoke(extensionRepositoryService, new object[0]) as IEnumerable <object>;
                if (repositories != null)
                {
                    var onlineExtension = ((from repository in repositories.ToList()
                                            let getUpdateMethod = repository.GetType().GetMethod("GetUpdates")
                                                                  where getUpdateMethod != null
                                                                  let repo = repository
                                                                             select Check.TryCatch <IEnumerable <object>, Exception>(() => getUpdateMethod.Invoke(repo, new object[] { extensionsToCheck }) as IEnumerable <object>)
                                                                             into possibleUpdates
                                                                             where possibleUpdates != null
                                                                             select possibleUpdates.FirstOrDefault())).ToList().OfType <IVsExtension>().FirstOrDefault();
                    {
                        if (onlineExtension != null)
                        {
                            bool isAllreadyInstalled = onlineExtension.GetType().GetProperty("UpdateIsInstalled").GetValue(onlineExtension) as bool? ?? false;
                            if (!isAllreadyInstalled)
                            {
                                var updateEntry = onlineExtension.GetType().GetProperty("UpdateEntry").GetValue(onlineExtension) as IRepositoryEntry;
                                if (updateEntry != null)
                                {
                                    update = _repository.Download(updateEntry);
                                }
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
예제 #9
0
        public static RestartReason CheckForUpdates(string identifier, string updateUrl)
        {
            // Don't check for updates on non-DEPLOY builds; the URLs don't work and it seems
            // undesirable anyway.
#if DEPLOY
            IVsExtensionManager extensionManager   = Package.GetGlobalService(typeof(SVsExtensionManager)) as IVsExtensionManager;
            IInstalledExtension installedExtension = extensionManager.GetInstalledExtension(identifier);
            if (installedExtension == null)
            {
                throw new Exception(String.Format("Unable to find extension: {0}", identifier));
            }

            RepositoryEntry entry = new RepositoryEntry();
            entry.DownloadUrl = updateUrl;

            IVsExtensionRepository repository      = Package.GetGlobalService(typeof(SVsExtensionRepository)) as IVsExtensionRepository;
            IInstallableExtension  latestExtension = repository.Download(entry);

            if (latestExtension.Header.Version > installedExtension.Header.Version)
            {
                RestartReason reason = RestartReason.None;
                reason |= extensionManager.Disable(installedExtension);
                extensionManager.Uninstall(installedExtension);

                try {
                    reason |= extensionManager.Install(latestExtension, /*perMachine*/ false);

                    // Enable the new one.
                    IInstalledExtension latestInstalledExtension = extensionManager.GetInstalledExtension(latestExtension.Header.Identifier);
                    reason |= extensionManager.Enable(latestInstalledExtension);
                    return(reason);
                } catch {
                    // Revert the uninstallation.
                    extensionManager.RevertUninstall(installedExtension);
                    extensionManager.Enable(installedExtension);
                    throw;
                }
            }
#endif
            return(RestartReason.None);
        }
예제 #10
0
        public bool CheckForUpdate(IInstalledExtension extension, out IInstallableExtension update)
        {
            // Find the vsix on the vs gallery
            // IMPORTANT: The .AsEnumerble() call is REQUIRED. Don't remove it or the update service won't work.
            GalleryEntry entry = _repository.CreateQuery<GalleryEntry>(includeTypeInQuery: false, includeSkuInQuery: true, searchSource: "ExtensionManagerUpdate")
                                            .Where(e => e.VsixID == extension.Header.Identifier)
                                            .AsEnumerable()
                                            .FirstOrDefault();

            // If we're running an older version then update
            if (entry != null && entry.NonNullVsixVersion > extension.Header.Version)
            {
                update = _repository.Download(entry);
                return true;
            }
            else
            {
                update = null;
                return false;
            }
        }
        public void InstallPackagesFromVSExtensionRepositoryThrowsExtensionError()
        {
            // Arrange
            var extensionId = "myExtensionId";
            var project     = TestUtils.GetProject("Foo");

            var extensionManagerMock      = new Mock <IVsExtensionManager>();
            IInstalledExtension extension = null;

            extensionManagerMock.Setup(em => em.TryGetInstalledExtension(extensionId, out extension)).Returns(false);

            var installer = new VsPackageInstaller(null, null, null, null, null, null, null, null, extensionManagerMock.Object);
            var packages  = new Dictionary <string, string>();

            packages.Add("A", "1.0.0");

            // Act & Assert
            var exception = Assert.Throws <InvalidOperationException>(() => installer.InstallPackagesFromVSExtensionRepository(extensionId, isPreUnzipped: false, skipAssemblyReferences: false, project: project, packageVersions: packages));

            Assert.Equal(string.Format(NuGet.VisualStudio.Resources.VsResources.PreinstalledPackages_InvalidExtensionId, extensionId), exception.Message);
        }
예제 #12
0
        private string GetCFlowLocation()
        {
            var extensionManager = GetService(typeof(SVsExtensionManager)) as IVsExtensionManager;

            IInstalledExtension self = extensionManager.GetInstalledExtension("CFlow.Morten Engelhardt Olsen.d8f9f542-e05d-4939-a76e-73211eca9cda");

            var cflow = self.Content.Where(e => e.ContentTypeName.Equals("CFlow.Executable")).First();

            var fullPath = Path.Combine(self.InstallPath, cflow.RelativePath);

            if (File.Exists(fullPath))
            {
                Log($"Found CFlow at '{ fullPath }'");
            }
            else
            {
                Log($"Failed to find CFlow at '{ fullPath }'");
            }

            return(fullPath);
        }
예제 #13
0
        public bool CheckForUpdate(IInstalledExtension extension, out IInstallableExtension update)
        {
            // Find the vsix on the vs gallery
            // IMPORTANT: The .AsEnumerble() call is REQUIRED. Don't remove it or the update service won't work.
            GalleryEntry entry = _repository.CreateQuery <GalleryEntry>(includeTypeInQuery: false, includeSkuInQuery: true, searchSource: "ExtensionManagerUpdate")
                                 .Where(e => e.VsixID == extension.Header.Identifier)
                                 .AsEnumerable()
                                 .FirstOrDefault();

            // If we're running an older version then update
            if (entry != null && entry.NonNullVsixVersion > extension.Header.Version)
            {
                update = _repository.Download(entry);
                return(true);
            }
            else
            {
                update = null;
                return(false);
            }
        }
        private static ImageSource GetExtensionIcon(IInstalledExtension extension)
        {
            try
            {
                var prop = extension.GetType().GetProperty("IconFullPath", BindingFlags.Public | BindingFlags.Instance);

                if (prop != null)
                {
                    string icon = prop.GetValue(extension) as string;

                    if (!string.IsNullOrEmpty(icon) && File.Exists(icon))
                    {
                        return(BitmapFrame.Create(new Uri(icon, UriKind.Absolute)));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }

            return(null);
        }
예제 #15
0
            public void Initialize()
            {
                var mock = new Mock <IInstalledExtension>();

                mock.Setup(ext => ext.InstallPath).Returns(@"X:\");
                mock.Setup(ext => ext.Content).Returns(
                    new[]
                {
                    Mocks.Of <IExtensionContent>().First(c => c.ContentTypeName == InstalledToolkitInfo.PatternModelCustomExtensionName && c.RelativePath == @"Foo.patterndefinition" && c.Attributes == new Dictionary <string, string> {
                        { SchemaResource.AssemblyFileProperty, "Test.dll" }
                    }),
                    Mocks.Of <IExtensionContent>().First(c => c.ContentTypeName == "Other" && c.RelativePath == @"Documentation\Other.docx" && c.Attributes == new Dictionary <string, string> {
                        { "IsCustomizable", bool.TrueString }
                    }),
                    Mocks.Of <IExtensionContent>().First(c => c.ContentTypeName == "Other" && c.RelativePath == @"Sample.file" && c.Attributes == new Dictionary <string, string> {
                        { "IsCustomizable", bool.TrueString }
                    }),
                });

                this.extension = mock.Object;
                this.reader    = new Mock <ISchemaReader>().Object;
                this.resource  = new Mock <ISchemaResource>().Object;
                this.target    = new InstalledToolkitInfo(this.extension, this.reader, this.resource);
            }
            public void Initialize()
            {
                var mock = new Mock<IInstalledExtension>();
                mock.Setup(ext => ext.InstallPath).Returns(@"X:\");
                mock.Setup(ext => ext.Content).Returns(
                    new[]
                    {
                        Mocks.Of<IExtensionContent>().First(c => c.ContentTypeName == InstalledToolkitInfo.PatternModelCustomExtensionName && c.RelativePath == @"Foo.patterndefinition" && c.Attributes == new Dictionary<string, string> { { SchemaResource.AssemblyFileProperty, "Test.dll" } }),
                        Mocks.Of<IExtensionContent>().First(c => c.ContentTypeName == "Other" && c.RelativePath == @"Documentation\Other.docx" && c.Attributes == new Dictionary<string, string> { { "IsCustomizable", bool.TrueString } }),
                        Mocks.Of<IExtensionContent>().First(c => c.ContentTypeName == "Other" && c.RelativePath == @"Sample.file" && c.Attributes == new Dictionary<string, string> { { "IsCustomizable", bool.TrueString } }),
                    });

                this.extension = mock.Object;
                this.reader = new Mock<ISchemaReader>().Object;
                this.resource = new Mock<ISchemaResource>().Object;
                this.target = new InstalledToolkitInfo(this.extension, this.reader, this.resource);
            }
예제 #17
0
 private static bool IsToolkit(IInstalledExtension extension)
 {
     return extension.Content.Any(c => c.ContentTypeName.Equals(InstalledToolkitInfo.PatternModelCustomExtensionName, StringComparison.OrdinalIgnoreCase));
 }
        private static string GetGuidancePackageManifest(this IInstalledExtension extension)
        {
            var customExtension = extension.Content.FirstOrDefault(content => content.ContentTypeName == "GuidancePackage");

            return(customExtension != null ? customExtension.RelativePath : null);
        }
예제 #19
0
 private static string GetManifestPath(IInstalledExtension installedExtension)
 => Path.Combine(installedExtension.InstallPath, "extension.vsixmanifest");
 public void InitializeContext()
 {
     this.extension = null;
     this.reader = new Mock<ISchemaReader>().Object;
     this.resource = new Mock<ISchemaResource>().Object;
 }
예제 #21
0
        private static void RevertUninstall(ExtensionManagerService extensionManager, IInstalledExtension oldExtension)
        {
            if (oldExtension == null || extensionManager.IsInstalled(oldExtension))
            {
                return;
            }

            Log($"Reverting uninstall of '{oldExtension.Header.Name}'...");
            extensionManager.RevertUninstall(oldExtension);
        }
예제 #22
0
 public RestartReason Enable(IInstalledExtension extension)
 {
     throw new NotImplementedException();
 }
예제 #23
0
 public void InitializeContext()
 {
     this.extension = null;
     this.reader    = new Mock <ISchemaReader>().Object;
     this.resource  = new Mock <ISchemaResource>().Object;
 }
예제 #24
0
 public bool TryGetInstalledExtension(string identifier, out IInstalledExtension result)
 {
     throw new NotImplementedException();
 }
예제 #25
0
 public void Uninstall(IInstalledExtension extension)
 {
     throw new NotImplementedException();
 }
예제 #26
0
        private OleMenuCommand PrepareMenuItem(IInstalledExtension extension, CommandID commandId)
        {
            OleMenuCommand command = new OleMenuCommand(ToggleAutoUpdating, commandId);
            command.Text = extension.Header.Name;
            command.ParametersDescription = extension.Header.Identifier;
            command.Checked = Settings.IsEnabled(extension.Header.Identifier);
            command.BeforeQueryStatus += (x, y) =>
            {
                OleMenuCommand c = (OleMenuCommand)x;
                c.Enabled = Settings.Enabled;
                c.Checked = Settings.IsEnabled(c.ParametersDescription);
            };

            return command;
        }
예제 #27
0
        private static string GetIconFromExtension(IInstalledExtension extension)
        {
            if (extension.Header == null || string.IsNullOrEmpty(extension.Header.Icon))
            {
                return null;
            }

            // Ensure file exists in VSIX at configured path.
            var fullPath = Path.Combine(extension.InstallPath, extension.Header.Icon);
            return File.Exists(fullPath) ? fullPath : null;
        }
예제 #28
0
 private static bool IsToolkit(IInstalledExtension extension)
 {
     return(extension.Content.Any(c => c.ContentTypeName.Equals(InstalledToolkitInfo.PatternModelCustomExtensionName, StringComparison.OrdinalIgnoreCase)));
 }
예제 #29
0
        protected override void Initialize()
        {
            // determine whether we're running the experimental instance.
            _isExperimental = false;
            string[] args = Environment.GetCommandLineArgs();
            if (args.Length >= 3 && args[2].Equals("exp", StringComparison.OrdinalIgnoreCase))
            {
                _isExperimental = true;
            }

            // get the product version
            IVsExtensionManager manager     = GetService(typeof(SVsExtensionManager)) as IVsExtensionManager;
            IInstalledExtension myExtension = manager.GetInstalledExtension(PackageId);

            if (myExtension != null)
            {
                ProductVersion = myExtension.Header.Version;
            }

            // Initialize NLog
            if (LogManager.Configuration == null)
            {
                string path = Path.Combine(SettingsDirectory, string.Format("{0}_NLog.config", PackageName));
                if (!File.Exists(path))
                {
                    // Get the template from resources and write it to the directory.
                    if (!Directory.Exists(SettingsDirectory))
                    {
                        Directory.CreateDirectory(SettingsDirectory);
                    }
                    File.WriteAllText(path, GetDefaultNLogConfigFileContents());
                }
                if (File.Exists(path))
                {
                    LogManager.Configuration = new XmlLoggingConfiguration(path);
                    // Register for changes to the config file
                    LogManager.ConfigurationChanged += LogManager_ConfigurationChanged;
                }
            }

            // Get the current logger now, since we have the configuration
            _logger = LogManager.GetCurrentClassLogger();
            _logger.Trace("VS arguments: [{0}]", string.Join(",", args));

            var componentManager = _compMgr = (IOleComponentManager)GetService(typeof(SOleComponentManager));

            OLECRINFO[] crinfo = new OLECRINFO[1];
            crinfo[0].cbSize            = (uint)Marshal.SizeOf(typeof(OLECRINFO));
            crinfo[0].grfcrf            = (uint)_OLECRF.olecrfNeedIdleTime;
            crinfo[0].grfcadvf          = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff;
            crinfo[0].uIdleTimeInterval = 0;
            ErrorHandler.ThrowOnFailure(componentManager.FRegisterComponent(this, crinfo, out _componentID));

            _activityLog = GetService(typeof(SVsActivityLog)) as IVsActivityLog;

            base.Initialize();
            Instance = this;

            _packageDTEEvents = ApplicationObject.Events.DTEEvents;
            _packageDTEEvents.OnBeginShutdown += OnBeginShutdown;
        }
예제 #30
0
 public System.Collections.Generic.IEnumerable <IInstalledExtension> GetImmediateDependants(IInstalledExtension extension)
 {
     throw new NotImplementedException();
 }
        private static ImageSource GetExtensionIcon(IInstalledExtension extension)
        {
            try
            {
                var prop = extension.GetType().GetProperty("IconFullPath", BindingFlags.Public | BindingFlags.Instance);

                if (prop != null)
                {
                    string icon = prop.GetValue(extension) as string;

                    if (!string.IsNullOrEmpty(icon) && File.Exists(icon))
                        return BitmapFrame.Create(new Uri(icon, UriKind.Absolute));
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }

            return null;
        }
예제 #32
0
        private static InstalledToolkitInfo TryCreateRegistration(ISchemaReader reader, IInstalledExtension extension)
        {
            try
            {
                var resource = AsSchemaResource(extension);

                return(new InstalledToolkitInfo(extension, reader, resource));
            }
            catch (Exception ex)
            {
                if (Microsoft.VisualStudio.ErrorHandler.IsCriticalException(ex))
                {
                    throw;
                }

                tracer.Warn(Resources.InstalledToolkitAdapter_FailedToCreateRegistration, extension.InstallPath);
                return(null);
            }
        }