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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Text;
|
---|
25 |
|
---|
26 | namespace HeuristicLab.PluginInfrastructure.GUI {
|
---|
27 |
|
---|
28 | [Flags]
|
---|
29 | enum PluginState {
|
---|
30 | Installed = 1,
|
---|
31 | Available = 2,
|
---|
32 | Upgradeable = 4,
|
---|
33 | };
|
---|
34 |
|
---|
35 | class PluginTag {
|
---|
36 | private PluginInfo plugin;
|
---|
37 |
|
---|
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 |
|
---|
53 | private PluginDescription upgradePluginDescription;
|
---|
54 | public PluginDescription UpgradePluginDescription {
|
---|
55 | get { return upgradePluginDescription; }
|
---|
56 | set {
|
---|
57 | upgradePluginDescription = value;
|
---|
58 | pluginDependencies = GeneratePluginDependencies(upgradePluginDescription);
|
---|
59 | pluginDetails = GenerateUpgradeDetails(upgradePluginDescription);
|
---|
60 | state = PluginState.Upgradeable;
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | private string pluginName;
|
---|
65 | public string PluginName {
|
---|
66 | get { return pluginName; }
|
---|
67 | set { pluginName = value; }
|
---|
68 | }
|
---|
69 |
|
---|
70 | private Version pluginVersion;
|
---|
71 | public Version PluginVersion {
|
---|
72 | get { return pluginVersion; }
|
---|
73 | set { pluginVersion = value; }
|
---|
74 | }
|
---|
75 |
|
---|
76 | private string pluginDetails;
|
---|
77 | private List<string> pluginDependencies;
|
---|
78 | private List<PluginTag> allTags;
|
---|
79 |
|
---|
80 | private PluginState state;
|
---|
81 | public PluginState State {
|
---|
82 | get { return state; }
|
---|
83 | set { state = value; }
|
---|
84 | }
|
---|
85 |
|
---|
86 | public List<PluginTag> hull = new List<PluginTag>();
|
---|
87 |
|
---|
88 | public PluginTag(List<PluginTag> allTags, PluginInfo plugin, PluginState state) {
|
---|
89 | this.plugin = plugin;
|
---|
90 | this.state = state;
|
---|
91 | this.allTags = allTags;
|
---|
92 |
|
---|
93 | this.pluginName = plugin.Name;
|
---|
94 | this.pluginVersion = plugin.Version;
|
---|
95 | pluginDetails = GeneratePluginDetails(plugin);
|
---|
96 | pluginDependencies = GeneratePluginDependencies(plugin);
|
---|
97 | }
|
---|
98 |
|
---|
99 | public PluginTag(List<PluginTag> allTags, PluginDescription plugin, PluginState state) {
|
---|
100 | this.pluginDescription = plugin;
|
---|
101 | this.state = state;
|
---|
102 | this.allTags = allTags;
|
---|
103 |
|
---|
104 | this.pluginName = plugin.Name;
|
---|
105 | this.pluginVersion = plugin.Version;
|
---|
106 |
|
---|
107 | pluginDetails = GeneratePluginDetails(plugin);
|
---|
108 | pluginDependencies = GeneratePluginDependencies(plugin);
|
---|
109 | }
|
---|
110 |
|
---|
111 |
|
---|
112 |
|
---|
113 | private string GeneratePluginDetails(PluginInfo plugin) {
|
---|
114 | string filenames = "";
|
---|
115 | foreach (string filename in plugin.Files) {
|
---|
116 | filenames += filename + "\n";
|
---|
117 | }
|
---|
118 | string dependencies = "";
|
---|
119 | foreach (PluginInfo dependency in plugin.Dependencies) {
|
---|
120 | dependencies += dependency.Name + " (" + dependency.Version + ")\n";
|
---|
121 | }
|
---|
122 | string dependents = "";
|
---|
123 | PluginManager.Manager.GetDependentPlugins(plugin).ForEach(delegate(PluginInfo dependentPlugin) {
|
---|
124 | dependents += dependentPlugin.Name + " (" + dependentPlugin.Version + ")\n";
|
---|
125 | });
|
---|
126 | return "plugin: " + plugin.Name + "\n" +
|
---|
127 | "Version: " + plugin.Version + "\n\n" +
|
---|
128 | "Requires: \n" + dependencies + "\n" +
|
---|
129 | "Used by:\n" + dependents + "\n" +
|
---|
130 | "Files:\n" + filenames + "\n";
|
---|
131 | }
|
---|
132 |
|
---|
133 | private string GeneratePluginDetails(PluginDescription plugin) {
|
---|
134 | string dependencies = "";
|
---|
135 | foreach (string dependency in plugin.Dependencies) {
|
---|
136 | dependencies += dependency + "\n";
|
---|
137 | }
|
---|
138 | return "plugin: " + plugin.Name + "\n" +
|
---|
139 | "Version: " + plugin.Version + "\n" +
|
---|
140 | "Installed from: " + plugin.Source + "\n" +
|
---|
141 | "Requires: \n" + dependencies;
|
---|
142 | }
|
---|
143 |
|
---|
144 | private string GenerateUpgradeDetails(PluginDescription upgrade) {
|
---|
145 | string dependencies = "";
|
---|
146 | foreach(string dependency in upgrade.Dependencies) {
|
---|
147 | dependencies += dependency + "\n";
|
---|
148 | }
|
---|
149 | return "plugin: " + upgrade.Name + "\n" +
|
---|
150 | "Current version: " + plugin.Version + " will be upgraded to new version: " + upgrade.Version + "\n"+
|
---|
151 | "Upgraded from: " + upgrade.Source + "\n" +
|
---|
152 | "Requires: \n" + dependencies;
|
---|
153 | }
|
---|
154 |
|
---|
155 | private List<string> GeneratePluginDependencies(PluginInfo plugin) {
|
---|
156 | List<string> dependencies = new List<string>();
|
---|
157 |
|
---|
158 | plugin.Dependencies.ForEach(delegate(PluginInfo dependency) {
|
---|
159 | dependencies.Add(dependency.Name);
|
---|
160 | });
|
---|
161 |
|
---|
162 | return dependencies;
|
---|
163 | }
|
---|
164 |
|
---|
165 | private List<string> GeneratePluginDependencies(PluginDescription plugin) {
|
---|
166 | return new List<string>(plugin.Dependencies);
|
---|
167 | }
|
---|
168 |
|
---|
169 | internal string GetPluginDetails() {
|
---|
170 | return pluginDetails;
|
---|
171 | }
|
---|
172 |
|
---|
173 | internal List<PluginTag> GetDependentTags() {
|
---|
174 | List<PluginTag> dependentTags = new List<PluginTag>();
|
---|
175 | foreach(PluginTag tag in allTags) {
|
---|
176 | if (tag.pluginDependencies.Contains(pluginName)) {
|
---|
177 | if (!dependentTags.Contains(tag)) {
|
---|
178 | dependentTags.Add(tag);
|
---|
179 |
|
---|
180 | tag.GetDependentTags().ForEach(delegate(PluginTag dependentTag) {
|
---|
181 | if (!dependentTags.Contains(dependentTag)) {
|
---|
182 | dependentTags.Add(dependentTag);
|
---|
183 | }
|
---|
184 | });
|
---|
185 | }
|
---|
186 | }
|
---|
187 | }
|
---|
188 | return dependentTags;
|
---|
189 | }
|
---|
190 |
|
---|
191 | internal List<PluginTag> GetDependencyTags() {
|
---|
192 | List<PluginTag> dependencyTags = new List<PluginTag>();
|
---|
193 | foreach(PluginTag tag in allTags) {
|
---|
194 | if (pluginDependencies.Contains(tag.pluginName)) {
|
---|
195 | if (!dependencyTags.Contains(tag)) {
|
---|
196 | dependencyTags.Add(tag);
|
---|
197 |
|
---|
198 | tag.GetDependencyTags().ForEach(delegate(PluginTag dependencyTag) {
|
---|
199 | if (!dependencyTags.Contains(dependencyTag)) {
|
---|
200 | dependencyTags.Add(dependencyTag);
|
---|
201 | }
|
---|
202 | });
|
---|
203 | }
|
---|
204 | }
|
---|
205 | };
|
---|
206 | return dependencyTags;
|
---|
207 | }
|
---|
208 |
|
---|
209 | internal bool UpgradeAvailable() {
|
---|
210 | return UpgradePluginDescription != null;
|
---|
211 | }
|
---|
212 |
|
---|
213 | public override bool Equals(object obj) {
|
---|
214 | if (obj == null || !(obj is PluginTag)) return false;
|
---|
215 | PluginTag other = (PluginTag)obj;
|
---|
216 | return other.pluginName == pluginName && other.pluginVersion == pluginVersion;
|
---|
217 | }
|
---|
218 |
|
---|
219 | public override int GetHashCode() {
|
---|
220 | return pluginName.GetHashCode() + pluginVersion.GetHashCode();
|
---|
221 | }
|
---|
222 | }
|
---|
223 | }
|
---|