[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 | using System.Reflection;
|
---|
| 26 | using System.Diagnostics;
|
---|
[2475] | 27 | using System.Linq;
|
---|
[2] | 28 |
|
---|
| 29 | namespace HeuristicLab.PluginInfrastructure {
|
---|
| 30 | /// <summary>
|
---|
| 31 | /// Default implementation of the IPlugin interface.
|
---|
| 32 | /// </summary>
|
---|
[1229] | 33 | public abstract class PluginBase : IPlugin {
|
---|
[1189] | 34 | /// <summary>
|
---|
| 35 | /// Initializes a new instance of <see cref="PluginBase"/>.
|
---|
| 36 | /// </summary>
|
---|
[2475] | 37 | public PluginBase() { }
|
---|
[2] | 38 |
|
---|
[2488] | 39 | private PluginAttribute PluginAttribute {
|
---|
[2475] | 40 | get {
|
---|
[2488] | 41 | object[] pluginAttributes = this.GetType().GetCustomAttributes(typeof(PluginAttribute), false);
|
---|
[2475] | 42 | // exactly one attribute of the type PluginDescriptionAttribute must be given
|
---|
| 43 | if (pluginAttributes.Length != 1) {
|
---|
[2488] | 44 | throw new InvalidPluginException("Found multiple PluginAttributes on type " + this.GetType());
|
---|
[2475] | 45 | }
|
---|
[2488] | 46 | return (PluginAttribute)pluginAttributes[0];
|
---|
[8] | 47 | }
|
---|
[2] | 48 | }
|
---|
| 49 |
|
---|
| 50 | #region IPlugin Members
|
---|
[2475] | 51 | /// <inheritdoc />
|
---|
[2] | 52 | public string Name {
|
---|
| 53 | get {
|
---|
[2488] | 54 | return PluginAttribute.Name;
|
---|
[2] | 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[2481] | 58 | ///// <inheritdoc />
|
---|
| 59 | //public Version Version {
|
---|
| 60 | // get {
|
---|
| 61 | // var pluginAttribute = PluginDescriptionAttribute;
|
---|
| 62 | // // if the version is not set in the attribute then the version of the assembly is used as default
|
---|
| 63 | // if (string.IsNullOrEmpty(pluginAttribute.Version)) {
|
---|
| 64 | // return this.GetType().Assembly.GetName().Version;
|
---|
| 65 | // } else {
|
---|
| 66 | // return new Version(pluginAttribute.Version);
|
---|
| 67 | // }
|
---|
| 68 | // }
|
---|
| 69 | //}
|
---|
[2] | 70 |
|
---|
[2481] | 71 | ///// <inheritdoc />
|
---|
| 72 | //public string Description {
|
---|
| 73 | // get {
|
---|
| 74 | // var pluginAttribute = PluginDescriptionAttribute;
|
---|
| 75 | // // if the description is not explicitly set in the attribute then the name of the plugin is used as default
|
---|
| 76 | // if (string.IsNullOrEmpty(pluginAttribute.Description)) {
|
---|
| 77 | // return pluginAttribute.Name;
|
---|
| 78 | // } else {
|
---|
| 79 | // return pluginAttribute.Description;
|
---|
| 80 | // }
|
---|
| 81 | // }
|
---|
| 82 | //}
|
---|
[2] | 83 |
|
---|
[1189] | 84 | /// <inheritdoc/>
|
---|
[2475] | 85 | public IEnumerable<string> FileNames {
|
---|
[2] | 86 | get {
|
---|
[2475] | 87 | // get all attributes of type PluginFileAttribute, multiple usage is possible
|
---|
| 88 | return from x in this.GetType().GetCustomAttributes(typeof(PluginFileAttribute), false)
|
---|
| 89 | let pluginFileAttr = (PluginFileAttribute)x
|
---|
| 90 | select pluginFileAttr.Filename;
|
---|
[2] | 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[2475] | 94 | /// <inhertitdoc>
|
---|
[1229] | 95 | public virtual void OnLoad() { }
|
---|
[2] | 96 | #endregion
|
---|
| 97 |
|
---|
| 98 | }
|
---|
| 99 | }
|
---|