Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3624 was 3624, checked in by gkronber, 14 years ago

Implemented changes in plugin infrastructure requested by reviewers. #989 (Implement review comments in plugin infrastructure)

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