[2612] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[2790] | 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2612] | 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 |
|
---|
| 22 | using System;
|
---|
[2517] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.PluginInfrastructure.Manager;
|
---|
| 27 | using System.IO;
|
---|
| 28 | using System.ComponentModel;
|
---|
[2922] | 29 | using HeuristicLab.PluginInfrastructure.Advanced.DeploymentService;
|
---|
[2517] | 30 |
|
---|
[2811] | 31 |
|
---|
[2517] | 32 | namespace HeuristicLab.PluginInfrastructure.Advanced {
|
---|
[3090] | 33 | internal class InstallationManagerConsole {
|
---|
[2517] | 34 | private InstallationManager installManager;
|
---|
[2922] | 35 | private string connectionString;
|
---|
[2527] | 36 | public InstallationManagerConsole(string pluginDir) {
|
---|
[2922] | 37 |
|
---|
| 38 | // get default connection string
|
---|
| 39 | using (var client = new UpdateClient()) {
|
---|
| 40 | connectionString = client.Endpoint.Address.ToString();
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[2527] | 43 | this.installManager = new InstallationManager(pluginDir);
|
---|
[2517] | 44 | installManager.PreInstallPlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreInstallPlugin);
|
---|
| 45 | installManager.PreRemovePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreRemovePlugin);
|
---|
| 46 | installManager.PreUpdatePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreUpdatePlugin);
|
---|
| 47 | installManager.PluginInstalled += new EventHandler<PluginInfrastructureEventArgs>(installManager_PluginInstalled);
|
---|
| 48 | installManager.PluginRemoved += new EventHandler<PluginInfrastructureEventArgs>(installManager_PluginRemoved);
|
---|
| 49 | installManager.PluginUpdated += new EventHandler<PluginInfrastructureEventArgs>(installManager_PluginUpdated);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | void installManager_PreUpdatePlugin(object sender, PluginInfrastructureCancelEventArgs e) {
|
---|
[2527] | 53 | Console.WriteLine("Following plugins are updated:");
|
---|
[3006] | 54 | foreach (var info in e.Plugins) {
|
---|
[2922] | 55 | Console.WriteLine(e);
|
---|
[2527] | 56 | }
|
---|
| 57 | if (GetUserConfirmation()) e.Cancel = false;
|
---|
| 58 | else e.Cancel = true;
|
---|
| 59 | return;
|
---|
[2517] | 60 | }
|
---|
| 61 |
|
---|
| 62 | void installManager_PluginUpdated(object sender, PluginInfrastructureEventArgs e) {
|
---|
[2922] | 63 | foreach (var info in (IEnumerable<IPluginDescription>)e.Entity)
|
---|
[2527] | 64 | Console.WriteLine("Updated: {0}", info.Name);
|
---|
[2517] | 65 | }
|
---|
| 66 |
|
---|
| 67 | void installManager_PreRemovePlugin(object sender, PluginInfrastructureCancelEventArgs e) {
|
---|
| 68 | Console.WriteLine("Following files are deleted:");
|
---|
[3006] | 69 | foreach (var plugin in e.Plugins) {
|
---|
| 70 | foreach (var file in plugin.Files)
|
---|
| 71 | Console.WriteLine(file);
|
---|
[2517] | 72 | }
|
---|
| 73 | if (GetUserConfirmation()) e.Cancel = false;
|
---|
| 74 | else e.Cancel = true;
|
---|
| 75 | return;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void installManager_PluginRemoved(object sender, PluginInfrastructureEventArgs e) {
|
---|
| 79 | foreach (string fileName in (IEnumerable<string>)e.Entity)
|
---|
| 80 | Console.WriteLine("Deleted: {0}", fileName);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | void installManager_PreInstallPlugin(object sender, PluginInfrastructureCancelEventArgs e) {
|
---|
[2527] | 84 |
|
---|
[2517] | 85 | }
|
---|
| 86 |
|
---|
| 87 | void installManager_PluginInstalled(object sender, PluginInfrastructureEventArgs e) {
|
---|
[2527] | 88 |
|
---|
[2517] | 89 | }
|
---|
| 90 |
|
---|
| 91 | private static bool GetUserConfirmation() {
|
---|
| 92 | Console.Write("Are you sure? (Y/n)");
|
---|
| 93 | string input = Console.ReadLine().ToUpperInvariant();
|
---|
| 94 | if (string.IsNullOrEmpty(input) || input == "Y") return true;
|
---|
| 95 | else return false;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | public void Show(IEnumerable<string> pluginNames) {
|
---|
[2922] | 99 | //foreach (string pluginName in pluginNames)
|
---|
| 100 | // Console.WriteLine(installManager.GetInformation(pluginName));
|
---|
[2517] | 101 | }
|
---|
| 102 |
|
---|
| 103 | public void Install(IEnumerable<string> pluginNames) {
|
---|
[2922] | 104 | //installManager.Install(connectionString, pluginNames);
|
---|
[2517] | 105 | }
|
---|
| 106 |
|
---|
| 107 | public void Remove(IEnumerable<string> pluginNames) {
|
---|
[2922] | 108 | // installManager.Remove(pluginNames);
|
---|
[2517] | 109 | }
|
---|
| 110 |
|
---|
| 111 | public void Update(IEnumerable<string> pluginNames) {
|
---|
[2922] | 112 | // installManager.Update(connectionString, pluginNames);
|
---|
[2517] | 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|