source: trunk/CrypPlugins/PeerToPeer_DHTretrieve/P2P_DHTload.cs @ 798

Last change on this file since 798 was 798, checked in by arnold, 12 years ago

P2P DHT_Retrieve added instead of SVN-internal-error-project DHTload

File size: 6.7 KB
Line 
1/* Copyright 2009 Team CrypTool (Christian Arnold), Uni Duisburg-Essen
2
3   Licensed under the Apache License, Version 2.0 (the "License");
4   you may not use this file except in compliance with the License.
5   You may obtain a copy of the License at
6
7       http://www.apache.org/licenses/LICENSE-2.0
8
9   Unless required by applicable law or agreed to in writing, software
10   distributed under the License is distributed on an "AS IS" BASIS,
11   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   See the License for the specific language governing permissions and
13   limitations under the License.
14*/
15
16
17using System;
18using System.Collections.Generic;
19using System.Linq;
20using System.Text;
21using Cryptool;
22using Cryptool.PluginBase.IO;
23using Cryptool.PluginBase;
24using Cryptool.PluginBase.Miscellaneous;
25using System.ComponentModel;
26using Cryptool.PluginBase.Tool;
27using Cryptool.PluginBase.Control;
28
29namespace Cryptool.Plugins.PeerToPeer
30{
31    /// <summary>
32    /// This PlugIn only works, when its connected with a P2P_Peer object.
33    /// </summary>
34    [Author("Christian Arnold", "arnold@cryptool.org", "Uni Duisburg-Essen", "http://www.uni-due.de")]
35    [PluginInfo(false, "P2P_DHTload", "Loading data out of the DHT", "", "PeerToPeer_DHTretrieve/ct2_dht_load_icon_medium.png")]
36    public class P2P_DHTload : IThroughput
37    {
38        private P2PDHTloadSettings settings;
39
40        #region In and Output
41
42        private IP2PControl p2pMaster;
43        /// <summary>
44        /// Catches the completely configurated, initialized and joined P2P object from the P2PPeer-Slave-PlugIn.
45        /// </summary>
46        [PropertyInfo(Direction.ControlMaster, "P2P Slave", "Input the P2P-Peer-PlugIn", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
47        public IP2PControl P2PMaster
48        {
49            get
50            {
51                return this.p2pMaster;
52            }
53            set
54            {
55                if (p2pMaster != null)
56                {
57                    p2pMaster.OnStatusChanged -= P2PMaster_OnStatusChanged;
58                }
59                if (value != null)
60                {
61                    value.OnStatusChanged += new IControlStatusChangedEventHandler(P2PMaster_OnStatusChanged);
62                    p2pMaster = (P2PPeerMaster)value;
63                    OnPropertyChanged("P2PMaster");
64                }
65                else
66                {
67                    p2pMaster = null;
68                }
69            }
70        }
71
72        private void P2PMaster_OnStatusChanged(IControl sender, bool readyForExecution)
73        {
74            //throw new NotImplementedException();
75        }
76
77        private string sDhtKey;
78        [PropertyInfo(Direction.InputData, "Key Name", "Key Name of DHT Entry in the P2P-System", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
79        public string DhtKey
80        {
81            get
82            {
83                return this.sDhtKey;
84            }
85            set
86            {
87                this.sDhtKey = value;
88                OnPropertyChanged("DhtKey");
89            }
90        }
91
92        private byte[] bDhtValue;
93        [PropertyInfo(Direction.OutputData, "Value of the Key", "Value of the DHT Entry in the P2P-System", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
94        public byte[] DhtValue
95        {
96            get
97            {
98                return this.bDhtValue;
99            }
100            set
101            {
102                this.bDhtValue = value;
103                OnPropertyChanged("DhtValue");
104            }
105        }
106
107        #endregion
108
109        #region Events
110
111        public event StatusChangedEventHandler OnPluginStatusChanged;
112
113        public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
114
115        public event PluginProgressChangedEventHandler OnPluginProgressChanged;
116
117        #endregion
118
119        public P2P_DHTload()
120        {
121            this.settings = new P2PDHTloadSettings(this);
122        }
123
124        public ISettings Settings
125        {
126            set { this.settings = (P2PDHTloadSettings)value; }
127            get { return this.settings; }
128        }
129
130        public System.Windows.Controls.UserControl Presentation
131        {
132            get { return null; }
133        }
134
135        public System.Windows.Controls.UserControl QuickWatchPresentation
136        {
137            get { return null; }
138        }
139
140        public void PreExecution()
141        {
142        }
143
144        public void Execute()
145        {
146            // if no P2P Slave PlugIn is connected with this PlugIn --> No execution!
147            if (P2PMaster == null)
148            {
149                GuiLogMessage("No P2P_Peer connected with this PlugIn!", NotificationLevel.Error);
150                return;
151            }
152            if (DhtKey != null)
153            {
154                DhtValue = P2PMaster.DHTload(DhtKey);
155                if (DhtValue != null)
156                    GuiLogMessage("KeyValue of DHT Entry '" + DhtKey + "' retrieved: " + DhtValue.ToString(), NotificationLevel.Info);
157                else
158                    GuiLogMessage("KeyValue of DHT Entry '" + DhtKey + "' is null. Possible cause: Key doesn't exist", NotificationLevel.Info);
159            }
160            else
161            {
162                GuiLogMessage("No key in input. Loading isn't possible.", NotificationLevel.Error);
163            }
164        }
165
166        public void PostExecution()
167        {
168            //throw new NotImplementedException();
169        }
170
171        public void Pause()
172        {
173            //throw new NotImplementedException();
174        }
175
176        public void Stop()
177        {
178            //throw new NotImplementedException();
179        }
180
181        public void Initialize()
182        {
183        }
184
185        public void Dispose()
186        {
187        }
188
189        #region INotifyPropertyChanged Members
190
191        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
192
193        public void OnPropertyChanged(string name)
194        {
195            EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
196        }
197
198        public event PluginProgressChangedEventHandler OnPluginProcessChanged;
199
200        private void ProgressChanged(double value, double max)
201        {
202            EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(value, max));
203        }
204
205        private void GuiLogMessage(string p, NotificationLevel notificationLevel)
206        {
207            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(p, this, notificationLevel));
208        }
209
210        #endregion
211    }
212}
Note: See TracBrowser for help on using the repository browser.