[3547] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3547] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Linq;
|
---|
| 26 | using HeuristicLab.PluginInfrastructure.Manager;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.PluginInfrastructure.Advanced {
|
---|
| 29 | internal partial class BasicUpdateView : InstallationManagerControl {
|
---|
| 30 | private BackgroundWorker updatePluginsBackgroundWorker;
|
---|
| 31 | private const string CheckingPluginsMessage = "Checking for updated plugins...";
|
---|
| 32 | private const string NoUpdatesAvailableMessage = "No updates available.";
|
---|
| 33 |
|
---|
| 34 | private PluginManager pluginManager;
|
---|
| 35 | public PluginManager PluginManager {
|
---|
| 36 | get { return pluginManager; }
|
---|
| 37 | set { pluginManager = value; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | private InstallationManager installationManager;
|
---|
| 41 | public InstallationManager InstallationManager {
|
---|
| 42 | get { return installationManager; }
|
---|
| 43 | set { installationManager = value; }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | public BasicUpdateView() {
|
---|
| 47 | InitializeComponent();
|
---|
| 48 | updatePluginsBackgroundWorker = new BackgroundWorker();
|
---|
| 49 | updatePluginsBackgroundWorker.DoWork += new DoWorkEventHandler(updatePluginsBackgroundWorker_DoWork);
|
---|
| 50 | updatePluginsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(updatePluginsBackgroundWorker_RunWorkerCompleted);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | #region event handlers for update plugins backgroundworker
|
---|
| 54 | void updatePluginsBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
| 55 | if (e.Error != null) {
|
---|
| 56 | StatusView.ShowError("Connection Error",
|
---|
| 57 | "There was an error while connecting to the server." + Environment.NewLine +
|
---|
| 58 | "Please check your connection settings and user credentials.");
|
---|
| 59 | } else if (e.Cancelled) {
|
---|
| 60 | StatusView.ShowMessage(NoUpdatesAvailableMessage);
|
---|
| 61 | }
|
---|
| 62 | StatusView.RemoveMessage(CheckingPluginsMessage);
|
---|
| 63 | StatusView.HideProgressIndicator();
|
---|
| 64 | StatusView.UnlockUI();
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | void updatePluginsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
| 68 | IEnumerable<IPluginDescription> installedPlugins = (IEnumerable<IPluginDescription>)e.Argument;
|
---|
| 69 | var remotePlugins = installationManager.GetRemotePluginList();
|
---|
| 70 | // if there is a local plugin with same name and same major and minor version then it's an update
|
---|
| 71 | var pluginsToUpdate = from remotePlugin in remotePlugins
|
---|
| 72 | let matchingLocalPlugins = from installedPlugin in installedPlugins
|
---|
| 73 | where installedPlugin.Name == remotePlugin.Name
|
---|
| 74 | where installedPlugin.Version.Major == remotePlugin.Version.Major
|
---|
| 75 | where installedPlugin.Version.Minor == remotePlugin.Version.Minor
|
---|
| 76 | where IsNewerThan(remotePlugin, installedPlugin)
|
---|
| 77 | select installedPlugin
|
---|
| 78 | where matchingLocalPlugins.Count() > 0
|
---|
| 79 | select remotePlugin;
|
---|
| 80 | if (pluginsToUpdate.Count() > 0) {
|
---|
[6413] | 81 | bool cancelled;
|
---|
| 82 | installationManager.Update(pluginsToUpdate, out cancelled);
|
---|
| 83 | if (!cancelled)
|
---|
| 84 | pluginManager.DiscoverAndCheckPlugins();
|
---|
[3547] | 85 | e.Cancel = false;
|
---|
| 86 | } else {
|
---|
| 87 | e.Cancel = true;
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[4527] | 91 | // compares for two plugins with same major and minor version if plugin1 is newer than plugin2
|
---|
[4482] | 92 | private static bool IsNewerThan(IPluginDescription plugin1, IPluginDescription plugin2) {
|
---|
[3547] | 93 | // newer: build version is higher, or if build version is the same revision is higher
|
---|
[4527] | 94 | return plugin1.Version.Build > plugin2.Version.Build ||
|
---|
| 95 | (plugin1.Version.Build == plugin2.Version.Build && plugin1.Version.Revision > plugin2.Version.Revision);
|
---|
[3547] | 96 | }
|
---|
| 97 |
|
---|
| 98 | #endregion
|
---|
| 99 | private void updateAndInstallButton_Click(object sender, EventArgs e) {
|
---|
| 100 | var installedPlugins = pluginManager.Plugins.OfType<IPluginDescription>().ToList();
|
---|
| 101 | updatePluginsBackgroundWorker.RunWorkerAsync(installedPlugins);
|
---|
| 102 | StatusView.LockUI();
|
---|
| 103 | StatusView.ShowProgressIndicator();
|
---|
| 104 | StatusView.RemoveMessage(NoUpdatesAvailableMessage);
|
---|
| 105 | StatusView.ShowMessage(CheckingPluginsMessage);
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | }
|
---|