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

Last change on this file since 2220 was 1433, checked in by Paul Lelgemann, 12 years ago

o Extracted common classes from PeerToPeerBase plugin into new PeerToPeer plugin as a preparation for the new P2P proxy
o Modified directory properties to ignore the CrypBuild directory

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;
28using Cryptool.Plugins.PeerToPeer.Internal;
29
30namespace Cryptool.Plugins.PeerToPeer
31{
32    /// <summary>
33    /// This PlugIn only works, when its connected with a P2P_Peer object.
34    /// </summary>
35    [Author("Christian Arnold", "arnold@cryptool.org", "Uni Duisburg-Essen", "http://www.uni-due.de")]
36    [PluginInfo(false, "P2P_DHTload", "Loading data out of the DHT", "", "PeerToPeer_DHTretrieve/ct2_dht_load_icon_medium.png")]
37    public class P2P_DHTload : IThroughput
38    {
39        private P2PDHTloadSettings settings;
40
41        #region In and Output
42
43        private IP2PControl p2pMaster;
44        /// <summary>
45        /// Catches the completely configurated, initialized and joined P2P object from the P2PPeer-Slave-PlugIn.
46        /// </summary>
47        [PropertyInfo(Direction.ControlMaster, "P2P Slave", "Input the P2P-Peer-PlugIn", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
48        public IP2PControl P2PMaster
49        {
50            get
51            {
52                return this.p2pMaster;
53            }
54            set
55            {
56                if (p2pMaster != null)
57                {
58                    p2pMaster.OnStatusChanged -= P2PMaster_OnStatusChanged;
59                }
60                if (value != null)
61                {
62                    value.OnStatusChanged += new IControlStatusChangedEventHandler(P2PMaster_OnStatusChanged);
63                    p2pMaster = (P2PPeerMaster)value;
64                    OnPropertyChanged("P2PMaster");
65                }
66                else
67                {
68                    p2pMaster = null;
69                }
70            }
71        }
72
73        private void P2PMaster_OnStatusChanged(IControl sender, bool readyForExecution)
74        {
75            //throw new NotImplementedException();
76        }
77
78        private string sDhtKey;
79        [PropertyInfo(Direction.InputData, "Key Name", "Key Name of DHT Entry in the P2P-System", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
80        public string DhtKey
81        {
82            get
83            {
84                return this.sDhtKey;
85            }
86            set
87            {
88                this.sDhtKey = value;
89                OnPropertyChanged("DhtKey");
90            }
91        }
92
93        private byte[] bDhtValue;
94        [PropertyInfo(Direction.OutputData, "Value of the Key", "Value of the DHT Entry in the P2P-System", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
95        public byte[] DhtValue
96        {
97            get
98            {
99                return this.bDhtValue;
100            }
101            set
102            {
103                this.bDhtValue = value;
104                OnPropertyChanged("DhtValue");
105            }
106        }
107
108        #endregion
109
110        #region Events
111
112        public event StatusChangedEventHandler OnPluginStatusChanged;
113
114        public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
115
116        public event PluginProgressChangedEventHandler OnPluginProgressChanged;
117
118        #endregion
119
120        public P2P_DHTload()
121        {
122            this.settings = new P2PDHTloadSettings(this);
123        }
124
125        public ISettings Settings
126        {
127            set { this.settings = (P2PDHTloadSettings)value; }
128            get { return this.settings; }
129        }
130
131        public System.Windows.Controls.UserControl Presentation
132        {
133            get { return null; }
134        }
135
136        public System.Windows.Controls.UserControl QuickWatchPresentation
137        {
138            get { return null; }
139        }
140
141        public void PreExecution()
142        {
143        }
144
145        public void Execute()
146        {
147            // if no P2P Slave PlugIn is connected with this PlugIn --> No execution!
148            if (P2PMaster == null)
149            {
150                GuiLogMessage("No P2P_Peer connected with this PlugIn!", NotificationLevel.Error);
151                return;
152            }
153            if (DhtKey != null)
154            {
155                DhtValue = P2PMaster.DHTload(DhtKey);
156                if (DhtValue != null)
157                    GuiLogMessage("KeyValue of DHT Entry '" + DhtKey + "' retrieved: " + DhtValue.ToString(), NotificationLevel.Info);
158                else
159                    GuiLogMessage("KeyValue of DHT Entry '" + DhtKey + "' is null. Possible cause: Key doesn't exist", NotificationLevel.Info);
160            }
161            else
162            {
163                GuiLogMessage("No key in input. Loading isn't possible.", NotificationLevel.Error);
164            }
165        }
166
167        public void PostExecution()
168        {
169            //throw new NotImplementedException();
170        }
171
172        public void Pause()
173        {
174            //throw new NotImplementedException();
175        }
176
177        public void Stop()
178        {
179            //throw new NotImplementedException();
180        }
181
182        public void Initialize()
183        {
184        }
185
186        public void Dispose()
187        {
188        }
189
190        #region INotifyPropertyChanged Members
191
192        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
193
194        public void OnPropertyChanged(string name)
195        {
196            EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
197        }
198
199        public event PluginProgressChangedEventHandler OnPluginProcessChanged;
200
201        private void ProgressChanged(double value, double max)
202        {
203            EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(value, max));
204        }
205
206        private void GuiLogMessage(string p, NotificationLevel notificationLevel)
207        {
208            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(p, this, notificationLevel));
209        }
210
211        #endregion
212    }
213}
Note: See TracBrowser for help on using the repository browser.