Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Manager/PluginDescription.cs @ 2517

Last change on this file since 2517 was 2517, checked in by gkronber, 14 years ago

Worked on plugin installation manager and update location service. #799

File size: 5.8 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.Manager {
27  /// <summary>
28  /// Holds information of loaded plugins that is needed for plugin management.
29  /// Used to represent plugins in AppDomains without loading the plugin assemblies.
30  /// </summary>
31  [Serializable]
32  public sealed class PluginDescription : IPluginDescription {
33    private int nTimesLoaded;
34
35    private string name;
36    /// <summary>
37    /// Gets or sets the name of the plugin.
38    /// </summary>
39    public string Name {
40      get { return name; }
41      internal set { name = value; }
42    }
43
44    private string description;
45    /// <summary>
46    /// Gets or sets the description of the plugin.
47    /// </summary>
48    internal string Description {
49      get { return description; }
50      set { description = value; }
51    }
52    private Version version;
53    /// <summary>
54    /// Gets or sets the version of the plugin.
55    /// </summary>
56    internal Version Version {
57      get { return version; }
58      set { version = value; }
59    }
60    private DateTime buildDate;
61    /// <summary>
62    /// Gets or sets the build date of the plugin.
63    /// </summary>
64    internal DateTime BuildDate {
65      get { return buildDate; }
66      set { buildDate = value; }
67    }
68
69    private PluginState pluginState;
70    /// <summary>
71    /// Gets or sets the plugin state.
72    /// </summary>
73    public PluginState PluginState {
74      get { return pluginState; }
75    }
76
77
78    private List<string> files = new List<string>();
79    /// <summary>
80    /// Gets the names of all files that belong to this plugin.
81    /// These files are deleted when the plugin is removed or updated.
82    /// </summary>
83    internal IEnumerable<string> Files {
84      get { return files; }
85    }
86
87    internal void AddFiles(IEnumerable<string> fileNames) {
88      files.AddRange(fileNames);
89    }
90
91    private List<PluginDescription> dependencies = new List<PluginDescription>();
92    /// <summary>
93    /// Gets all dependencies of the plugin.
94    /// </summary>
95    internal IEnumerable<PluginDescription> Dependencies {
96      get { return dependencies; }
97    }
98
99    internal void AddDependency(PluginDescription dependency) {
100      dependencies.Add(dependency);
101    }
102
103
104    private List<string> assemblies = new List<string>();
105    /// <summary>
106    /// Gets the names of the assemblies that belong to this plugin.
107    /// </summary>
108    internal IEnumerable<string> Assemblies {
109      get { return assemblies; }
110      // set { assemblies = value; }
111    }
112
113    internal void AddAssemblies(IEnumerable<string> assemblyNames) {
114      assemblies.AddRange(assemblyNames);
115    }
116
117    internal PluginDescription() {
118      pluginState = PluginState.Undefined;
119    }
120
121    internal void Disable() {
122      if (pluginState != PluginState.Undefined)
123        throw new InvalidOperationException("Can't disabled a plugin in state " + pluginState);
124      pluginState = PluginState.Disabled;
125    }
126
127    internal void Enable() {
128      if (pluginState != PluginState.Undefined)
129        throw new InvalidOperationException("Can't enabled a plugin in state " + pluginState);
130      pluginState = PluginState.Enabled;
131    }
132
133    internal void Load() {
134      if (!(pluginState == PluginState.Enabled || pluginState == PluginState.Loaded))
135        throw new InvalidOperationException("Can't loaded a plugin in state " + pluginState);
136      pluginState = PluginState.Loaded;
137      nTimesLoaded++;
138    }
139
140    internal void Unload() {
141      if (pluginState != PluginState.Loaded)
142        throw new InvalidOperationException("Can't unload a plugin in state " + pluginState);
143      nTimesLoaded--;
144      if (nTimesLoaded == 0) pluginState = PluginState.Enabled;
145    }
146
147
148    /// <summary>
149    /// Gets the string representation of the plugin.
150    /// </summary>
151    /// <returns>The name of the plugin.</returns>
152    public override string ToString() {
153      return Name;
154    }
155
156    // equals and hashcode have to be implemented because we want to compare PluginDescriptions from
157    // different AppDomains and serialization destroys reference equality
158    /// <summary>
159    /// Checks whether the given object is equal to the current plugin.
160    /// </summary>
161    /// <param name="obj">The object to compare.</param>
162    /// <returns><c>true</c> if it is equal, <c>false</c> otherwise.</returns>
163    public override bool Equals(object obj) {
164      PluginDescription other = obj as PluginDescription;
165      if (other == null) return false;
166
167      return other.Name == this.Name && other.Version == this.Version;
168    }
169    /// <summary>
170    /// Gets the hash code of the current plugin.
171    /// </summary>
172    /// <returns>The hash code of the plugin.</returns>
173    public override int GetHashCode() {
174      if (version != null) {
175        return name.GetHashCode() + version.GetHashCode();
176      } else return name.GetHashCode();
177    }
178  }
179}
Note: See TracBrowser for help on using the repository browser.