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