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.Diagnostics;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.PluginInfrastructure {
|
---|
28 | public abstract class ApplicationBase : IApplication {
|
---|
29 | private string name;
|
---|
30 | private Version version;
|
---|
31 | private string description;
|
---|
32 | private bool autoRestart;
|
---|
33 |
|
---|
34 | public ApplicationBase() {
|
---|
35 | ReadAttributes();
|
---|
36 | Run();
|
---|
37 | }
|
---|
38 |
|
---|
39 | private void ReadAttributes() {
|
---|
40 | object[] pluginAttributes = this.GetType().GetCustomAttributes(typeof(ClassInfoAttribute), false);
|
---|
41 |
|
---|
42 | // exactly one attribute of the type ClassInfoAttribute must be given
|
---|
43 | if(pluginAttributes.Length != 1) {
|
---|
44 | throw new InvalidPluginException();
|
---|
45 | }
|
---|
46 |
|
---|
47 | // after the assertion we are sure that the array access will not fail
|
---|
48 | ClassInfoAttribute pluginAttribute = (ClassInfoAttribute)pluginAttributes[0];
|
---|
49 | if(pluginAttribute != null) {
|
---|
50 | // if the plugin name is not explicitly set in the attribute then the default plugin name is the FullName of the type
|
---|
51 | if(pluginAttribute.Name != null) {
|
---|
52 | this.name = pluginAttribute.Name;
|
---|
53 | } else {
|
---|
54 | this.name = this.GetType().FullName;
|
---|
55 | }
|
---|
56 |
|
---|
57 | // if the version is not explicitly set in the attribute then the version of the assembly is used as default
|
---|
58 | if(pluginAttribute.Version != null) {
|
---|
59 | this.version = new Version(pluginAttribute.Version);
|
---|
60 | } else {
|
---|
61 | this.version = this.GetType().Assembly.GetName().Version;
|
---|
62 | }
|
---|
63 |
|
---|
64 | // if the description is not explicitly set in the attribute then the name of name of the application is used as default
|
---|
65 | if(pluginAttribute.Description != null) {
|
---|
66 | this.description = pluginAttribute.Description;
|
---|
67 | } else {
|
---|
68 | this.description = name;
|
---|
69 | }
|
---|
70 |
|
---|
71 | this.autoRestart = pluginAttribute.AutoRestart;
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | #region IApplication Members
|
---|
77 |
|
---|
78 | public string Name {
|
---|
79 | get { return name; }
|
---|
80 | }
|
---|
81 |
|
---|
82 | public Version Version {
|
---|
83 | get { return version; }
|
---|
84 | }
|
---|
85 |
|
---|
86 | public string Description {
|
---|
87 | get { return description; }
|
---|
88 | }
|
---|
89 |
|
---|
90 | public bool AutoRestart {
|
---|
91 | get { return autoRestart; }
|
---|
92 | }
|
---|
93 |
|
---|
94 | public abstract void Run();
|
---|
95 |
|
---|
96 | #endregion
|
---|
97 | }
|
---|
98 | }
|
---|