public InstallDialogViewModel(Dispatcher dispatcher, string configFileName, IDependencies deps, string targetPath, Action <bool> closeDialog)
        {
            _configFileName = configFileName;
            _targetPath     = targetPath;
            _deps           = deps;
            _dispatcher     = dispatcher;
            _closeDialog    = closeDialog;

            List <IProvider> providers = new List <IProvider>();

            foreach (IProvider provider in deps.Providers.OrderBy(x => x.Id))
            {
                ILibraryCatalog catalog = provider.GetCatalog();

                if (catalog == null)
                {
                    continue;
                }

                if (_catalog == null)
                {
                    _activeProvider = provider;
                    _catalog        = catalog;
                }

                providers.Add(provider);
            }

            Providers             = providers;
            InstallPackageCommand = ActionCommand.Create(InstallPackageAsync, CanInstallPackage, false);
            Task t = LoadPackagesAsync();
        }
        public override void Invoke(CancellationToken cancellationToken)
        {
            if (_disabled)
            {
                return;
            }

            try
            {
                var             dependencies = Dependencies.FromConfigFile(_provider.ConfigFilePath);
                IProvider       provider     = dependencies.GetProvider(_provider.InstallationState.ProviderId);
                ILibraryCatalog catalog      = provider?.GetCatalog();

                if (catalog == null)
                {
                    return;
                }

                JSONMember member = _provider.LibraryObject.Children.OfType <JSONMember>().FirstOrDefault(m => m.UnquotedNameText == "id");

                if (member != null)
                {
                    using (ITextEdit edit = TextBuffer.CreateEdit())
                    {
                        edit.Replace(new Span(member.Value.Start, member.Value.Length), "\"" + _updatedLibraryId + "\"");
                        edit.Apply();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogEvent(ex.ToString(), LogLevel.Error);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates file set on the passed in ILibraryInstallationState in case user selected to have all files included
        /// </summary>
        /// <param name="desiredState"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ILibraryOperationResult> UpdateStateAsync(ILibraryInstallationState desiredState, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(LibraryOperationResult.FromCancelled(desiredState));
            }

            string libraryId = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(desiredState.Name, desiredState.Version, Id);

            try
            {
                ILibraryCatalog catalog = GetCatalog();
                ILibrary        library = await catalog.GetLibraryAsync(desiredState.Name, desiredState.Version, cancellationToken).ConfigureAwait(false);

                if (library == null)
                {
                    return(new LibraryOperationResult(desiredState, PredefinedErrors.UnableToResolveSource(desiredState.Name, desiredState.ProviderId)));
                }

                if (desiredState.Files != null && desiredState.Files.Count > 0)
                {
                    IReadOnlyList <string> invalidFiles = library.GetInvalidFiles(desiredState.Files);
                    if (invalidFiles.Any())
                    {
                        IError invalidFilesError = PredefinedErrors.InvalidFilesInLibrary(libraryId, invalidFiles, library.Files.Keys);
                        return(new LibraryOperationResult(desiredState, invalidFilesError));
                    }
                    else
                    {
                        return(LibraryOperationResult.FromSuccess(desiredState));
                    }
                }

                desiredState = new LibraryInstallationState
                {
                    ProviderId                = Id,
                    Name                      = desiredState.Name,
                    Version                   = desiredState.Version,
                    DestinationPath           = desiredState.DestinationPath,
                    Files                     = library.Files.Keys.ToList(),
                    IsUsingDefaultDestination = desiredState.IsUsingDefaultDestination,
                    IsUsingDefaultProvider    = desiredState.IsUsingDefaultProvider
                };
            }
            catch (InvalidLibraryException)
            {
                return(new LibraryOperationResult(desiredState, PredefinedErrors.UnableToResolveSource(libraryId, desiredState.ProviderId)));
            }
            catch (UnauthorizedAccessException)
            {
                return(new LibraryOperationResult(desiredState, PredefinedErrors.PathOutsideWorkingDirectory()));
            }
            catch (Exception ex)
            {
                HostInteraction.Logger.Log(ex.ToString(), LogLevel.Error);
                return(new LibraryOperationResult(desiredState, PredefinedErrors.UnknownException()));
            }

            return(LibraryOperationResult.FromSuccess(desiredState));
        }
        private async Task <List <ISuggestedAction> > GetListOfActionsAsync(ILibraryCatalog catalog, CancellationToken cancellationToken)
        {
            var    list = new List <ISuggestedAction>();
            string latestStableVersion = await catalog.GetLatestVersion(_provider.InstallationState.Name, false, cancellationToken).ConfigureAwait(false);

            string latestStable = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(
                _provider.InstallationState.Name,
                latestStableVersion,
                _provider.InstallationState.ProviderId);

            if (!string.IsNullOrEmpty(latestStableVersion) && latestStableVersion != _provider.InstallationState.Version)
            {
                list.Add(new UpdateSuggestedAction(_provider, latestStable, $"Stable: {latestStable}"));
            }

            string latestPreVersion = await catalog.GetLatestVersion(_provider.InstallationState.Name, true, cancellationToken).ConfigureAwait(false);

            string latestPre = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(_provider.InstallationState.Name,
                                                                                        latestPreVersion,
                                                                                        _provider.InstallationState.ProviderId);

            if (!string.IsNullOrEmpty(latestPreVersion) && latestPreVersion != _provider.InstallationState.Version && latestPre != latestStable)
            {
                list.Add(new UpdateSuggestedAction(_provider, latestPre, $"Pre-release: {latestPre}"));
            }

            return(list);
        }
        private void GetCatalog()
        {
            IProvider       provider = _dependencies.GetProvider("cdnjs");
            ILibraryCatalog catalog  = provider.GetCatalog();

            Assert.IsNotNull(catalog);
        }
        private ISearchService GetTestSearchService(ILibraryCatalog libraryCatalog)
        {
            IProvider testProvider = new Provider(new HostInteraction())
            {
                Catalog = libraryCatalog
            };

            return(new ProviderCatalogSearchService(() => testProvider));
        }
Exemplo n.º 7
0
        public void Setup()
        {
            string projectFolder   = Path.Combine(Path.GetTempPath(), "LibraryManager");
            string cacheFolder     = Environment.ExpandEnvironmentVariables(@"%localappdata%\Microsoft\Library\");
            var    hostInteraction = new HostInteraction(projectFolder, cacheFolder);
            var    dependencies    = new Dependencies(hostInteraction, new CdnjsProviderFactory());

            _provider = dependencies.GetProvider("cdnjs");
            _catalog  = _provider.GetCatalog();
        }
        public void Setup()
        {
            _projectFolder = Path.Combine(Path.GetTempPath(), "LibraryInstaller");

            var hostInteraction = new HostInteraction(_projectFolder, "");
            var dependencies    = new Dependencies(hostInteraction, new FileSystemProvider());

            _provider = dependencies.GetProvider("filesystem");
            _catalog  = _provider.GetCatalog();
        }
Exemplo n.º 9
0
        public void Setup()
        {
            _projectFolder = Path.Combine(Path.GetTempPath(), "LibraryManager");

            var hostInteraction = new HostInteraction(_projectFolder, "");
            var dependencies    = new Dependencies(hostInteraction, new UnpkgProviderFactory());

            _provider = dependencies.GetProvider("unpkg");
            _catalog  = new UnpkgCatalog((UnpkgProvider)_provider);
        }
Exemplo n.º 10
0
        public void Setup()
        {
            _projectFolder = Path.Combine(Path.GetTempPath(), "LibraryManager");

            var hostInteraction = new HostInteraction(_projectFolder, "");
            var dependencies    = new Dependencies(hostInteraction, new FileSystemProviderFactory());

            _provider = dependencies.GetProvider("filesystem");
            _catalog  = new FileSystemCatalog((FileSystemProvider)_provider, true);
        }
Exemplo n.º 11
0
        public void Setup()
        {
            string projectFolder   = Path.Combine(Path.GetTempPath(), "LibraryManager");
            string cacheFolder     = Environment.ExpandEnvironmentVariables(@"%localappdata%\Microsoft\Library\");
            var    hostInteraction = new HostInteraction(projectFolder, cacheFolder);
            var    dependencies    = new Dependencies(hostInteraction, new UnpkgProviderFactory());

            LibraryIdToNameAndVersionConverter.Instance.EnsureInitialized(dependencies);

            _provider = dependencies.GetProvider("unpkg");
            _catalog  = _provider.GetCatalog();
        }
Exemplo n.º 12
0
        public InstallDialogViewModel(ILibraryCommandService libraryCommandService,
                                      string configFileName,
                                      IDependencies deps,
                                      LibraryIdViewModel libraryIdViewModel,
                                      TargetLocationViewModel targetLocationViewModel,
                                      SelectedProviderBinding selectedProviderBinding,
                                      LibraryNameBinding bindLibraryNameToTargetLocation,
                                      string targetPath,
                                      Project project,
                                      string initialProvider)
        {
            _libraryCommandService = libraryCommandService;
            _configFileName        = configFileName;
            _targetPath            = targetPath;
            _deps                    = deps;
            _anyFileSelected         = false;
            _isTreeViewEmpty         = true;
            _selectedProviderBinding = selectedProviderBinding;
            _libraryNameChange       = bindLibraryNameToTargetLocation;
            _project                 = project;
            _taskFactory             = new TaskFactory(TaskScheduler.FromCurrentSynchronizationContext());

            LibraryIdViewModel      = libraryIdViewModel;
            TargetLocationViewModel = targetLocationViewModel;

            var providers = new List <IProvider>();

            foreach (IProvider provider in deps.Providers.OrderBy(x => x.Id))
            {
                ILibraryCatalog catalog = provider.GetCatalog();

                if (catalog == null)
                {
                    continue;
                }

                if (_catalog == null || provider.Id.Equals(initialProvider, StringComparison.Ordinal))
                {
                    SelectedProvider = provider;
                    _selectedProviderBinding.SelectedProvider = SelectedProvider;
                    _catalog = catalog;
                }

                providers.Add(provider);
            }

            Providers             = providers;
            InstallPackageCommand = ActionCommand.Create(InstallPackage, CanInstallPackage, false);
            Task t = LoadPackagesAsync();

            LibraryIdViewModel.PropertyChanged += LibraryIdViewModel_PropertyChanged;
        }
Exemplo n.º 13
0
 private PackageSearchItem(IProvider provider, string name, string alias = null)
 {
     Alias             = alias ?? name;
     _dispatcher       = Dispatcher.CurrentDispatcher;
     CollapsedItemText = name;
     Icon      = WpfUtil.GetIconForImageMoniker(KnownMonikers.Package, 24, 24);
     _infoTask = new Lazy <Task <string> >(async() =>
     {
         ILibraryCatalog catalog = provider.GetCatalog();
         IReadOnlyList <ILibraryGroup> packageGroups = await catalog.SearchAsync(name, 1, CancellationToken.None).ConfigureAwait(false);
         IEnumerable <string> displayInfos           = await packageGroups[0].GetLibraryIdsAsync(CancellationToken.None).ConfigureAwait(false);
         return(displayInfos.FirstOrDefault());
     });
 }
Exemplo n.º 14
0
        public async Task EndToEndTestAsync()
        {
            IProvider       provider = _dependencies.GetProvider("cdnjs");
            ILibraryCatalog catalog  = provider.GetCatalog();

            // Search for libraries to display in search result
            IReadOnlyList <ILibraryGroup> groups = await catalog.SearchAsync("jquery", 4, CancellationToken.None);

            Assert.AreEqual(4, groups.Count);

            // Show details for selected library
            ILibraryGroup group = groups.FirstOrDefault();

            Assert.AreEqual("jquery", group.DisplayName);
            Assert.IsNotNull(group.Description);

            // Get all libraries in group to display version list
            IEnumerable <string> libraryIds = await group.GetLibraryIdsAsync(CancellationToken.None);

            Assert.IsTrue(libraryIds.Count() >= 67);
            Assert.AreEqual("[email protected]", libraryIds.Last(), "Library version mismatch");

            // Get the library to install
            ILibrary library = await catalog.GetLibraryAsync(libraryIds.First(), CancellationToken.None);

            Assert.AreEqual(group.DisplayName, library.Name);

            var desiredState = new LibraryInstallationState
            {
                LibraryId       = "[email protected]",
                ProviderId      = "cdnjs",
                DestinationPath = "lib",
                Files           = new[] { "jquery.js", "jquery.min.js" }
            };

            // Install library
            ILibraryInstallationResult result = await provider.InstallAsync(desiredState, CancellationToken.None).ConfigureAwait(false);

            foreach (string file in desiredState.Files)
            {
                string absolute = Path.Combine(_projectFolder, desiredState.DestinationPath, file);
                Assert.IsTrue(File.Exists(absolute));
            }

            Assert.IsTrue(result.Success);
            Assert.IsFalse(result.Cancelled);
            Assert.AreSame(desiredState, result.InstallationState);
            Assert.AreEqual(0, result.Errors.Count);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Updates file set on the passed in ILibraryInstallationState in case user selected to have all files included
        /// </summary>
        /// <param name="desiredState"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ILibraryInstallationResult> UpdateStateAsync(ILibraryInstallationState desiredState, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(LibraryInstallationResult.FromCancelled(desiredState));
            }

            try
            {
                ILibraryCatalog catalog = GetCatalog();
                ILibrary        library = await catalog.GetLibraryAsync(desiredState.LibraryId, cancellationToken).ConfigureAwait(false);

                if (library == null)
                {
                    throw new InvalidLibraryException(desiredState.LibraryId, Id);
                }

                await HydrateCacheAsync(library, cancellationToken).ConfigureAwait(false);

                if (desiredState.Files != null && desiredState.Files.Count > 0)
                {
                    return(LibraryInstallationResult.FromSuccess(desiredState));
                }

                desiredState = new LibraryInstallationState
                {
                    ProviderId      = Id,
                    LibraryId       = desiredState.LibraryId,
                    DestinationPath = desiredState.DestinationPath,
                    Files           = library.Files.Keys.ToList(),
                };
            }
            catch (Exception ex) when(ex is InvalidLibraryException || ex.InnerException is InvalidLibraryException)
            {
                return(new LibraryInstallationResult(desiredState, PredefinedErrors.UnableToResolveSource(desiredState.LibraryId, desiredState.ProviderId)));
            }
            catch (UnauthorizedAccessException)
            {
                return(new LibraryInstallationResult(desiredState, PredefinedErrors.PathOutsideWorkingDirectory()));
            }
            catch (Exception ex)
            {
                HostInteraction.Logger.Log(ex.ToString(), LogLevel.Error);
                return(new LibraryInstallationResult(desiredState, PredefinedErrors.UnknownException()));
            }

            return(LibraryInstallationResult.FromSuccess(desiredState));
        }
Exemplo n.º 16
0
        private async Task <IEnumerable <string> > GetFilesAsync(ILibraryInstallationState state)
        {
            if (state.Files == null)
            {
                ILibraryCatalog catalog = _dependencies.GetProvider(state.ProviderId)?.GetCatalog();

                if (catalog != null)
                {
                    ILibrary library = await catalog?.GetLibraryAsync(state.LibraryId, CancellationToken.None);

                    return(library?.Files.Keys.ToList());
                }
            }

            return(state.Files.Distinct());
        }
Exemplo n.º 17
0
        public async Task InstallAsync_FullEndToEnd()
        {
            ILibraryCatalog catalog = _provider.GetCatalog();

            // Search for libraries to display in search result
            IReadOnlyList <ILibraryGroup> groups = await catalog.SearchAsync("jquery", 4, CancellationToken.None);

            Assert.IsTrue(groups.Count > 0);

            // Show details for selected library
            ILibraryGroup group = groups.FirstOrDefault();

            Assert.AreEqual("jquery", group.DisplayName);

            // Get all libraries in group to display version list
            IEnumerable <string> libraryVersions = await group.GetLibraryVersions(CancellationToken.None);

            Assert.IsTrue(libraryVersions.Count() >= 0);

            // Get the library to install
            ILibrary library = await catalog.GetLibraryAsync(group.DisplayName, libraryVersions.First(), CancellationToken.None);

            Assert.AreEqual(group.DisplayName, library.Name);

            var desiredState = new LibraryInstallationState
            {
                Name            = "jquery",
                Version         = "3.3.1",
                ProviderId      = "unpkg",
                DestinationPath = "lib",
                Files           = new[] { "dist/jquery.js", "dist/jquery.min.js" }
            };

            // Install library
            ILibraryOperationResult result = await _provider.InstallAsync(desiredState, CancellationToken.None).ConfigureAwait(false);

            foreach (string file in desiredState.Files)
            {
                string absolute = Path.Combine(_projectFolder, desiredState.DestinationPath, file);
                Assert.IsTrue(File.Exists(absolute));
            }

            Assert.IsTrue(result.Success);
            Assert.IsFalse(result.Cancelled);
            Assert.AreSame(desiredState, result.InstallationState);
            Assert.AreEqual(0, result.Errors.Count);
        }
Exemplo n.º 18
0
        private async Task <string> GetLatestVersionAsync(ILibraryInstallationState libraryToUpdate, CancellationToken cancellationToken)
        {
            ILibraryCatalog catalog = ManifestDependencies.GetProvider(libraryToUpdate.ProviderId)?.GetCatalog();

            if (catalog == null)
            {
                throw new InvalidOperationException(PredefinedErrors.LibraryIdIsUndefined().Message);
            }

            try
            {
                return(await catalog.GetLatestVersion(libraryToUpdate.LibraryId, PreRelease.HasValue(), cancellationToken));
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(Resources.UnableToFindLatestVersionForLibrary, libraryToUpdate.LibraryId), ex);
            }
        }
        private async Task <IEnumerable <FileIdentifier> > GetFilesWithVersionsAsync(ILibraryInstallationState state)
        {
            ILibraryCatalog catalog = _dependencies.GetProvider(state.ProviderId)?.GetCatalog();
            ILibrary        library = await catalog?.GetLibraryAsync(state.LibraryId, CancellationToken.None);

            IEnumerable <FileIdentifier> filesWithVersions = new List <FileIdentifier>();

            if (library != null && library.Files != null)
            {
                IEnumerable <string> desiredStateFiles = state?.Files?.Where(f => library.Files.Keys.Contains(f));
                if (desiredStateFiles != null && desiredStateFiles.Any())
                {
                    filesWithVersions = desiredStateFiles.Select(f => new FileIdentifier(Path.Combine(state.DestinationPath, f), library.Version));
                }
            }

            return(filesWithVersions);
        }
        public async Task GetRecommendedSelectedCompletionAsync_SearchTextDoesContainAt_NonMatching_ReturnsFirstItem()
        {
            ILibraryCatalog testCatalog = CreateLibraryCatalogWithUnscopedLibrary();

            var testObj = new LibraryIdViewModel(GetTestSearchService(testCatalog), "test@3");

            CompletionItem[] completions = new[] {
                new CompletionItem {
                    DisplayText = "1.2"
                },
                new CompletionItem {
                    DisplayText = "2.1"
                },
            };

            CompletionItem result = await testObj.GetRecommendedSelectedCompletionAsync(completions, null);

            Assert.AreEqual("1.2", result.DisplayText);
        }
Exemplo n.º 21
0
        private static async Task SearchAsync(IProvider provider, ILibraryCatalog catalog, string searchTerm)
        {
            CancellationToken token = CancellationToken.None;

            IReadOnlyList <ILibraryGroup> absolute = await catalog.SearchAsync(searchTerm, 1, token);

            Assert.AreEqual(1, absolute.Count);
            IEnumerable <string> libraryId = await absolute[0].GetLibraryIdsAsync(token);

            Assert.IsTrue(libraryId.Count() > 0);

            ILibrary library = await catalog.GetLibraryAsync(libraryId.First(), token);

            Assert.IsTrue(library.Files.Count > 0);
            Assert.AreEqual(1, library.Files.Count(f => f.Value));
            Assert.IsNotNull(library.Name);
            Assert.IsNotNull(library.Version);
            Assert.AreEqual(provider.Id, library.ProviderId);
        }
Exemplo n.º 22
0
        private async Task <IEnumerable <FileIdentifier> > GetFilesWithVersionsAsync(ILibraryInstallationState state)
        {
            IEnumerable <FileIdentifier> filesWithVersions = new List <FileIdentifier>();
            ILibraryCatalog catalog = _dependencies.GetProvider(state.ProviderId)?.GetCatalog();

            if (catalog == null)
            {
                return(filesWithVersions);
            }

            ILibraryOperationResult validationResult = await state.IsValidAsync(_dependencies).ConfigureAwait(false);

            if (validationResult.Success)
            {
                IProvider provider = _dependencies.GetProvider(state.ProviderId);

                if (provider != null)
                {
                    ILibraryOperationResult updatedStateResult = await provider.UpdateStateAsync(state, CancellationToken.None).ConfigureAwait(false);

                    if (updatedStateResult.Success)
                    {
                        ILibrary library = await catalog.GetLibraryAsync(state.Name, state.Version, CancellationToken.None).ConfigureAwait(false);

                        if (library != null && library.Files != null)
                        {
                            IEnumerable <string> desiredStateFiles = updatedStateResult.InstallationState.Files;
                            if (desiredStateFiles != null && desiredStateFiles.Any())
                            {
                                filesWithVersions = desiredStateFiles.Select(f => new FileIdentifier(Path.Combine(state.DestinationPath, f), library.Version));
                            }
                        }
                    }
                }
            }
            else
            {
                // Assert disabled due to breaking unit test execution.  See: https://github.com/Microsoft/testfx/issues/561
                //Debug.Assert(validationResult.Success);
            }

            return(filesWithVersions);
        }
        private static async Task SearchAsync(IProvider provider, ILibraryCatalog catalog, string file)
        {
            CancellationToken token = CancellationToken.None;

            IReadOnlyList <ILibraryGroup> absolute = await catalog.SearchAsync(file, 1, token);

            Assert.AreEqual(1, absolute.Count);
            IEnumerable <string> info = await absolute[0].GetLibraryIdsAsync(token);

            Assert.AreEqual(1, info.Count());

            ILibrary library = await catalog.GetLibraryAsync(info.First(), token);

            Assert.AreEqual(1, library.Files.Count);
            Assert.AreEqual(1, library.Files.Count(f => f.Value));
            Assert.AreEqual(file, library.Name);
            Assert.AreEqual("1.0", library.Version);
            Assert.AreEqual(provider.Id, library.ProviderId);
            Assert.AreEqual(Path.GetFileName(file), library.Files.Keys.ElementAt(0));
        }
        private async Task <List <ISuggestedAction> > GetListOfActionsAsync(ILibraryCatalog catalog, CancellationToken cancellationToken)
        {
            var list = new List <ISuggestedAction>();

            string latestStable = await catalog.GetLatestVersion(_provider.InstallationState.LibraryId, false, cancellationToken);

            if (!string.IsNullOrEmpty(latestStable) && latestStable != _provider.InstallationState.LibraryId)
            {
                list.Add(new UpdateSuggestedAction(_provider, latestStable, $"Stable: {latestStable}"));
            }

            string latestPre = await catalog.GetLatestVersion(_provider.InstallationState.LibraryId, true, cancellationToken);

            if (!string.IsNullOrEmpty(latestPre) && latestPre != _provider.InstallationState.LibraryId && latestPre != latestStable)
            {
                list.Add(new UpdateSuggestedAction(_provider, latestPre, $"Pre-release: {latestPre}"));
            }

            return(list);
        }
Exemplo n.º 25
0
        /// <summary>
        ///  Validates <see cref="ILibraryInstallationState"/>
        /// </summary>
        /// <param name="state">The <see cref="ILibraryInstallationState"/> to validate.</param>
        /// <param name="provider">The <see cref="IProvider"/> used to validate <see cref="ILibraryInstallationState"/></param>
        /// <returns><see cref="ILibraryOperationResult"/> with the result of the validation</returns>
        public static async Task <ILibraryOperationResult> IsValidAsync(this ILibraryInstallationState state, IProvider provider)
        {
            if (state == null)
            {
                return(new LibraryOperationResult(state, new[] { PredefinedErrors.UnknownError() }));
            }

            if (provider == null)
            {
                return(new LibraryOperationResult(state, new[] { PredefinedErrors.ProviderUnknown(provider.Id) }));
            }

            if (string.IsNullOrEmpty(state.Name))
            {
                return(new LibraryOperationResult(state, new[] { PredefinedErrors.LibraryIdIsUndefined() }));
            }

            ILibraryCatalog catalog = provider.GetCatalog();

            try
            {
                await catalog.GetLibraryAsync(state.Name, state.Version, CancellationToken.None).ConfigureAwait(false);
            }
            catch
            {
                return(new LibraryOperationResult(state, new[] { PredefinedErrors.UnableToResolveSource(state.Name, state.Version, provider.Id) }));
            }

            if (string.IsNullOrEmpty(state.DestinationPath))
            {
                return(new LibraryOperationResult(state, new[] { PredefinedErrors.PathIsUndefined() }));
            }

            if (state.DestinationPath.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
            {
                return(new LibraryOperationResult(state, new[] { PredefinedErrors.DestinationPathHasInvalidCharacters(state.DestinationPath) }));
            }

            return(LibraryOperationResult.FromSuccess(state));
        }
        public override void Invoke(CancellationToken cancellationToken)
        {
            Telemetry.TrackUserTask("Invoke-UpdateSuggestedAction");

            if (_disabled)
            {
                return;
            }

            try
            {
                IDependencies   dependencies = _provider.DependenciesFactory.FromConfigFile(_provider.ConfigFilePath);
                IProvider       provider     = dependencies.GetProvider(_provider.InstallationState.ProviderId);
                ILibraryCatalog catalog      = provider?.GetCatalog();

                if (catalog == null)
                {
                    return;
                }

                SortedNodeList <Node> children = JsonHelpers.GetChildren(_provider.LibraryObject);
                MemberNode            member   = children.OfType <MemberNode>().FirstOrDefault(m => m.UnquotedNameText == ManifestConstants.Library);

                if (member != null)
                {
                    using (ITextEdit edit = TextBuffer.CreateEdit())
                    {
                        edit.Replace(new Span(member.Value.Start, member.Value.Width), "\"" + _updatedLibraryId + "\"");
                        edit.Apply();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogEvent(ex.ToString(), LogLevel.Error);
                Telemetry.TrackException("UpdateSuggestedActionFailed", ex);
            }
        }
Exemplo n.º 27
0
        public async Task GetRecommendedSelectedCompletionAsync_SearchTextDoesContainAt_ReturnsItemThatStartsWithPrefix()
        {
            ILibraryCatalog testCatalog = CreateLibraryCatalogWithUnscopedLibrary();

            var testObj       = new LibraryIdViewModel(GetTestSearchService(testCatalog), "test@2");
            var completionSet = new CompletionSet
            {
                Start       = 0,
                Length      = 4,
                Completions = new[] {
                    new CompletionItem {
                        DisplayText = "1.2"
                    },
                    new CompletionItem {
                        DisplayText = "2.1"
                    },
                },
            };

            CompletionItem result = await testObj.GetRecommendedSelectedCompletionAsync(completionSet, null);

            Assert.AreEqual("2.1", result.DisplayText);
        }
Exemplo n.º 28
0
        public InstallDialogViewModel(Dispatcher dispatcher, ILibraryCommandService libraryCommandService, string configFileName, IDependencies deps, string targetPath, Action <bool> closeDialog, Project project)
        {
            _libraryCommandService = libraryCommandService;
            _configFileName        = configFileName;
            _targetPath            = targetPath;
            _deps              = deps;
            _dispatcher        = dispatcher;
            _closeDialog       = closeDialog;
            _anyFileSelected   = false;
            _isTreeViewEmpty   = true;
            _libraryNameChange = new BindLibraryNameToTargetLocation();
            _project           = project;

            List <IProvider> providers = new List <IProvider>();

            foreach (IProvider provider in deps.Providers.OrderBy(x => x.Id))
            {
                ILibraryCatalog catalog = provider.GetCatalog();

                if (catalog == null)
                {
                    continue;
                }

                if (_catalog == null)
                {
                    _activeProvider = provider;
                    _catalog        = catalog;
                }

                providers.Add(provider);
            }

            Providers             = providers;
            InstallPackageCommand = ActionCommand.Create(InstallPackage, CanInstallPackage, false);
            Task t = LoadPackagesAsync();
        }
Exemplo n.º 29
0
 public override ILibraryCatalog GetCatalog()
 {
     return(_catalog ?? (_catalog = new JsDelivrCatalog(Id, LibraryNamingScheme, HostInteraction.Logger, WebRequestHandler.Instance, _infoFactory, _packageSearch)));
 }
Exemplo n.º 30
0
 public override ILibraryCatalog GetCatalog()
 {
     // TODO: sort out the WebRequestHandler dependency
     return(_catalog ?? (_catalog = new UnpkgCatalog(Id, LibraryNamingScheme, HostInteraction.Logger, WebRequestHandler.Instance, _infoFactory, _packageSearch)));
 }