Exemplo n.º 1
0
        private async Task UpdateImplAsync(IRPackageViewModel package)
        {
            await _coreShell.SwitchToMainThreadAsync();

            if (package.IsLoaded)
            {
                try {
                    await _packageManager.UnloadPackageAsync(package.Name);
                } catch (RHostDisconnectedException) {
                    AddErrorMessage(string.Format(CultureInfo.CurrentCulture, Resources.PackageManager_CantUnloadPackageNoRSession, package.Name));
                } catch (RPackageManagerException ex) {
                    AddErrorMessage(ex.Message);
                }
                await ReloadLoadedPackagesAsync();
            }

            if (!package.IsLoaded)
            {
                try {
                    var libPath = package.LibraryPath.ToRPath();
                    try {
                        var packageLockState = await _packageManager.UpdatePackageAsync(package.Name, libPath);

                        if (packageLockState != PackageLockState.Unlocked)
                        {
                            ShowPackageLockedMessage(packageLockState, package.Name);
                        }
                    } catch (RHostDisconnectedException) {
                        AddErrorMessage(string.Format(CultureInfo.CurrentCulture, Resources.PackageManager_CantUpdatePackageNoRSession, package.Name));
                    }
                } catch (RPackageManagerException ex) {
                    AddErrorMessage(ex.Message);
                }
            }

            await ReloadInstalledAndLoadedPackagesAsync();
        }
Exemplo n.º 2
0
        public async Task UpdateAsync(IRPackageViewModel package)
        {
            await _coreShell.SwitchToMainThreadAsync();

            if (!package.IsInstalled || package.IsChanging)
            {
                return;
            }

            var confirmUpdate = _coreShell.ShowMessage(string.Format(CultureInfo.CurrentCulture, Resources.PackageManager_PackageUpdateWarning, package.Name), MessageButtons.YesNo);

            if (confirmUpdate != MessageButtons.Yes)
            {
                return;
            }

            package.IsChanging = true;

            if (_selectedTab == SelectedTab.InstalledPackages || _selectedTab == SelectedTab.LoadedPackages)
            {
                IsLoading = true;
            }

            if (package.IsLoaded)
            {
                try {
                    await _packageManager.UnloadPackageAsync(package.Name);
                } catch (RPackageManagerException ex) {
                    AddErrorMessage(ex.Message);
                }
                await ReloadLoadedPackagesAsync();
            }

            if (!package.IsLoaded)
            {
                try {
                    var libPath          = package.LibraryPath.ToRPath();
                    var packageLockState = _packageManager.GetPackageLockState(package.Name, libPath);
                    if (packageLockState == PackageLockState.Unlocked)
                    {
                        await _packageManager.UninstallPackageAsync(package.Name, libPath);

                        await _packageManager.InstallPackageAsync(package.Name, libPath);
                    }
                    else
                    {
                        ShowPackageLockedMessage(packageLockState, package.Name);
                    }
                } catch (RPackageManagerException ex) {
                    AddErrorMessage(ex.Message);
                }

                await ReloadInstalledAndLoadedPackagesAsync();
            }

            if (_selectedTab == SelectedTab.InstalledPackages)
            {
                ReplaceItems(_installedPackages);
                IsLoading = false;
            }
            else if (_selectedTab == SelectedTab.LoadedPackages)
            {
                ReplaceItems(_loadedPackages);
                IsLoading = false;
            }

            package.IsChanging = false;
        }