source: trunk/CrypPlugins/PeerToPeer_DHTstore/P2PDHTstore.cs @ 800

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

dhtstore new version

File size: 6.5 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_DHTstore", "Storing data in DHT", "", "PeerToPeer_DHTstore/ct2_dht_store_icon_medium.png")]
36    public class P2P_DHTstore : IInput
37    {
38        private P2PDHTstoreSettings 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 string sDhtValue;
93        [PropertyInfo(Direction.InputData, "Value of the Key", "Value of the Key of DHT Entry in the P2P-System", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
94        public string DhtValue
95        {
96            get
97            {
98                return this.sDhtValue;
99            }
100            set
101            {
102                this.sDhtValue = 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_DHTstore()
120        {
121            this.settings = new P2PDHTstoreSettings(this);
122        }
123
124        public ISettings Settings
125        {
126            set { this.settings = (P2PDHTstoreSettings)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 && DhtValue != null)
153            {
154                P2PMaster.DHTstore(DhtKey, DhtValue);
155                GuiLogMessage("KeyValue-Pair will be stored in the DHT Entry '" + DhtKey + "'. Value: " + DhtValue, NotificationLevel.Info);
156            }
157            else
158            {
159                GuiLogMessage("No key and/or value in inputs. Storing isn't possible.", NotificationLevel.Error);
160            }
161        }
162
163        public void PostExecution()
164        {
165            //throw new NotImplementedException();
166        }
167
168        public void Pause()
169        {
170            //throw new NotImplementedException();
171        }
172
173        public void Stop()
174        {
175            //throw new NotImplementedException();
176        }
177
178        public void Initialize()
179        {
180        }
181
182        public void Dispose()
183        {
184        }
185
186        #region INotifyPropertyChanged Members
187
188        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
189
190        public void OnPropertyChanged(string name)
191        {
192            EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
193        }
194
195        public event PluginProgressChangedEventHandler OnPluginProcessChanged;
196
197        private void ProgressChanged(double value, double max)
198        {
199            EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(value, max));
200        }
201
202        private void GuiLogMessage(string p, NotificationLevel notificationLevel)
203        {
204            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(p, this, notificationLevel));
205        }
206
207        #endregion
208    }
209}
Note: See TracBrowser for help on using the repository browser.