[2] | 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 |
|
---|
[2481] | 26 | namespace HeuristicLab.PluginInfrastructure.Manager {
|
---|
[2] | 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]
|
---|
[2488] | 32 | public class PluginDescription : IPluginDescription {
|
---|
[2] | 33 | private string name;
|
---|
[1189] | 34 | /// <summary>
|
---|
| 35 | /// Gets or sets the name of the plugin.
|
---|
| 36 | /// </summary>
|
---|
[2] | 37 | public string Name {
|
---|
| 38 | get { return name; }
|
---|
| 39 | set { name = value; }
|
---|
| 40 | }
|
---|
| 41 | private Version version;
|
---|
[1189] | 42 | /// <summary>
|
---|
| 43 | /// Gets or sets the version of the plugin.
|
---|
| 44 | /// </summary>
|
---|
[2] | 45 | public Version Version {
|
---|
| 46 | get { return version; }
|
---|
| 47 | set { version = value; }
|
---|
| 48 | }
|
---|
[91] | 49 | private DateTime buildDate;
|
---|
[1189] | 50 | /// <summary>
|
---|
| 51 | /// Gets or sets the build date of the plugin.
|
---|
| 52 | /// </summary>
|
---|
[91] | 53 | public DateTime BuildDate {
|
---|
| 54 | get { return buildDate; }
|
---|
| 55 | set { buildDate = value; }
|
---|
| 56 | }
|
---|
[2481] | 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 |
|
---|
[2488] | 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 |
|
---|
[91] | 93 | private List<string> files = new List<string>();
|
---|
[2] | 94 | /// <summary>
|
---|
[1189] | 95 | /// Gets the names of all files that belong to this plugin.
|
---|
[2] | 96 | /// These files are deleted when the plugin is removed or updated.
|
---|
| 97 | /// </summary>
|
---|
[2481] | 98 | public IEnumerable<string> Files {
|
---|
[2] | 99 | get { return files; }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[2481] | 102 | internal void AddFiles(IEnumerable<string> fileNames) {
|
---|
| 103 | files.AddRange(fileNames);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[2488] | 106 | private List<IPluginDescription> dependencies = new List<IPluginDescription>();
|
---|
[1189] | 107 | /// <summary>
|
---|
| 108 | /// Gets all dependencies of the plugin.
|
---|
| 109 | /// </summary>
|
---|
[2488] | 110 | public IEnumerable<IPluginDescription> Dependencies {
|
---|
[2] | 111 | get { return dependencies; }
|
---|
| 112 | }
|
---|
[2481] | 113 |
|
---|
| 114 | public void AddDependency(PluginDescription dependency) {
|
---|
| 115 | dependencies.Add(dependency);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 |
|
---|
[2] | 119 | private List<string> assemblies = new List<string>();
|
---|
| 120 | /// <summary>
|
---|
[1189] | 121 | /// Gets the names of the assemblies that belong to this plugin.
|
---|
[2] | 122 | /// </summary>
|
---|
[2481] | 123 | public IEnumerable<string> Assemblies {
|
---|
[2] | 124 | get { return assemblies; }
|
---|
[2481] | 125 | // set { assemblies = value; }
|
---|
[2] | 126 | }
|
---|
[2481] | 127 |
|
---|
| 128 | internal void AddAssemblies(IEnumerable<string> assemblyNames) {
|
---|
| 129 | assemblies.AddRange(assemblyNames);
|
---|
[37] | 130 | }
|
---|
[2481] | 131 |
|
---|
[2488] | 132 | public PluginDescription() {
|
---|
| 133 | nTimesLoaded = 0;
|
---|
| 134 | pluginState = PluginState.Undefined;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 |
|
---|
[2481] | 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 |
|
---|
[1189] | 147 | /// <summary>
|
---|
| 148 | /// Gets the string representation of the plugin.
|
---|
| 149 | /// </summary>
|
---|
| 150 | /// <returns>The name of the plugin.</returns>
|
---|
[2] | 151 | public override string ToString() {
|
---|
| 152 | return Name;
|
---|
| 153 | }
|
---|
[2481] | 154 |
|
---|
[2488] | 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;
|
---|
[2] | 166 |
|
---|
[2488] | 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 | //}
|
---|
[2] | 178 | }
|
---|
| 179 | }
|
---|