Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/11 13:59:25 (13 years ago)
Author:
epitzer
Message:

#1530 integrate changes from trunk

Location:
branches/PersistenceSpeedUp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceSpeedUp

  • branches/PersistenceSpeedUp/HeuristicLab.PluginInfrastructure/3.3/Starter/StarterForm.cs

    r5445 r6760  
    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;
    43 
     47    private bool updatesAvailable = false;
    4448    /// <summary>
    4549    /// Initializes an instance of the starter form.
     
    5054      InitializeComponent();
    5155      largeImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.HeuristicLab.ToBitmap());
     56      largeImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.UpdateAvailable.ToBitmap());
    5257      smallImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.HeuristicLab.ToBitmap());
     58      smallImageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.UpdateAvailable.ToBitmap());
    5359      FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
    5460      Text = "HeuristicLab " + pluginInfrastructureVersion.FileVersion;
     
    6167      pluginManager.DiscoverAndCheckPlugins();
    6268      UpdateApplicationsList();
     69
     70      CheckUpdatesAvailableAsync();
     71    }
     72
     73    private void CheckUpdatesAvailableAsync() {
     74      string pluginPath = Path.GetFullPath(Application.StartupPath);
     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        try {
     93          t.Wait();
     94          updatesAvailable = t.Result;
     95          UpdateApplicationsList();
     96        }
     97        catch (AggregateException ae) {
     98          ae.Handle(ex => {
     99            if (ex is InstallationManagerException) {
     100              // this is expected when no internet connection is available => do nothing
     101              return true;
     102            } else {
     103              return false;
     104            }
     105          });
     106        }
     107      });
    63108    }
    64109
     
    85130      if (applicationsListView.SelectedItems.Count > 0) {
    86131        ListViewItem selected = applicationsListView.SelectedItems[0];
    87         if (selected == pluginManagerListViewItem) {
     132        if (selected.Text == pluginManagerItemName) {
    88133          if (pluginManager.Plugins.Any(x => x.PluginState == PluginState.Loaded)) {
    89134            MessageBox.Show("Installation Manager cannot be started while another HeuristicLab application is active." + Environment.NewLine +
     
    102147            }
    103148          }
     149        } else if (selected.Text == updatePluginsItemName) {
     150          if (pluginManager.Plugins.Any(x => x.PluginState == PluginState.Loaded)) {
     151            MessageBox.Show("Updating is not possible while another HeuristicLab application is active." + Environment.NewLine +
     152              "Please stop all active HeuristicLab applications and try again.", "Update plugins",
     153              MessageBoxButtons.OK, MessageBoxIcon.Information);
     154          } else {
     155            try {
     156              Cursor = Cursors.AppStarting;
     157              using (PluginUpdaterForm form = new PluginUpdaterForm(pluginManager)) {
     158                form.ShowDialog(this);
     159              }
     160              updatesAvailable = false;
     161              CheckUpdatesAvailableAsync();
     162              UpdateApplicationsList();
     163            }
     164            finally {
     165              Cursor = Cursors.Arrow;
     166            }
     167          }
    104168        } else {
    105169          ApplicationDescription app = (ApplicationDescription)applicationsListView.SelectedItems[0].Tag;
     
    110174
    111175    private void UpdateApplicationsList() {
    112       applicationsListView.Items.Clear();
     176      if (InvokeRequired) Invoke((Action)UpdateApplicationsList);
     177      else {
     178        applicationsListView.Items.Clear();
     179        AddPluginManagerItem();
     180        AddUpdatePluginsItem();
     181
     182        foreach (ApplicationDescription info in pluginManager.Applications) {
     183          ListViewItem item = new ListViewItem(info.Name, 0);
     184          item.Tag = info;
     185          item.Group = applicationsListView.Groups["Applications"];
     186          item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Version.ToString()));
     187          item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Description));
     188          item.ToolTipText = info.Description;
     189          applicationsListView.Items.Add(item);
     190        }
     191        foreach (ColumnHeader column in applicationsListView.Columns) {
     192          if (applicationsListView.Items.Count > 0)
     193            column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     194          else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
     195        }
     196      }
     197    }
     198
     199    private void AddPluginManagerItem() {
    113200      FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
    114       pluginManagerListViewItem = new ListViewItem("Plugin Manager", 0);
     201      pluginManagerListViewItem = new ListViewItem(pluginManagerItemName, 0);
    115202      pluginManagerListViewItem.Group = applicationsListView.Groups["Plugin Management"];
    116203      pluginManagerListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(pluginManagerListViewItem, pluginInfrastructureVersion.FileVersion));
     
    119206
    120207      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);
     208    }
     209
     210    private void AddUpdatePluginsItem() {
     211      if (updatesAvailable) {
     212        var updateListViewItem = new ListViewItem(updatePluginsItemName, 1);
     213        updateListViewItem.Group = applicationsListView.Groups["Plugin Management"];
     214        updateListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(updateListViewItem, ""));
     215        updateListViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(updateListViewItem, "Download and install updates"));
     216        updateListViewItem.ToolTipText = "Download and install updates";
     217
     218        applicationsListView.Items.Add(updateListViewItem);
    135219      }
    136220    }
Note: See TracChangeset for help on using the changeset viewer.