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

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