Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6120 was 5445, checked in by swagner, 13 years ago

Updated year of copyrights (#1406)

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