Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2595 was 2527, checked in by gkronber, 15 years ago

Implemented changes as requested by swagner. #799

File size: 3.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.PluginInfrastructure.Manager;
6using System.IO;
7using System.ComponentModel;
8using HeuristicLab.PluginInfrastructure.UpdateLocationReference;
9
10namespace HeuristicLab.PluginInfrastructure.Advanced {
11  public class InstallationManagerConsole {
12    private InstallationManager installManager;
13    public InstallationManagerConsole(string pluginDir) {
14      this.installManager = new InstallationManager(pluginDir);
15      installManager.PreInstallPlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreInstallPlugin);
16      installManager.PreRemovePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreRemovePlugin);
17      installManager.PreUpdatePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreUpdatePlugin);
18      installManager.PluginInstalled += new EventHandler<PluginInfrastructureEventArgs>(installManager_PluginInstalled);
19      installManager.PluginRemoved += new EventHandler<PluginInfrastructureEventArgs>(installManager_PluginRemoved);
20      installManager.PluginUpdated += new EventHandler<PluginInfrastructureEventArgs>(installManager_PluginUpdated);
21    }
22
23    void installManager_PreUpdatePlugin(object sender, PluginInfrastructureCancelEventArgs e) {
24      Console.WriteLine("Following plugins are updated:");
25      var infos = (IEnumerable<PluginInformation>)e.Entity;
26      foreach (var info in infos) {
27        Console.WriteLine(info.Name + " " + info.Version + " " + info.BuildDate);
28      }
29      if (GetUserConfirmation()) e.Cancel = false;
30      else e.Cancel = true;
31      return;
32    }
33
34    void installManager_PluginUpdated(object sender, PluginInfrastructureEventArgs e) {
35      foreach (var info in (IEnumerable<PluginInformation>)e.Entity)
36        Console.WriteLine("Updated: {0}", info.Name);
37    }
38
39    void installManager_PreRemovePlugin(object sender, PluginInfrastructureCancelEventArgs e) {
40      Console.WriteLine("Following files are deleted:");
41      var fileNames = (IEnumerable<string>)e.Entity;
42      foreach (string fileName in fileNames) {
43        Console.WriteLine(fileName);
44      }
45      if (GetUserConfirmation()) e.Cancel = false;
46      else e.Cancel = true;
47      return;
48    }
49
50    void installManager_PluginRemoved(object sender, PluginInfrastructureEventArgs e) {
51      foreach (string fileName in (IEnumerable<string>)e.Entity)
52        Console.WriteLine("Deleted: {0}", fileName);
53    }
54
55    void installManager_PreInstallPlugin(object sender, PluginInfrastructureCancelEventArgs e) {
56
57    }
58
59    void installManager_PluginInstalled(object sender, PluginInfrastructureEventArgs e) {
60
61    }
62
63    private static bool GetUserConfirmation() {
64      Console.Write("Are you sure? (Y/n)");
65      string input = Console.ReadLine().ToUpperInvariant();
66      if (string.IsNullOrEmpty(input) || input == "Y") return true;
67      else return false;
68    }
69
70    public void Show(IEnumerable<string> pluginNames) {
71      foreach (string pluginName in pluginNames)
72        Console.WriteLine(installManager.GetInformation(pluginName));
73    }
74
75    public void Install(IEnumerable<string> pluginNames) {
76      installManager.Install(pluginNames);
77    }
78
79    public void Remove(IEnumerable<string> pluginNames) {
80      installManager.Remove(pluginNames);
81    }
82
83    public void Update(IEnumerable<string> pluginNames) {
84      installManager.Update(pluginNames);
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.