[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2] | 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 |
|
---|
[16984] | 23 | using System;
|
---|
| 24 |
|
---|
[2] | 25 | namespace HeuristicLab.PluginInfrastructure {
|
---|
[1189] | 26 | /// <summary>
|
---|
[2504] | 27 | /// Abstract base implementation for the IApplication interface.
|
---|
[1189] | 28 | /// </summary>
|
---|
[16984] | 29 | [Serializable]
|
---|
[2488] | 30 | public abstract class ApplicationBase : IApplication {
|
---|
[1189] | 31 | /// <summary>
|
---|
| 32 | /// Initializes a new instance of <see cref="ApplicationBase"/>.
|
---|
| 33 | /// </summary>
|
---|
[2504] | 34 | protected ApplicationBase() { }
|
---|
[2] | 35 |
|
---|
[2488] | 36 | private ApplicationAttribute ApplicationAttribute {
|
---|
[2475] | 37 | get {
|
---|
[2488] | 38 | object[] appAttributes = this.GetType().GetCustomAttributes(typeof(ApplicationAttribute), false);
|
---|
[2] | 39 |
|
---|
[2475] | 40 | // exactly one attribute of the type ClassInfoAttribute must be given
|
---|
[2504] | 41 | if (appAttributes.Length == 0) {
|
---|
| 42 | throw new InvalidPluginException("ApplicationAttribute on type " + this.GetType() + " is missing.");
|
---|
| 43 | } else if (appAttributes.Length > 1) {
|
---|
[2488] | 44 | throw new InvalidPluginException("Found multiple ApplicationAttributes on type " + this.GetType());
|
---|
[242] | 45 | }
|
---|
[2] | 46 |
|
---|
[2488] | 47 | return (ApplicationAttribute)appAttributes[0];
|
---|
[2] | 48 | }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | #region IApplication Members
|
---|
| 52 |
|
---|
[1189] | 53 | /// <summary>
|
---|
| 54 | /// Gets the name of the application.
|
---|
| 55 | /// </summary>
|
---|
[2] | 56 | public string Name {
|
---|
[2488] | 57 | get { return ApplicationAttribute.Name; }
|
---|
[2] | 58 | }
|
---|
| 59 |
|
---|
[1189] | 60 | /// <summary>
|
---|
| 61 | /// Gets the description of the application.
|
---|
| 62 | /// </summary>
|
---|
[2] | 63 | public string Description {
|
---|
[2475] | 64 | get {
|
---|
[2504] | 65 | return ApplicationAttribute.Description;
|
---|
[2475] | 66 | }
|
---|
[2] | 67 | }
|
---|
| 68 |
|
---|
[1189] | 69 | /// <summary>
|
---|
| 70 | /// Runs the application.
|
---|
| 71 | /// </summary>
|
---|
[8818] | 72 | public abstract void Run(ICommandLineArgument[] args);
|
---|
[242] | 73 |
|
---|
[16984] | 74 | public virtual void OnCancel() { Console.WriteLine("OnCancellation"); }
|
---|
| 75 | public virtual void OnPause() { Console.WriteLine("OnPause"); }
|
---|
| 76 | public virtual void OnResume() { Console.WriteLine("OnResume"); }
|
---|
| 77 |
|
---|
[2] | 78 | #endregion
|
---|
| 79 | }
|
---|
| 80 | }
|
---|