Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.PluginInfrastructure/Advanced/InstallationManagerForm.cs @ 3580

Last change on this file since 3580 was 3573, checked in by gkronber, 15 years ago

Implemented a list of review comments by swagner. #989 (Implement review comments in plugin infrastructure)

File size: 10.7 KB
RevLine 
[3090]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
21using System;
[2748]22using System.Collections.Generic;
23using System.ComponentModel;
24using System.Data;
25using System.Drawing;
26using System.Linq;
27using System.Text;
28using System.Windows.Forms;
[2753]29using System.IO;
30using HeuristicLab.PluginInfrastructure.Manager;
[2748]31
32namespace HeuristicLab.PluginInfrastructure.Advanced {
[3547]33  internal partial class InstallationManagerForm : Form, IStatusView {
[2753]34    private InstallationManager installationManager;
[3474]35    private PluginManager pluginManager;
[2922]36    private string pluginDir;
[2753]37
[3474]38    public InstallationManagerForm(PluginManager pluginManager) {
[2748]39      InitializeComponent();
[3573]40      Text = "HeuristicLab Plugin Manager " + GetType().Assembly.GetName().Version.ToString();
41     
[3474]42      this.pluginManager = pluginManager;
[3547]43
[3474]44      pluginManager.PluginLoaded += pluginManager_PluginLoaded;
45      pluginManager.PluginUnloaded += pluginManager_PluginUnloaded;
46      pluginManager.Initializing += pluginManager_Initializing;
47      pluginManager.Initialized += pluginManager_Initialized;
[2753]48
[2922]49      pluginDir = Application.StartupPath;
50
51      installationManager = new InstallationManager(pluginDir);
52      installationManager.PluginInstalled += new EventHandler<PluginInfrastructureEventArgs>(installationManager_PluginInstalled);
53      installationManager.PluginRemoved += new EventHandler<PluginInfrastructureEventArgs>(installationManager_PluginRemoved);
54      installationManager.PluginUpdated += new EventHandler<PluginInfrastructureEventArgs>(installationManager_PluginUpdated);
55      installationManager.PreInstallPlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installationManager_PreInstallPlugin);
56      installationManager.PreRemovePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installationManager_PreRemovePlugin);
57      installationManager.PreUpdatePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installationManager_PreUpdatePlugin);
58
[3508]59      // show or hide controls for uploading plugins based on setting
60      if (!HeuristicLab.PluginInfrastructure.Properties.Settings.Default.ShowPluginUploadControls) {
61        tabControl.Controls.Remove(uploadPluginsTabPage);
62        tabControl.Controls.Remove(manageProductsTabPage);
63      } else {
[3547]64        pluginEditor.PluginManager = pluginManager;
[3508]65      }
66
[3547]67      localPluginsView.StatusView = this;
68      localPluginsView.PluginManager = pluginManager;
69      localPluginsView.InstallationManager = installationManager;
[3508]70
[3547]71      basicUpdateView.StatusView = this;
72      basicUpdateView.PluginManager = pluginManager;
73      basicUpdateView.InstallationManager = installationManager;
[2753]74
[3547]75      remotePluginInstaller.StatusView = this;
76      remotePluginInstaller.InstallationManager = installationManager;
77      remotePluginInstaller.PluginManager = pluginManager;
[2753]78    }
79
80
[2922]81    #region plugin manager event handlers
82    void pluginManager_Initialized(object sender, PluginInfrastructureEventArgs e) {
83      SetStatusStrip("Initialized PluginInfrastructure");
84    }
85
86    void pluginManager_Initializing(object sender, PluginInfrastructureEventArgs e) {
87      SetStatusStrip("Initializing PluginInfrastructure");
88    }
89
90    void pluginManager_PluginUnloaded(object sender, PluginInfrastructureEventArgs e) {
91      SetStatusStrip("Unloaded " + e.Entity);
92    }
93
94    void pluginManager_PluginLoaded(object sender, PluginInfrastructureEventArgs e) {
95      SetStatusStrip("Loaded " + e.Entity);
96    }
97    #endregion
98
99    #region installation manager event handlers
100    void installationManager_PreUpdatePlugin(object sender, PluginInfrastructureCancelEventArgs e) {
[3006]101      if (e.Plugins.Count() > 0) {
102        e.Cancel = ConfirmUpdateAction(e.Plugins) == false;
103      }
[2922]104    }
105
106    void installationManager_PreRemovePlugin(object sender, PluginInfrastructureCancelEventArgs e) {
[3006]107      if (e.Plugins.Count() > 0) {
108        e.Cancel = ConfirmRemoveAction(e.Plugins) == false;
109      }
[2922]110    }
111
112    void installationManager_PreInstallPlugin(object sender, PluginInfrastructureCancelEventArgs e) {
[3006]113      if (e.Plugins.Count() > 0)
114        if (ConfirmInstallAction(e.Plugins) == true) {
115          SetStatusStrip("Installing " + e.Plugins.Aggregate("", (a, b) => a.ToString() + "; " + b.ToString()));
116          e.Cancel = false;
117        } else {
118          e.Cancel = true;
119          SetStatusStrip("Install canceled");
120        }
[2922]121    }
122
123    void installationManager_PluginUpdated(object sender, PluginInfrastructureEventArgs e) {
124      SetStatusStrip("Updated " + e.Entity);
125    }
126
127    void installationManager_PluginRemoved(object sender, PluginInfrastructureEventArgs e) {
128      SetStatusStrip("Removed " + e.Entity);
129    }
130
131    void installationManager_PluginInstalled(object sender, PluginInfrastructureEventArgs e) {
132      SetStatusStrip("Installed " + e.Entity);
133    }
134    #endregion
135
136    #region button events
[3508]137    private void connectionSettingsToolStripMenuItem_Click(object sender, EventArgs e) {
138      new ConnectionSetupView().ShowDialog();
139    }
140
141    private void tabControl_Selected(object sender, TabControlEventArgs e) {
[3573]142      viewToolStripMenuItem.Visible = e.TabPage == availablePluginsTabPage;
[3547]143      toolStripStatusLabel.Text = string.Empty;
144      toolStripProgressBar.Visible = false;
[3508]145    }
146
147    private void simpleToolStripMenuItem_Click(object sender, EventArgs e) {
148      remotePluginInstaller.ShowAllPlugins = false;
149      advancedToolStripMenuItem.Checked = false;
150    }
151
152    private void advancedToolStripMenuItem_Click(object sender, EventArgs e) {
153      remotePluginInstaller.ShowAllPlugins = true;
154      simpleToolStripMenuItem.Checked = false;
155    }
[2922]156    #endregion
157
158    #region confirmation dialogs
[3006]159    private bool ConfirmRemoveAction(IEnumerable<IPluginDescription> plugins) {
[2922]160      StringBuilder strBuilder = new StringBuilder();
[3006]161      foreach (var plugin in plugins) {
162        foreach (var file in plugin.Files) {
[3069]163          strBuilder.AppendLine(Path.GetFileName(file.Name));
[3006]164        }
[2922]165      }
[3069]166      return (new ConfirmationDialog("Confirm Delete", "Do you want to delete following files?", strBuilder.ToString())).ShowDialog() == DialogResult.OK;
[2922]167    }
168
[3006]169    private bool ConfirmUpdateAction(IEnumerable<IPluginDescription> plugins) {
[2922]170      StringBuilder strBuilder = new StringBuilder();
171      foreach (var plugin in plugins) {
[3006]172        strBuilder.AppendLine(plugin.ToString());
[2922]173      }
[3069]174      return (new ConfirmationDialog("Confirm Update", "Do you want to update following plugins?", strBuilder.ToString())).ShowDialog() == DialogResult.OK;
[2922]175    }
176
[3006]177    private bool ConfirmInstallAction(IEnumerable<IPluginDescription> plugins) {
178      foreach (var plugin in plugins) {
179        if (!string.IsNullOrEmpty(plugin.LicenseText)) {
180          var licenseConfirmationBox = new LicenseConfirmationBox(plugin);
181          if (licenseConfirmationBox.ShowDialog() != DialogResult.OK)
182            return false;
183        }
184      }
185      return true;
186    }
187
188
[2922]189    #endregion
190
191    #region helper methods
[3508]192    private void SetStatusStrip(string msg) {
193      if (InvokeRequired) Invoke((Action<string>)SetStatusStrip, msg);
194      else {
195        toolStripStatusLabel.Text = msg;
196        logTextBox.Text += DateTime.Now + ": " + msg + Environment.NewLine;
197      }
198    }
[2922]199
[3547]200    #endregion
[2922]201
202
[3547]203    protected override void OnClosing(CancelEventArgs e) {
204      installationManager.PluginInstalled -= new EventHandler<PluginInfrastructureEventArgs>(installationManager_PluginInstalled);
205      installationManager.PluginRemoved -= new EventHandler<PluginInfrastructureEventArgs>(installationManager_PluginRemoved);
206      installationManager.PluginUpdated -= new EventHandler<PluginInfrastructureEventArgs>(installationManager_PluginUpdated);
207      installationManager.PreInstallPlugin -= new EventHandler<PluginInfrastructureCancelEventArgs>(installationManager_PreInstallPlugin);
208      installationManager.PreRemovePlugin -= new EventHandler<PluginInfrastructureCancelEventArgs>(installationManager_PreRemovePlugin);
209      installationManager.PreUpdatePlugin -= new EventHandler<PluginInfrastructureCancelEventArgs>(installationManager_PreUpdatePlugin);
210      base.OnClosing(e);
211    }
[2922]212
[3547]213    #region IStatusView Members
[2922]214
[3547]215    public void ShowProgressIndicator(double percentProgress) {
216      if (percentProgress < 0.0 || percentProgress > 1.0) throw new ArgumentException();
[2922]217      toolStripProgressBar.Visible = true;
[3547]218      toolStripProgressBar.Style = ProgressBarStyle.Continuous;
219      int range = toolStripProgressBar.Maximum - toolStripProgressBar.Minimum;
220      toolStripProgressBar.Value = (int)(percentProgress * range + toolStripProgressBar.Minimum);
[2922]221    }
222
[3547]223    public void ShowProgressIndicator() {
[2922]224      toolStripProgressBar.Visible = true;
[3547]225      toolStripProgressBar.Style = ProgressBarStyle.Marquee;
[2922]226    }
227
[3547]228    public void HideProgressIndicator() {
[2922]229      toolStripProgressBar.Visible = false;
230    }
231
[3547]232    public void ShowMessage(string message) {
233      if (toolStripStatusLabel.Text == string.Empty)
234        toolStripStatusLabel.Text = message;
235      else
236        toolStripStatusLabel.Text += "; " + message;
[2922]237    }
238
[3547]239    public void RemoveMessage(string message) {
240      if (toolStripStatusLabel.Text.IndexOf("; " + message) > 0) {
241        toolStripStatusLabel.Text = toolStripStatusLabel.Text.Replace("; " + message, "");
242      }
243      toolStripStatusLabel.Text = toolStripStatusLabel.Text.Replace(message, "");
244      toolStripStatusLabel.Text = toolStripStatusLabel.Text.TrimStart(' ', ';');
[2922]245    }
[3547]246    public void LockUI() {
247      Cursor = Cursors.AppStarting;
248      tabControl.Enabled = false;
[2922]249    }
[3547]250    public void UnlockUI() {
251      tabControl.Enabled = true;
252      Cursor = Cursors.Default;
[2922]253    }
[3547]254    public void ShowError(string shortMessage, string description) {
255      logTextBox.Text += DateTime.Now + ": " + shortMessage + Environment.NewLine + description + Environment.NewLine;
256      MessageBox.Show(description, shortMessage);
[3179]257    }
[3547]258    #endregion
[3573]259
[2748]260  }
261}
Note: See TracBrowser for help on using the repository browser.