Free cookie consent management tool by TermsFeed Policy Generator

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

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

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