Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2505 was 2504, checked in by gkronber, 15 years ago

Worked on core of plugin infrastructure.

  • Collected all classes into a single assembly (HL.PluginInfrastructure)
  • Moved SplashScreen and MainForm from HeuristicLab.exe project into the plugin infrastructure.
  • Introduced namespaces
  • Added strict access modifiers (internal)
  • Fixed most FxCop warnings in plugin infrastructure core.
  • Fixed issues with plugin load/unload events
  • Deleted empty interface IControl

#799

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