Example #1
0
        private async Task RemovePackageAsync(IEnumerable <string>?assemblyNames)
        {
            try
            {
                IsLoading = true;
                _removeCancellationTokenSource?.Cancel();
                _removeCancellationTokenSource = new CancellationTokenSource();

                var removeTask = Task.Run(async() =>
                {
                    var assemblies = assemblyNames ?? (await _assembliesService.RequireAllAssembliesAsync()).Select(a => a.Name);
                    return(await _localPackagesService.RemovePackageAsync(_selectedPackage !.Value.Id, assemblies));
                }, _removeCancellationTokenSource.Token);

                var successRemove = await DialogHelper.ShowLoadingAsync("Removing", "Please wait while package removing...", removeTask);

                if (successRemove)
                {
                    PackageInstalledOrRemoved?.Invoke();
                    await ChangeSelectedPackageRowAsync(_selectedPackage !.Value);
                }
                else
                {
                    DialogHelper.ShowErrorAlert($"Failed to remove package {_selectedPackage!.Value.Id}");
                }
            }
            finally
            {
                IsLoading = false;
            }
        }
Example #2
0
        private async Task InstallPackageAsync(IEnumerable <string>?assemblyNames)
        {
            try
            {
                IsLoading = true;
                _installCancellationTokenSource?.Cancel();
                _installCancellationTokenSource = new CancellationTokenSource();
                var identity = new PackageIdentity(_selectedPackage !.Value.Id, SelectedVersion !);

                var task = Task.Run(async() =>
                {
                    try
                    {
                        await _remotePackagesService.DownloadPackageAsync(identity, SelectedSource !, false, _installCancellationTokenSource.Token);
                    }
                    catch (TaskCanceledException)
                    {
                        return(true);
                    }

                    var assemblies = assemblyNames ?? (await _assembliesService.RequireAllAssembliesAsync()).Select(a => a.Name);
                    var framework  = _frameworkService.RequireCurrentFramework();
                    return(await _localPackagesService.InstallPackageAsync(identity, assemblies, framework));
                }, _installCancellationTokenSource.Token);

                var successInstall = await DialogHelper.ShowLoadingAsync("Installing", "Please wait while package installing...", task);

                if (successInstall)
                {
                    PackageInstalledOrRemoved?.Invoke();
                    await ChangeSelectedPackageRowAsync(_selectedPackage !.Value);
                }
                else
                {
                    DialogHelper.ShowErrorAlert($"Failed to install package {identity}");
                }
            }
            finally
            {
                IsLoading = false;
            }
        }