Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3763 was 3752, checked in by gkronber, 15 years ago

Cleaned up unnecessary .resx files in plugin infrastructure. #989

File size: 10.5 KB
Line 
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;
22using System.Collections.Generic;
23using System.ComponentModel;
24using System.Data;
25using System.Drawing;
26using System.Linq;
27using System.Text;
28using System.Windows.Forms;
29using System.IO;
30using HeuristicLab.PluginInfrastructure.Manager;
31using System.Diagnostics;
32
33namespace HeuristicLab.PluginInfrastructure.Advanced {
34  internal partial class InstallationManagerForm : Form, IStatusView {
35    private InstallationManager installationManager;
36    private PluginManager pluginManager;
37    private string pluginDir;
38
39    public InstallationManagerForm(PluginManager pluginManager) : base() {
40      InitializeComponent();
41      FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
42      Text = "HeuristicLab Plugin Manager " + pluginInfrastructureVersion.FileVersion;
43     
44      this.pluginManager = pluginManager;
45
46      pluginManager.PluginLoaded += pluginManager_PluginLoaded;
47      pluginManager.PluginUnloaded += pluginManager_PluginUnloaded;
48      pluginManager.Initializing += pluginManager_Initializing;
49      pluginManager.Initialized += pluginManager_Initialized;
50
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
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 {
66        pluginEditor.PluginManager = pluginManager;
67      }
68
69      localPluginsView.StatusView = this;
70      localPluginsView.PluginManager = pluginManager;
71      localPluginsView.InstallationManager = installationManager;
72
73      basicUpdateView.StatusView = this;
74      basicUpdateView.PluginManager = pluginManager;
75      basicUpdateView.InstallationManager = installationManager;
76
77      remotePluginInstaller.StatusView = this;
78      remotePluginInstaller.InstallationManager = installationManager;
79      remotePluginInstaller.PluginManager = pluginManager;
80
81      pluginEditor.StatusView = this;
82      pluginEditor.PluginManager = pluginManager;
83
84      productEditor.StatusView = this;     
85    }
86
87
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) {
108      if (e.Plugins.Count() > 0) {
109        e.Cancel = ConfirmUpdateAction(e.Plugins) == false;
110      }
111    }
112
113    void installationManager_PreRemovePlugin(object sender, PluginInfrastructureCancelEventArgs e) {
114      if (e.Plugins.Count() > 0) {
115        e.Cancel = ConfirmRemoveAction(e.Plugins) == false;
116      }
117    }
118
119    void installationManager_PreInstallPlugin(object sender, PluginInfrastructureCancelEventArgs e) {
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        }
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
144    private void connectionSettingsToolStripMenuItem_Click(object sender, EventArgs e) {
145      new ConnectionSetupView().ShowDialog(this);
146    }
147    private void tabControl_SelectedIndexChanged(object sender, EventArgs e) {
148      toolStripStatusLabel.Text = string.Empty;
149    }
150    #endregion
151
152    #region confirmation dialogs
153    private bool ConfirmRemoveAction(IEnumerable<IPluginDescription> plugins) {
154      StringBuilder strBuilder = new StringBuilder();
155      foreach (var plugin in plugins) {
156        foreach (var file in plugin.Files) {
157          strBuilder.AppendLine(Path.GetFileName(file.Name));
158        }
159      }
160      return (new ConfirmationDialog("Confirm Delete", "Do you want to delete following files?", strBuilder.ToString())).ShowDialog(this) == DialogResult.OK;
161    }
162
163    private bool ConfirmUpdateAction(IEnumerable<IPluginDescription> plugins) {
164      StringBuilder strBuilder = new StringBuilder();
165      foreach (var plugin in plugins) {
166        strBuilder.AppendLine(plugin.ToString());
167      }
168      return (new ConfirmationDialog("Confirm Update", "Do you want to update following plugins?", strBuilder.ToString())).ShowDialog(this) == DialogResult.OK;
169    }
170
171    private bool ConfirmInstallAction(IEnumerable<IPluginDescription> plugins) {
172      foreach (var plugin in plugins) {
173        if (!string.IsNullOrEmpty(plugin.LicenseText)) {
174          var licenseConfirmationBox = new LicenseConfirmationDialog(plugin);
175          if (licenseConfirmationBox.ShowDialog(this) != DialogResult.OK)
176            return false;
177        }
178      }
179      return true;
180    }
181
182
183    #endregion
184
185    #region helper methods
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    }
193
194    #endregion
195
196
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    }
206
207    #region IStatusView Members
208
209    public void ShowProgressIndicator(double percentProgress) {
210      if (percentProgress < 0.0 || percentProgress > 1.0) throw new ArgumentException();
211      toolStripProgressBar.Visible = true;
212      toolStripProgressBar.Style = ProgressBarStyle.Continuous;
213      int range = toolStripProgressBar.Maximum - toolStripProgressBar.Minimum;
214      toolStripProgressBar.Value = (int)(percentProgress * range + toolStripProgressBar.Minimum);
215    }
216
217    public void ShowProgressIndicator() {
218      toolStripProgressBar.Visible = true;
219      toolStripProgressBar.Style = ProgressBarStyle.Marquee;
220    }
221
222    public void HideProgressIndicator() {
223      toolStripProgressBar.Visible = false;
224    }
225
226    public void ShowMessage(string message) {
227      if (toolStripStatusLabel.Text == string.Empty)
228        toolStripStatusLabel.Text = message;
229      else
230        toolStripStatusLabel.Text += "; " + message;
231    }
232
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(' ', ';');
239    }
240    public void LockUI() {
241      Cursor = Cursors.AppStarting;
242      tabControl.Enabled = false;
243    }
244    public void UnlockUI() {
245      tabControl.Enabled = true;
246      Cursor = Cursors.Default;
247    }
248    public void ShowError(string shortMessage, string description) {
249      logTextBox.Text += DateTime.Now + ": " + shortMessage + Environment.NewLine + description + Environment.NewLine;
250      MessageBox.Show(description, shortMessage);
251    }
252    #endregion
253
254  }
255}
Note: See TracBrowser for help on using the repository browser.