Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Advanced/InstallationManagerConsole.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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