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
|
---|
21 |
|
---|
22 | using System;
|
---|
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;
|
---|
29 |
|
---|
30 |
|
---|
31 | namespace HeuristicLab.PluginInfrastructure.Advanced {
|
---|
32 | public class InstallationManagerConsole {
|
---|
33 | private InstallationManager installManager;
|
---|
34 | public InstallationManagerConsole(string pluginDir) {
|
---|
35 | this.installManager = new InstallationManager(pluginDir);
|
---|
36 | installManager.PreInstallPlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreInstallPlugin);
|
---|
37 | installManager.PreRemovePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreRemovePlugin);
|
---|
38 | installManager.PreUpdatePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreUpdatePlugin);
|
---|
39 | installManager.PluginInstalled += new EventHandler<PluginInfrastructureEventArgs>(installManager_PluginInstalled);
|
---|
40 | installManager.PluginRemoved += new EventHandler<PluginInfrastructureEventArgs>(installManager_PluginRemoved);
|
---|
41 | installManager.PluginUpdated += new EventHandler<PluginInfrastructureEventArgs>(installManager_PluginUpdated);
|
---|
42 | }
|
---|
43 |
|
---|
44 | void installManager_PreUpdatePlugin(object sender, PluginInfrastructureCancelEventArgs e) {
|
---|
45 | Console.WriteLine("Following plugins are updated:");
|
---|
46 | var infos = (IEnumerable<PluginDescription>)e.Entity;
|
---|
47 | foreach (var info in infos) {
|
---|
48 | Console.WriteLine(info.Name + " " + info.Version);
|
---|
49 | }
|
---|
50 | if (GetUserConfirmation()) e.Cancel = false;
|
---|
51 | else e.Cancel = true;
|
---|
52 | return;
|
---|
53 | }
|
---|
54 |
|
---|
55 | void installManager_PluginUpdated(object sender, PluginInfrastructureEventArgs e) {
|
---|
56 | foreach (var info in (IEnumerable<PluginDescription>)e.Entity)
|
---|
57 | Console.WriteLine("Updated: {0}", info.Name);
|
---|
58 | }
|
---|
59 |
|
---|
60 | void installManager_PreRemovePlugin(object sender, PluginInfrastructureCancelEventArgs e) {
|
---|
61 | Console.WriteLine("Following files are deleted:");
|
---|
62 | var fileNames = (IEnumerable<string>)e.Entity;
|
---|
63 | foreach (string fileName in fileNames) {
|
---|
64 | Console.WriteLine(fileName);
|
---|
65 | }
|
---|
66 | if (GetUserConfirmation()) e.Cancel = false;
|
---|
67 | else e.Cancel = true;
|
---|
68 | return;
|
---|
69 | }
|
---|
70 |
|
---|
71 | void installManager_PluginRemoved(object sender, PluginInfrastructureEventArgs e) {
|
---|
72 | foreach (string fileName in (IEnumerable<string>)e.Entity)
|
---|
73 | Console.WriteLine("Deleted: {0}", fileName);
|
---|
74 | }
|
---|
75 |
|
---|
76 | void installManager_PreInstallPlugin(object sender, PluginInfrastructureCancelEventArgs e) {
|
---|
77 |
|
---|
78 | }
|
---|
79 |
|
---|
80 | void installManager_PluginInstalled(object sender, PluginInfrastructureEventArgs e) {
|
---|
81 |
|
---|
82 | }
|
---|
83 |
|
---|
84 | private static bool GetUserConfirmation() {
|
---|
85 | Console.Write("Are you sure? (Y/n)");
|
---|
86 | string input = Console.ReadLine().ToUpperInvariant();
|
---|
87 | if (string.IsNullOrEmpty(input) || input == "Y") return true;
|
---|
88 | else return false;
|
---|
89 | }
|
---|
90 |
|
---|
91 | public void Show(IEnumerable<string> pluginNames) {
|
---|
92 | foreach (string pluginName in pluginNames)
|
---|
93 | Console.WriteLine(installManager.GetInformation(pluginName));
|
---|
94 | }
|
---|
95 |
|
---|
96 | public void Install(IEnumerable<string> pluginNames) {
|
---|
97 | installManager.Install(pluginNames);
|
---|
98 | }
|
---|
99 |
|
---|
100 | public void Remove(IEnumerable<string> pluginNames) {
|
---|
101 | installManager.Remove(pluginNames);
|
---|
102 | }
|
---|
103 |
|
---|
104 | public void Update(IEnumerable<string> pluginNames) {
|
---|
105 | installManager.Update(pluginNames);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|