Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/14/11 18:59:42 (14 years ago)
Author:
gkronber
Message:

#1536 implemented feature that checks for plugin updates on each application start and allows to install plugin updates easily. Removed more advanced plugin management features for all users except if it is manually reenabled in the HeuristicLab.config file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Starter/StarterForm.cs

    r5445 r6413  
    2929using HeuristicLab.PluginInfrastructure.Advanced;
    3030using HeuristicLab.PluginInfrastructure.Manager;
     31using System.Threading.Tasks;
    3132
    3233namespace HeuristicLab.PluginInfrastructure.Starter {
     
    3637  /// </summary>
    3738  public partial class StarterForm : Form {
     39    private const string pluginManagerItemName = "Plugin Manager";
     40    private const string updatePluginsItemName = "Updates Available";
     41
    3842
    3943    private ListViewItem pluginManagerListViewItem;
     
    4145    private PluginManager pluginManager;
    4246    private SplashScreen splashScreen;
     47    private bool updatesAvailable = false;
    4348
    4449    /// <summary>
     
    5055      InitializeComponent();
    5156      largeImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.HeuristicLab.ToBitmap());
     57      largeImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.UpdateAvailable.ToBitmap());
    5258      smallImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.HeuristicLab.ToBitmap());
     59      smallImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.UpdateAvailable.ToBitmap());
    5360      FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
    5461      Text = "HeuristicLab " + pluginInfrastructureVersion.FileVersion;
     
    6168      pluginManager.DiscoverAndCheckPlugins();
    6269      UpdateApplicationsList();
     70
     71      CheckUpdatesAvailableAsync(pluginPath);
     72    }
     73
     74    private void CheckUpdatesAvailableAsync(string pluginPath) {
     75      var task = Task.Factory.StartNew<bool>(() => {
     76        var installationManager = new InstallationManager(pluginPath);
     77        IEnumerable<IPluginDescription> installedPlugins = pluginManager.Plugins.OfType<IPluginDescription>();
     78        var remotePlugins = installationManager.GetRemotePluginList();
     79        // if there is a local plugin with same name and same major and minor version then it's an update
     80        var pluginsToUpdate = from remotePlugin in remotePlugins
     81                              let matchingLocalPlugins = from installedPlugin in installedPlugins
     82                                                         where installedPlugin.Name == remotePlugin.Name
     83                                                         where installedPlugin.Version.Major == remotePlugin.Version.Major
     84                                                         where installedPlugin.Version.Minor == remotePlugin.Version.Minor
     85                                                         where Util.IsNewerThan(remotePlugin, installedPlugin)
     86                                                         select installedPlugin
     87                              where matchingLocalPlugins.Count() > 0
     88                              select remotePlugin;
     89        return pluginsToUpdate.Count() > 0;
     90      });
     91      task.ContinueWith(t => {
     92        updatesAvailable = t.Result;
     93        UpdateApplicationsList();
     94      }, TaskContinuationOptions.NotOnFaulted);
    6395    }
    6496
     
    85117      if (applicationsListView.SelectedItems.Count > 0) {
    86118        ListViewItem selected = applicationsListView.SelectedItems[0];
    87         if (selected == pluginManagerListViewItem) {
     119        if (selected.Text == pluginManagerItemName) {
    88120          if (pluginManager.Plugins.Any(x => x.PluginState == PluginState.Loaded)) {
    89121            MessageBox.Show("Installation Manager cannot be started while another HeuristicLab application is active." + Environment.NewLine +
     
    102134            }
    103135          }
     136        } else if (selected.Text == updatePluginsItemName) {
     137          if (pluginManager.Plugins.Any(x => x.PluginState == PluginState.Loaded)) {
     138            MessageBox.Show("Updating is not possible while another HeuristicLab application is active." + Environment.NewLine +
     139              "Please stop all active HeuristicLab applications and try again.", "Update plugins",
     140              MessageBoxButtons.OK, MessageBoxIcon.Information);
     141          } else {
     142            try {
     143              Cursor = Cursors.AppStarting;
     144              using (PluginUpdaterForm form = new PluginUpdaterForm(pluginManager)) {
     145                form.ShowDialog(this);
     146              }
     147              UpdateApplicationsList();
     148            }
     149            finally {
     150              Cursor = Cursors.Arrow;
     151            }
     152          }
    104153        } else {
    105154          ApplicationDescription app = (ApplicationDescription)applicationsListView.SelectedItems[0].Tag;
     
    110159
    111160    private void UpdateApplicationsList() {
    112       applicationsListView.Items.Clear();
    113       FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
    114       pluginManagerListViewItem = new ListViewItem("Plugin Manager", 0);
    115       pluginManagerListViewItem.Group = applicationsListView.Groups["Plugin Management"];
    116       pluginManagerListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(pluginManagerListViewItem, pluginInfrastructureVersion.FileVersion));
    117       pluginManagerListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(pluginManagerListViewItem, "Install, upgrade or delete plugins"));
    118       pluginManagerListViewItem.ToolTipText = "Install, upgrade or delete plugins";
    119 
    120       applicationsListView.Items.Add(pluginManagerListViewItem);
    121 
    122       foreach (ApplicationDescription info in pluginManager.Applications) {
    123         ListViewItem item = new ListViewItem(info.Name, 0);
    124         item.Tag = info;
    125         item.Group = applicationsListView.Groups["Applications"];
    126         item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Version.ToString()));
    127         item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Description));
    128         item.ToolTipText = info.Description;
    129         applicationsListView.Items.Add(item);
    130       }
    131       foreach (ColumnHeader column in applicationsListView.Columns) {
    132         if (applicationsListView.Items.Count > 0)
    133           column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
    134         else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
     161      if (InvokeRequired) Invoke((Action)UpdateApplicationsList);
     162      else {
     163        applicationsListView.Items.Clear();
     164        AddPluginManagerItem();
     165        AddUpdatePluginsItem();
     166
     167        foreach (ApplicationDescription info in pluginManager.Applications) {
     168          ListViewItem item = new ListViewItem(info.Name, 0);
     169          item.Tag = info;
     170          item.Group = applicationsListView.Groups["Applications"];
     171          item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Version.ToString()));
     172          item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Description));
     173          item.ToolTipText = info.Description;
     174          applicationsListView.Items.Add(item);
     175        }
     176        foreach (ColumnHeader column in applicationsListView.Columns) {
     177          if (applicationsListView.Items.Count > 0)
     178            column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     179          else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
     180        }
     181      }
     182    }
     183
     184    private void AddPluginManagerItem() {
     185      if (HeuristicLab.PluginInfrastructure.Properties.Settings.Default.ShowPluginUploadControls) {
     186        FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
     187        pluginManagerListViewItem = new ListViewItem(pluginManagerItemName, 0);
     188        pluginManagerListViewItem.Group = applicationsListView.Groups["Plugin Management"];
     189        pluginManagerListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(pluginManagerListViewItem, pluginInfrastructureVersion.FileVersion));
     190        pluginManagerListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(pluginManagerListViewItem, "Install, upgrade or delete plugins"));
     191        pluginManagerListViewItem.ToolTipText = "Install, upgrade or delete plugins";
     192
     193        applicationsListView.Items.Add(pluginManagerListViewItem);
     194      }
     195    }
     196
     197    private void AddUpdatePluginsItem() {
     198      if (updatesAvailable) {
     199        var updateListViewItem = new ListViewItem(updatePluginsItemName, 1);
     200        updateListViewItem.Group = applicationsListView.Groups["Plugin Management"];
     201        updateListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(updateListViewItem, ""));
     202        updateListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(updateListViewItem, "Download and install updates"));
     203        updateListViewItem.ToolTipText = "Download and install updates";
     204
     205        applicationsListView.Items.Add(updateListViewItem);
    135206      }
    136207    }
Note: See TracChangeset for help on using the changeset viewer.