コード例 #1
0
        private RestartReason InstallExtension(ExtensionEntry extension, IVsExtensionRepository repository, IVsExtensionManager manager)
        {
            GalleryEntry entry = null;

            OnUpdate(string.Format("{0} ({1})", _settings.ResourceProvider.InstallingExtension, extension.Name));
            var ret = RestartReason.None;

            try
            {
                _logger.Log($"{Environment.NewLine}{extension.Name}");
                _logger.Log("  " + _settings.ResourceProvider.Verifying, false);

                entry = repository.GetVSGalleryExtensions <GalleryEntry>(new List <string> {
                    extension.Id
                }, 1033, false)?.FirstOrDefault();

                if (entry != null)
                {
                    _logger.Log(_settings.ResourceProvider.Ok); // Marketplace ok
#if DEBUG || true
                    var extensionsByAuthor = manager.GetInstalledExtensions().GroupBy(x => x.Header.Author).Select(y => new { y.Key, items = y }).ToArray();
#endif
                    var installed = manager.GetInstalledExtensions().SingleOrDefault(n => n.Header.Identifier == extension.Id);
                    _logger.Log("  " + _settings.ResourceProvider.Verifying, false);
                    IInstallableExtension installable = null;

                    if (installed != null)
                    {
                        if (NewerVersionExists(installed, repository, entry))
                        {
                            installed = null;
                        }
                    }
                    _logger.Log("  " + _settings.ResourceProvider.Ok);
                    if (installed == null)
                    {
                        _logger.Log("  " + _settings.ResourceProvider.Downloading, false);
                        installable = repository.Download(entry);
                        _logger.Log(_settings.ResourceProvider.Ok); // Download ok
                    }

                    if (installable == null)
                    {
                        _logger.Log(" nothing to do");
                    }
                    else
                    {
                        _logger.Log("  " + _settings.ResourceProvider.Installing, false);

                        ret = manager.Install(installable, false);
                        _logger.Log(_settings.ResourceProvider.Ok); // Install ok
                    }

                    Telemetry.Install(extension.Id, true);
                }
                else
                {
                    _logger.Log(_settings.ResourceProvider.Failed); // Markedplace failed
                }
            }
            catch (Exception e)
            {
                _logger.Log(_settings.ResourceProvider.Failed);
                _logger.Log("Failed to install package: " + e.Message);
                _log.Error(e);
                Telemetry.Install(extension.Id, false);
            }
            finally
            {
                if (entry != null)
                {
                    Store.MarkInstalled(extension);
                }
            }

            return(ret);
        }
コード例 #2
0
        //Checks the version of the extension
        private bool NewerVersionExists(IInstalledExtension extension, IVsExtensionRepository repository, GalleryEntry entry)
        {
            var version       = extension.Header.Version;
            var strNewVersion = repository.GetCurrentExtensionVersions("ExtensionManagerQuery", new List <string>()
            {
                extension.Header.Identifier
            }, 1033).Single();
            var newVersion = Version.Parse(strNewVersion);

            if (newVersion > version)
            {
                return(true);
            }

            return(false);
        }