Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.PluginInfrastructure.GUI/PluginTag.cs @ 37

Last change on this file since 37 was 37, checked in by gkronber, 16 years ago
  • fixed #37. Assemblies that have missing references (wrong versions) are also listed in the disabled plugins.
  • plugin-manager shows a message why a plugin has been disabled (see #8)
File size: 7.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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 System.Text;
25
26namespace HeuristicLab.PluginInfrastructure.GUI {
27
28  [Flags]
29  enum PluginState {
30    Installed = 1,
31    Available = 2,
32    Upgradeable = 4,
33    Disabled = 8,
34  };
35
36  class PluginTag {
37    private PluginInfo plugin;
38
39    public PluginInfo Plugin {
40      get { return plugin; }
41    }
42
43    private PluginDescription pluginDescription;
44    internal PluginDescription PluginDescription {
45      get { return pluginDescription; }
46      set {
47        pluginDescription = value;
48        pluginDependencies = GeneratePluginDependencies(pluginDescription);
49        pluginDetails = GeneratePluginDetails(pluginDescription);
50      }
51    }
52
53
54    private PluginDescription upgradePluginDescription;
55    public PluginDescription UpgradePluginDescription {
56      get { return upgradePluginDescription; }
57      set {
58        upgradePluginDescription = value;
59        pluginDependencies = GeneratePluginDependencies(upgradePluginDescription);
60        pluginDetails = GenerateUpgradeDetails(upgradePluginDescription);
61        state = PluginState.Upgradeable;
62      }
63    }
64
65    private string pluginName;
66    public string PluginName {
67      get { return pluginName; }
68      set { pluginName = value; }
69    }
70
71    private Version pluginVersion;
72    public Version PluginVersion {
73      get { return pluginVersion; }
74      set { pluginVersion = value; }
75    }
76
77    private string pluginDetails;
78    private List<string> pluginDependencies;
79    private List<PluginTag> allTags;
80
81    private PluginState state;
82    public PluginState State {
83      get { return state; }
84      set { state = value; }
85    }
86
87    private string message;
88    public string Message {
89      get { return message; }
90    }
91
92    public List<PluginTag> hull = new List<PluginTag>();
93
94    public PluginTag(List<PluginTag> allTags, PluginInfo plugin, PluginState state) {
95      this.plugin = plugin;
96      this.state = state;
97      this.allTags = allTags;
98
99      this.pluginName = plugin.Name;
100      this.pluginVersion = plugin.Version;
101      this.message = plugin.Message;
102      pluginDetails = GeneratePluginDetails(plugin);
103      pluginDependencies = GeneratePluginDependencies(plugin);
104    }
105
106    public PluginTag(List<PluginTag> allTags, PluginDescription plugin, PluginState state) {
107      this.pluginDescription = plugin;
108      this.state = state;
109      this.allTags = allTags;
110
111      this.pluginName = plugin.Name;
112      this.pluginVersion = plugin.Version;
113
114      pluginDetails = GeneratePluginDetails(plugin);
115      pluginDependencies = GeneratePluginDependencies(plugin);
116    }
117
118
119
120    private string GeneratePluginDetails(PluginInfo plugin) {
121      string filenames = "";
122      foreach (string filename in plugin.Files) {
123        filenames += filename + "\n";
124      }
125      string dependencies = "";
126      foreach (PluginInfo dependency in plugin.Dependencies) {
127        dependencies += dependency.Name + " (" + dependency.Version + ")\n";
128      }
129      string dependents = "";
130      PluginManager.Manager.GetDependentPlugins(plugin).ForEach(delegate(PluginInfo dependentPlugin) {
131        dependents += dependentPlugin.Name + " (" + dependentPlugin.Version + ")\n";
132      });
133      return "Plugin: " + plugin.Name + "\n" +
134      "Version: " + plugin.Version + "\n\n" +
135      (dependencies.Length != 0 ? "Requires: \n" + dependencies + "\n" : "") +
136      (dependents.Length != 0 ? "Used by:\n" + dependents + "\n" : "") +
137      (filenames.Length != 0 ? "Files:\n" + filenames + "\n" : "") + message;
138      ;
139    }
140
141    private string GeneratePluginDetails(PluginDescription plugin) {
142      string dependencies = "";
143      foreach (string dependency in plugin.Dependencies) {
144        dependencies += dependency + "\n";
145      }
146      return "plugin: " + plugin.Name + "\n" +
147      "Version: " + plugin.Version + "\n" +
148      "Installed from: " + plugin.Source + "\n" +
149      "Requires: \n" + dependencies;
150    }
151
152    private string GenerateUpgradeDetails(PluginDescription upgrade) {
153      string dependencies = "";
154      foreach(string dependency in upgrade.Dependencies) {
155        dependencies += dependency + "\n";
156      }
157      return "plugin: " + upgrade.Name + "\n" +
158      "Current version: " + plugin.Version + " will be upgraded to new version: " + upgrade.Version + "\n"+
159      "Upgraded from: " + upgrade.Source + "\n" +
160      "Requires: \n" + dependencies;
161    }
162
163    private List<string> GeneratePluginDependencies(PluginInfo plugin) {
164      List<string> dependencies = new List<string>();
165
166      plugin.Dependencies.ForEach(delegate(PluginInfo dependency) {
167        dependencies.Add(dependency.Name);
168      });
169
170      return dependencies;
171    }
172
173    private List<string> GeneratePluginDependencies(PluginDescription plugin) {
174      return new List<string>(plugin.Dependencies);
175    }
176
177    internal string GetPluginDetails() {
178      return pluginDetails;
179    }
180
181    internal List<PluginTag> GetDependentTags() {
182      List<PluginTag> dependentTags = new List<PluginTag>();
183      foreach(PluginTag tag in allTags) {
184        if (tag.pluginDependencies.Contains(pluginName)) {
185          if (!dependentTags.Contains(tag)) {
186            dependentTags.Add(tag);
187
188            tag.GetDependentTags().ForEach(delegate(PluginTag dependentTag) {
189              if (!dependentTags.Contains(dependentTag)) {
190                dependentTags.Add(dependentTag);
191              }
192            });
193          }
194        }
195      }
196      return dependentTags;
197    }
198
199    internal List<PluginTag> GetDependencyTags() {
200      List<PluginTag> dependencyTags = new List<PluginTag>();
201      foreach(PluginTag tag in allTags) {
202        if (pluginDependencies.Contains(tag.pluginName)) {
203          if (!dependencyTags.Contains(tag)) {
204            dependencyTags.Add(tag);
205
206            tag.GetDependencyTags().ForEach(delegate(PluginTag dependencyTag) {
207              if (!dependencyTags.Contains(dependencyTag)) {
208                dependencyTags.Add(dependencyTag);
209              }
210            });
211          }
212        }
213      };
214      return dependencyTags;
215    }
216
217    internal bool UpgradeAvailable() {
218      return UpgradePluginDescription != null;
219    }
220
221    public override bool Equals(object obj) {
222      if (obj == null || !(obj is PluginTag)) return false;
223      PluginTag other = (PluginTag)obj;
224      return other.pluginName == pluginName && other.pluginVersion == pluginVersion;
225    }
226
227    public override int GetHashCode() {
228      if(pluginVersion != null) {
229        return pluginName.GetHashCode() + pluginVersion.GetHashCode();
230      } else return pluginName.GetHashCode();
231    }
232  }
233}
Note: See TracBrowser for help on using the repository browser.