source: trunk/CrypPlugins/CrypPluginTemplate/ExamplePluginCT2.cs @ 1507

Last change on this file since 1507 was 1507, checked in by Matthäus Wander, 12 years ago

Updated plugin template. The template shall become the default way to create a new CT2 plugin.

File size: 5.5 KB
Line 
1/* HOWTO: Change year, author name and organization.
2   Copyright 2010 Your Name, University of Duckburg
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15*/
16using System;
17using System.Collections.Generic;
18using System.Linq;
19using System.Text;
20using Cryptool.PluginBase.IO;
21using Cryptool.PluginBase;
22using System.ComponentModel;
23using Cryptool.PluginBase.Miscellaneous;
24using System.Windows.Controls;
25
26namespace Cryptool.Plugin
27{
28    // HOWTO: Change author name, email address, organization and URL.
29    [Author("Matthäus Wander", "wander@cryptool.org", "Universität Duisburg-Essen, Fachgebiet Verteilte Systeme", "http://www.vs.uni-due.de")]
30    // HOWTO: Change plugin caption (title to appear in CT2) and tooltip. You can (and should) provide a description XAML and an own icon as well.
31    [PluginInfo(false, "Example Plugin", "Subtract one number from another", null, "CrypWin/images/default.png")]
32    // HOWTO: Change interface to one that fits to your plugin (see CrypPluginBase).
33    public class ExamplePluginCT2 : IIOMisc
34    {
35        #region Private Variables
36
37        // HOWTO: You need to adapt the settings class as well, see the corresponding file.
38        private readonly ExamplePluginCT2Settings settings = new ExamplePluginCT2Settings();
39
40        #endregion
41
42        #region Data Properties
43
44        /// <summary>
45        /// HOWTO: Input interface to read the input data.
46        /// You can add more input properties of other type if needed.
47        /// </summary>
48        [PropertyInfo(Direction.InputData, "Minuend", "Input number", null, DisplayLevel.Beginner)]
49        public int Minuend
50        {
51            get;
52            set;
53        }
54
55        /// <summary>
56        /// HOWTO: Output interface to write the output data.
57        /// You can add more output properties ot other type if needed.
58        /// </summary>
59        [PropertyInfo(Direction.OutputData, "Difference", "Result", null, DisplayLevel.Beginner)]
60        public int Difference
61        {
62            get;
63            set;
64        }
65
66        #endregion
67
68        #region IPlugin Members
69
70        public ISettings Settings
71        {
72            get { return settings; }
73        }
74
75        /// <summary>
76        /// HOWTO: You can provide a custom (tabbed) presentation to visualize your algorithm.
77        /// Return null if you don't provide one.
78        /// </summary>
79        public UserControl Presentation
80        {
81            get { return null; }
82        }
83
84        /// <summary>
85        /// HOWTO: You can provide custom (quickwatch) presentation to visualize your algorithm.
86        /// Return null if you don't provide one.
87        /// </summary>
88        public UserControl QuickWatchPresentation
89        {
90            get { return null; }
91        }
92
93        public void PreExecution()
94        {
95        }
96
97        /// <summary>
98        /// HOWTO: Enter the algorithm you'd like to implement in this method.
99        /// </summary>
100        public void Execute()
101        {
102            // HOWTO: Use this to show the progress of a plugin algorithm execution in the editor.
103            ProgressChanged(0, 1);
104
105            // HOWTO: After you have changed an output property, make sure you announce the name of the changed property to the CT2 core.
106            Difference = Minuend - settings.Subtrahend;
107            OnPropertyChanged("Difference");
108
109            // HOWTO: You can pass error, warning, info or debug messages to the CT2 main window.
110            if (settings.Subtrahend < 0)
111                GuiLogMessage("Subtrahend is negative", NotificationLevel.Debug);
112
113            // HOWTO: Make sure the progress bar is at maximum when your Execute() finished successfully.
114            ProgressChanged(1, 1);
115        }
116
117        public void PostExecution()
118        {
119        }
120
121        public void Pause()
122        {
123        }
124
125        public void Stop()
126        {
127        }
128
129        public void Initialize()
130        {
131        }
132
133        public void Dispose()
134        {
135        }
136
137        #endregion
138
139        #region Event Handling
140
141        public event StatusChangedEventHandler OnPluginStatusChanged;
142
143        public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
144
145        public event PluginProgressChangedEventHandler OnPluginProgressChanged;
146
147        public event PropertyChangedEventHandler PropertyChanged;
148
149        private void GuiLogMessage(string message, NotificationLevel logLevel)
150        {
151            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(message, this, logLevel));
152        }
153
154        private void OnPropertyChanged(string name)
155        {
156            EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
157        }
158
159        private void ProgressChanged(double value, double max)
160        {
161            EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(value, max));
162        }
163
164        #endregion
165    }
166}
Note: See TracBrowser for help on using the repository browser.