Free cookie consent management tool by TermsFeed Policy Generator

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

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

Refactored class Loader in plugin infrastructure. #799

File size: 4.7 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 {
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      set { pluginState = value; }
65    }
66
67    private List<string> files = new List<string>();
68    /// <summary>
69    /// Gets the names of all files that belong to this plugin.
70    /// These files are deleted when the plugin is removed or updated.
71    /// </summary>
72    public IEnumerable<string> Files {
73      get { return files; }
74    }
75
76    internal void AddFiles(IEnumerable<string> fileNames) {
77      files.AddRange(fileNames);
78    }
79
80    private List<PluginDescription> dependencies = new List<PluginDescription>();
81    /// <summary>
82    /// Gets all dependencies of the plugin.
83    /// </summary>
84    public IEnumerable<PluginDescription> Dependencies {
85      get { return dependencies; }
86    }
87
88    public void AddDependency(PluginDescription dependency) {
89      dependencies.Add(dependency);
90    }
91
92
93    private List<string> assemblies = new List<string>();
94    /// <summary>
95    /// Gets the names of the assemblies that belong to this plugin.
96    /// </summary>
97    public IEnumerable<string> Assemblies {
98      get { return assemblies; }
99      // set { assemblies = value; }
100    }
101
102    internal void AddAssemblies(IEnumerable<string> assemblyNames) {
103      assemblies.AddRange(assemblyNames);
104    }
105
106    //private string message;
107    ///// <summary>
108    ///// Gets or sets the message.
109    ///// </summary>
110    //public string Message {
111    //  get { return message; }
112    //  set { message = value; }
113    //}
114
115    /// <summary>
116    /// Gets the string representation of the plugin.
117    /// </summary>
118    /// <returns>The name of the plugin.</returns>
119    public override string ToString() {
120      return Name;
121    }
122
123    // equals and hashcode have to be implemented because we want to compare PluginDescriptions from
124    // different AppDomains and serialization destroys reference equality
125    /// <summary>
126    /// Checks whether the given object is equal to the current plugin.
127    /// </summary>
128    /// <param name="obj">The object to compare.</param>
129    /// <returns><c>true</c> if it is equal, <c>false</c> otherwise.</returns>
130    public override bool Equals(object obj) {
131      if (!(obj is PluginDescription))
132        return false;
133      PluginDescription other = (PluginDescription)obj;
134
135      return other.Name == this.Name && other.Version == this.Version;
136    }
137    /// <summary>
138    /// Gets the hash code of the current plugin.
139    /// </summary>
140    /// <returns>The hash code of the plugin.</returns>
141    public override int GetHashCode() {
142      if (version != null) {
143        return name.GetHashCode() + version.GetHashCode();
144      } else return name.GetHashCode();
145    }
146  }
147}
Note: See TracBrowser for help on using the repository browser.