예제 #1
0
        /// <summary>Attempts to install <paramref name="plugin" />.</summary>
        /// <param name="plugin">The plugin selected in the UI</param>
        /// <returns></returns>
        public async Task InstallPluginAsync(PluginPackage <PluginMetadata> plugin)
        {
            if (!(plugin is OnlinePluginPackage <PluginMetadata> onlinePlugin))
            {
                LogTo.Error("Install plugin was called with a type that is not OnlinePluginPackage: {V}", plugin.Serialize());
                return;
            }

            bool success = false;

            try
            {
                Status = PluginManagerStatus.Install;

                OperationLogs.Clear();
                PluginMgr.AddLogger(LogOperationOutput);

                using (CancellationTokenSource = new CancellationTokenSource())
                    if ((success = await PluginMgr.InstallPluginAsync(onlinePlugin,
                                                                      onlinePlugin.SelectedVersion,
                                                                      CancellationTokenSource.Token)
                                   .ConfigureAwait(true)) == false)
                    {
                        return;
                    }

                var localPlugin = PluginMgr.AllPlugins.FirstOrDefault(p => p.Package.Id == plugin.Id && p.IsDevelopment == false);

                if (Plugins.Replace(plugin, localPlugin.Package) == false)
                {
                    throw new InvalidOperationException("Failed to replace old OnlinePluginPackage with new LocalPluginPackage in Plugins");
                }

                localPlugin.Package.SetOnlineVersions(onlinePlugin);
            }
            catch (InvalidOperationException ex1) when(ex1.InnerException is NuGetProtocolException)
            {
                success = false;
            }
            catch (InvalidOperationException ex2) when(ex2.InnerException is OperationCanceledException)
            {
                success = true;
            }
            finally
            {
                PluginMgr.RemoveLogger(LogOperationOutput);
                CancellationTokenSource = null;

                Status = success ? PluginManagerStatus.Display : PluginManagerStatus.Install;
            }
        }
예제 #2
0
        /// <summary>Uninstall <paramref name="pluginPackage" /></summary>
        /// <param name="pluginPackage">The plugin to uninstall</param>
        /// <returns></returns>
        private async Task PluginUninstallAsync(LocalPluginPackage <PluginMetadata> pluginPackage)
        {
            bool success = false;

            try
            {
                Status = PluginManagerStatus.Uninstall;

                OperationLogs.Clear();
                PluginMgr.AddLogger(LogOperationOutput);

                using (CancellationTokenSource = new CancellationTokenSource())
                    if ((success = await PluginMgr.UninstallPluginAsync(pluginPackage)
                                   .ConfigureAwait(true)) == false)
                    {
                        return;
                    }

                // Attempt to replace the plugin in the list ; otherwise refresh online plugins
                bool refresh           = true;
                var  onlinePluginsCopy = Plugins;

                if (onlinePluginsCopy != null)
                {
                    pluginPackage = onlinePluginsCopy.FirstOrDefault(p => p.Id == pluginPackage.Id) as LocalPluginPackage <PluginMetadata>;

                    if (pluginPackage != null && pluginPackage.OnlineVersions != null)
                    {
                        onlinePluginsCopy.Replace(pluginPackage, new OnlinePluginPackage <PluginMetadata>(pluginPackage));
                        refresh = false;
                    }
                }

                if (refresh)
                {
                    RefreshPluginsAsync(true).RunAsync();
                }
            }
            catch (InvalidOperationException ex2) when(ex2.InnerException is OperationCanceledException)
            {
                success = true;
            }
            finally
            {
                PluginMgr.RemoveLogger(LogOperationOutput);
                CancellationTokenSource = null;

                Status = success ? PluginManagerStatus.Display : PluginManagerStatus.Uninstall;
            }
        }
예제 #3
0
        /// <summary>Updates <paramref name="plugin" /></summary>
        /// <param name="plugin">The plugin to update</param>
        /// <returns></returns>
        private async Task PluginUpdateAsync(LocalPluginPackage <PluginMetadata> plugin)
        {
            bool success = false;

            try
            {
                Status = PluginManagerStatus.Update;

                OperationLogs.Clear();
                PluginMgr.AddLogger(LogOperationOutput);

                using (CancellationTokenSource = new CancellationTokenSource())
                    if ((success = await PluginMgr.UpdatePluginAsync(plugin,
                                                                     plugin.SelectedVersion,
                                                                     EnablePrerelease,
                                                                     CancellationTokenSource.Token)
                                   .ConfigureAwait(true)) == false)
                    {
                        return;
                    }

                await PluginMgr.StartPlugin(PluginInstances.FirstOrDefault(pi => pi.Package == plugin)).ConfigureAwait(true);
            }
            catch (InvalidOperationException ex1) when(ex1.InnerException is NuGetProtocolException)
            {
                success = false;
            }
            catch (InvalidOperationException ex2) when(ex2.InnerException is OperationCanceledException)
            {
                success = true;
            }
            finally
            {
                PluginMgr.RemoveLogger(LogOperationOutput);
                CancellationTokenSource = null;

                Status = success ? PluginManagerStatus.Display : PluginManagerStatus.Update;
            }
        }