Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 885 was 91, checked in by gkronber, 17 years ago
  • added an attribute for the build time of an assembly.
  • build-date is automatically updated via SubWCRev in the pre-build action.
  • adapted PluginManager to correctly handle plugins with same version but newer build date

fixes ticket #39

File size: 7.9 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    public PluginInfo Plugin {
39      get { return plugin; }
40    }
41
42    private PluginDescription pluginDescription;
43    internal PluginDescription PluginDescription {
44      get { return pluginDescription; }
45      set {
46        pluginDescription = value;
47        pluginDependencies = GeneratePluginDependencies(pluginDescription);
48        pluginDetails = GeneratePluginDetails(pluginDescription);
49      }
50    }
51
52    private PluginDescription upgradePluginDescription;
53    public PluginDescription UpgradePluginDescription {
54      get { return upgradePluginDescription; }
55      set {
56        upgradePluginDescription = value;
57        pluginDependencies = GeneratePluginDependencies(upgradePluginDescription);
58        pluginDetails = GenerateUpgradeDetails(upgradePluginDescription);
59        state = PluginState.Upgradeable;
60      }
61    }
62
63    private string pluginName;
64    public string PluginName {
65      get { return pluginName; }
66      set { pluginName = value; }
67    }
68
69    private Version pluginVersion;
70    public Version PluginVersion {
71      get { return pluginVersion; }
72      set { pluginVersion = value; }
73    }
74    private DateTime pluginBuildDate;
75    public DateTime PluginBuildDate {
76      get { return pluginBuildDate; }
77      set { pluginBuildDate = value; }
78    }
79
80    private string pluginDetails;
81    private List<string> pluginDependencies;
82    private List<PluginTag> allTags;
83
84    private PluginState state;
85    public PluginState State {
86      get { return state; }
87      set { state = value; }
88    }
89
90    private string message;
91    public string Message {
92      get { return message; }
93    }
94
95    public List<PluginTag> hull = new List<PluginTag>();
96
97    public PluginTag(List<PluginTag> allTags, PluginInfo plugin, PluginState state) {
98      this.plugin = plugin;
99      this.state = state;
100      this.allTags = allTags;
101      this.pluginName = plugin.Name;
102      this.pluginVersion = plugin.Version;
103      this.pluginBuildDate = plugin.BuildDate;
104      this.message = plugin.Message;
105      pluginDetails = GeneratePluginDetails(plugin);
106      pluginDependencies = GeneratePluginDependencies(plugin);
107    }
108
109    public PluginTag(List<PluginTag> allTags, PluginDescription plugin, PluginState state) {
110      this.pluginDescription = plugin;
111      this.state = state;
112      this.allTags = allTags;
113      this.pluginName = plugin.Name;
114      this.pluginVersion = plugin.Version;
115      this.pluginBuildDate = plugin.BuildDate;
116      pluginDetails = GeneratePluginDetails(plugin);
117      pluginDependencies = GeneratePluginDependencies(plugin);
118    }
119
120
121
122    private string GeneratePluginDetails(PluginInfo plugin) {
123      string filenames = "";
124      foreach (string filename in plugin.Files) {
125        filenames += filename + "\n";
126      }
127      string dependencies = "";
128      foreach (PluginInfo dependency in plugin.Dependencies) {
129        dependencies += dependency.Name + " (" + dependency.Version + ")\n";
130      }
131      string dependents = "";
132      PluginManager.Manager.GetDependentPlugins(plugin).ForEach(delegate(PluginInfo dependentPlugin) {
133        dependents += dependentPlugin.Name + " (" + dependentPlugin.Version + ")\n";
134      });
135      return "Plugin: " + plugin.Name + "\n" +
136      "Version: " + plugin.Version + "\n" +
137      "Build: " +plugin.BuildDate + "\n\n" +
138      (dependencies.Length != 0 ? "Requires: \n" + dependencies + "\n" : "") +
139      (dependents.Length != 0 ? "Used by:\n" + dependents + "\n" : "") +
140      (filenames.Length != 0 ? "Files:\n" + filenames + "\n" : "") + message;
141      ;
142    }
143
144    private string GeneratePluginDetails(PluginDescription plugin) {
145      string dependencies = "";
146      foreach (string dependency in plugin.Dependencies) {
147        dependencies += dependency + "\n";
148      }
149      return "plugin: " + plugin.Name + "\n" +
150      "Version: " + plugin.Version + "\n" +
151      "Build: "+plugin.BuildDate +"\n" +
152      "Installed from: " + plugin.Source + "\n" +
153      "Requires: \n" + dependencies;
154    }
155
156    private string GenerateUpgradeDetails(PluginDescription upgrade) {
157      string dependencies = "";
158      foreach(string dependency in upgrade.Dependencies) {
159        dependencies += dependency + "\n";
160      }
161      return "plugin: " + upgrade.Name + "\n" +
162      "Current version: " + plugin.Version + " ("+plugin.BuildDate+") will be upgraded to new version: " + upgrade.Version + " ("+upgrade.BuildDate+")\n"+
163      "Upgraded from: " + upgrade.Source + "\n" +
164      "Requires: \n" + dependencies;
165    }
166
167    private List<string> GeneratePluginDependencies(PluginInfo plugin) {
168      List<string> dependencies = new List<string>();
169      plugin.Dependencies.ForEach(delegate(PluginInfo dependency) {
170        dependencies.Add(dependency.Name);
171      });
172      return dependencies;
173    }
174
175    private List<string> GeneratePluginDependencies(PluginDescription plugin) {
176      return new List<string>(plugin.Dependencies);
177    }
178
179    internal string GetPluginDetails() {
180      return pluginDetails;
181    }
182
183    internal List<PluginTag> GetDependentTags() {
184      List<PluginTag> dependentTags = new List<PluginTag>();
185      foreach(PluginTag tag in allTags) {
186        if (tag.pluginDependencies.Contains(pluginName)) {
187          if (!dependentTags.Contains(tag)) {
188            dependentTags.Add(tag);
189
190            tag.GetDependentTags().ForEach(delegate(PluginTag dependentTag) {
191              if (!dependentTags.Contains(dependentTag)) {
192                dependentTags.Add(dependentTag);
193              }
194            });
195          }
196        }
197      }
198      return dependentTags;
199    }
200
201    internal List<PluginTag> GetDependencyTags() {
202      List<PluginTag> dependencyTags = new List<PluginTag>();
203      foreach(PluginTag tag in allTags) {
204        if (pluginDependencies.Contains(tag.pluginName)) {
205          if (!dependencyTags.Contains(tag)) {
206            dependencyTags.Add(tag);
207
208            tag.GetDependencyTags().ForEach(delegate(PluginTag dependencyTag) {
209              if (!dependencyTags.Contains(dependencyTag)) {
210                dependencyTags.Add(dependencyTag);
211              }
212            });
213          }
214        }
215      };
216      return dependencyTags;
217    }
218
219    internal bool UpgradeAvailable() {
220      return UpgradePluginDescription != null;
221    }
222
223    public override bool Equals(object obj) {
224      if (obj == null || !(obj is PluginTag)) return false;
225      PluginTag other = (PluginTag)obj;
226      return other.pluginName == pluginName && other.pluginVersion == pluginVersion;
227    }
228
229    public override int GetHashCode() {
230      if(pluginVersion != null) {
231        return pluginName.GetHashCode() + pluginVersion.GetHashCode();
232      } else return pluginName.GetHashCode();
233    }
234  }
235}
Note: See TracBrowser for help on using the repository browser.