Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 29 was 29, checked in by gkronber, 16 years ago
  • refactored pluginInfrastructure
  • fixed #8
File size: 7.2 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    public List<PluginTag> hull = new List<PluginTag>();
88
89    public PluginTag(List<PluginTag> allTags, PluginInfo plugin, PluginState state) {
90      this.plugin = plugin;
91      this.state = state;
92      this.allTags = allTags;
93
94      this.pluginName = plugin.Name;
95      this.pluginVersion = plugin.Version;
96      pluginDetails = GeneratePluginDetails(plugin);
97      pluginDependencies = GeneratePluginDependencies(plugin);
98    }
99
100    public PluginTag(List<PluginTag> allTags, PluginDescription plugin, PluginState state) {
101      this.pluginDescription = plugin;
102      this.state = state;
103      this.allTags = allTags;
104
105      this.pluginName = plugin.Name;
106      this.pluginVersion = plugin.Version;
107
108      pluginDetails = GeneratePluginDetails(plugin);
109      pluginDependencies = GeneratePluginDependencies(plugin);
110    }
111
112
113
114    private string GeneratePluginDetails(PluginInfo plugin) {
115      string filenames = "";
116      foreach (string filename in plugin.Files) {
117        filenames += filename + "\n";
118      }
119      string dependencies = "";
120      foreach (PluginInfo dependency in plugin.Dependencies) {
121        dependencies += dependency.Name + " (" + dependency.Version + ")\n";
122      }
123      string dependents = "";
124      PluginManager.Manager.GetDependentPlugins(plugin).ForEach(delegate(PluginInfo dependentPlugin) {
125        dependents += dependentPlugin.Name + " (" + dependentPlugin.Version + ")\n";
126      });
127      return "plugin: " + plugin.Name + "\n" +
128      "Version: " + plugin.Version + "\n\n" +
129      "Requires: \n" + dependencies + "\n" +
130      "Used by:\n" + dependents + "\n" +
131      "Files:\n" + filenames + "\n";
132    }
133
134    private string GeneratePluginDetails(PluginDescription plugin) {
135      string dependencies = "";
136      foreach (string dependency in plugin.Dependencies) {
137        dependencies += dependency + "\n";
138      }
139      return "plugin: " + plugin.Name + "\n" +
140      "Version: " + plugin.Version + "\n" +
141      "Installed from: " + plugin.Source + "\n" +
142      "Requires: \n" + dependencies;
143    }
144
145    private string GenerateUpgradeDetails(PluginDescription upgrade) {
146      string dependencies = "";
147      foreach(string dependency in upgrade.Dependencies) {
148        dependencies += dependency + "\n";
149      }
150      return "plugin: " + upgrade.Name + "\n" +
151      "Current version: " + plugin.Version + " will be upgraded to new version: " + upgrade.Version + "\n"+
152      "Upgraded from: " + upgrade.Source + "\n" +
153      "Requires: \n" + dependencies;
154    }
155
156    private List<string> GeneratePluginDependencies(PluginInfo plugin) {
157      List<string> dependencies = new List<string>();
158
159      plugin.Dependencies.ForEach(delegate(PluginInfo dependency) {
160        dependencies.Add(dependency.Name);
161      });
162
163      return dependencies;
164    }
165
166    private List<string> GeneratePluginDependencies(PluginDescription plugin) {
167      return new List<string>(plugin.Dependencies);
168    }
169
170    internal string GetPluginDetails() {
171      return pluginDetails;
172    }
173
174    internal List<PluginTag> GetDependentTags() {
175      List<PluginTag> dependentTags = new List<PluginTag>();
176      foreach(PluginTag tag in allTags) {
177        if (tag.pluginDependencies.Contains(pluginName)) {
178          if (!dependentTags.Contains(tag)) {
179            dependentTags.Add(tag);
180
181            tag.GetDependentTags().ForEach(delegate(PluginTag dependentTag) {
182              if (!dependentTags.Contains(dependentTag)) {
183                dependentTags.Add(dependentTag);
184              }
185            });
186          }
187        }
188      }
189      return dependentTags;
190    }
191
192    internal List<PluginTag> GetDependencyTags() {
193      List<PluginTag> dependencyTags = new List<PluginTag>();
194      foreach(PluginTag tag in allTags) {
195        if (pluginDependencies.Contains(tag.pluginName)) {
196          if (!dependencyTags.Contains(tag)) {
197            dependencyTags.Add(tag);
198
199            tag.GetDependencyTags().ForEach(delegate(PluginTag dependencyTag) {
200              if (!dependencyTags.Contains(dependencyTag)) {
201                dependencyTags.Add(dependencyTag);
202              }
203            });
204          }
205        }
206      };
207      return dependencyTags;
208    }
209
210    internal bool UpgradeAvailable() {
211      return UpgradePluginDescription != null;
212    }
213
214    public override bool Equals(object obj) {
215      if (obj == null || !(obj is PluginTag)) return false;
216      PluginTag other = (PluginTag)obj;
217      return other.pluginName == pluginName && other.pluginVersion == pluginVersion;
218    }
219
220    public override int GetHashCode() {
221      if(pluginVersion != null) {
222        return pluginName.GetHashCode() + pluginVersion.GetHashCode();
223      } else return pluginName.GetHashCode();
224    }
225  }
226}
Note: See TracBrowser for help on using the repository browser.