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

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

CrypWin:

  • minor fix to startup routine (mainly cosmetic)

Template:

  • removed PostBuild events
  • minor changes to namespaces
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;
21using System.ComponentModel;
22using Cryptool.PluginBase.IO;
23using Cryptool.PluginBase.Miscellaneous;
24using System.ComponentModel;
25using System.Windows.Controls;
26
27namespace Cryptool.Plugins.ExamplePluginCT2
28{
29    // HOWTO: Change author name, email address, organization and URL.
30    [Author("Matthäus Wander", "wander@cryptool.org", "Universität Duisburg-Essen, Fachgebiet Verteilte Systeme", "http://www.vs.uni-due.de")]
31    // 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.
32    [PluginInfo(false, "Example Plugin", "Subtract one number from another", null, "CrypWin/images/default.png")]
33    // HOWTO: Change interface to one that fits to your plugin (see CrypPluginBase).
34    public class ExamplePluginCT2 : IIOMisc
35    {
36        #region Private Variables
37
38        // HOWTO: You need to adapt the settings class as well, see the corresponding file.
39        private readonly ExamplePluginCT2Settings settings = new ExamplePluginCT2Settings();
40
41        #endregion
42
43        #region Data Properties
44
45        /// <summary>
46        /// HOWTO: Input interface to read the input data.
47        /// You can add more input properties of other type if needed.
48        /// </summary>
49        [PropertyInfo(Direction.InputData, "Minuend", "Input number", null, DisplayLevel.Beginner)]
50        public int Minuend
51        {
52            get;
53            set;
54        }
55
56        /// <summary>
57        /// HOWTO: Output interface to write the output data.
58        /// You can add more output properties ot other type if needed.
59        /// </summary>
60        [PropertyInfo(Direction.OutputData, "Difference", "Result", null, DisplayLevel.Beginner)]
61        public int Difference
62        {
63            get;
64            set;
65        }
66
67        #endregion
68
69        #region IPlugin Members
70
71        public ISettings Settings
72        {
73            get { return settings; }
74        }
75
76        /// <summary>
77        /// HOWTO: You can provide a custom (tabbed) presentation to visualize your algorithm.
78        /// Return null if you don't provide one.
79        /// </summary>
80        public UserControl Presentation
81        {
82            get { return null; }
83        }
84
85        /// <summary>
86        /// HOWTO: You can provide custom (quickwatch) presentation to visualize your algorithm.
87        /// Return null if you don't provide one.
88        /// </summary>
89        public UserControl QuickWatchPresentation
90        {
91            get { return null; }
92        }
93
94        public void PreExecution()
95        {
96        }
97
98        /// <summary>
99        /// HOWTO: Enter the algorithm you'd like to implement in this method.
100        /// </summary>
101        public void Execute()
102        {
103            // HOWTO: Use this to show the progress of a plugin algorithm execution in the editor.
104            ProgressChanged(0, 1);
105
106            // HOWTO: After you have changed an output property, make sure you announce the name of the changed property to the CT2 core.
107            Difference = Minuend - settings.Subtrahend;
108            OnPropertyChanged("Difference");
109
110            // HOWTO: You can pass error, warning, info or debug messages to the CT2 main window.
111            if (settings.Subtrahend < 0)
112                GuiLogMessage("Subtrahend is negative", NotificationLevel.Debug);
113
114            // HOWTO: Make sure the progress bar is at maximum when your Execute() finished successfully.
115            ProgressChanged(1, 1);
116        }
117
118        public void PostExecution()
119        {
120        }
121
122        public void Pause()
123        {
124        }
125
126        public void Stop()
127        {
128        }
129
130        public void Initialize()
131        {
132        }
133
134        public void Dispose()
135        {
136        }
137
138        #endregion
139
140        #region Event Handling
141
142        public event StatusChangedEventHandler OnPluginStatusChanged;
143
144        public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
145
146        public event PluginProgressChangedEventHandler OnPluginProgressChanged;
147
148        public event PropertyChangedEventHandler PropertyChanged;
149
150        private void GuiLogMessage(string message, NotificationLevel logLevel)
151        {
152            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(message, this, logLevel));
153        }
154
155        private void OnPropertyChanged(string name)
156        {
157            EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
158        }
159
160        private void ProgressChanged(double value, double max)
161        {
162            EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(value, max));
163        }
164
165        #endregion
166    }
167}
Note: See TracBrowser for help on using the repository browser.