source: trunk/CrypPlugins/ArrayIndexer/ArrayIndexer.cs @ 777

Last change on this file since 777 was 777, checked in by Matthäus Wander, 12 years ago
  • enabled more generic usage of ArrayIndexer and LengthOf
  • added ArrayIndexer, HMAC, LengthOf to setup
File size: 5.4 KB
Line 
1/*
2   Copyright 2009 Christian Arnold, Uni Duisburg-Essen
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;
21using Cryptool.PluginBase.IO;
22using Cryptool.PluginBase;
23using Cryptool.PluginBase.Miscellaneous;
24using System.ComponentModel;
25
26namespace Cryptool.Plugins.ArrayIndexer
27{
28    [Author("Christian Arnold", "christian.arnold@stud.uni-due.de", "Uni Duisburg-Essen", "")]
29    [PluginInfo(false, "ArrayIndexer", "Content of the chosen index of the array", "", "ArrayIndexer/arrayindexer.png")]
30
31    public class ArrayIndexer : IThroughput
32    {
33        #region IPlugin Members
34
35        private ArrayIndexerSettings settings = new ArrayIndexerSettings();
36
37        private Array objInput = null;
38        private int arrayIndex = 0;
39        private object objOutput = null;
40
41        #region In and Out properties
42
43        [PropertyInfo(Direction.InputData, "Array Input", "The input object has to be an array type", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
44        public Array ObjInput
45        {
46            get
47            {
48                return objInput;
49            }
50            set
51            {
52                objInput = value;
53                OnPropertyChanged("ObjInput");
54            }
55        }
56
57        [PropertyInfo(Direction.InputData, "Index of Array", "Indexes of an array begin always with 0. Example: If you have an array of the length 8, you can index the values 0 to 7", "", DisplayLevel.Beginner)]
58        public int ArrayIndex
59        {
60            get
61            {
62                return this.arrayIndex;
63            }
64            set
65            {
66                this.arrayIndex = value;
67                settings.ArrayIndex = value;
68                OnPropertyChanged("ArrayIndex");
69            }
70        }
71
72        [PropertyInfo(Direction.OutputData, "Content of the chosen index of the array", "Content with the array-specific data type", "", DisplayLevel.Beginner)]
73        public object ObjOutput
74        {
75            get
76            {
77                return this.objOutput;
78            }
79            set
80            {
81                this.objOutput = value;
82                OnPropertyChanged("ObjOutput");
83            }
84        }
85
86        #endregion
87
88        public event StatusChangedEventHandler OnPluginStatusChanged;
89
90        public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
91
92        public event PluginProgressChangedEventHandler OnPluginProgressChanged;
93
94        public Cryptool.PluginBase.ISettings Settings
95        {
96            get { return this.settings; }
97            set { this.settings = (ArrayIndexerSettings)value; }
98        }
99
100        public System.Windows.Controls.UserControl Presentation
101        {
102            get { return null; }
103        }
104
105        public System.Windows.Controls.UserControl QuickWatchPresentation
106        {
107            get { return null; }
108        }
109
110        public void PreExecution()
111        {
112        }
113
114        public void Execute()
115        {
116            if (ObjInput != null)
117            {
118                // error case, if array index is greater than the length of the array
119                if (ObjInput.Length <= settings.ArrayIndex)
120                {
121                    GuiLogMessage("Array Index is greater than the length of the array", NotificationLevel.Error);
122                    return;
123                }
124
125                ObjOutput = ObjInput.GetValue(settings.ArrayIndex);
126
127                GuiLogMessage("Array type is " + ObjInput.GetType().ToString() + " with value: " + ObjOutput.ToString(), NotificationLevel.Debug);
128            }
129        }
130
131        public void PostExecution()
132        {
133        }
134
135        public void Pause()
136        {
137        }
138
139        public void Stop()
140        {
141        }
142
143        public void Initialize()
144        {
145        }
146
147        public void Dispose()
148        {
149        }
150
151        #endregion
152
153        #region INotifyPropertyChanged Members
154
155        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
156
157        public void OnPropertyChanged(string name)
158        {
159            EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
160        }
161
162        public event PluginProgressChangedEventHandler OnPluginProcessChanged;
163
164        private void ProgressChanged(double value, double max)
165        {
166            EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(value, max));
167        }
168
169        private void GuiLogMessage(string p, NotificationLevel notificationLevel)
170        {
171            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(p, this, notificationLevel));
172        }
173
174        #endregion
175    }
176}
Note: See TracBrowser for help on using the repository browser.