Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 18078 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

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