source: trunk/CrypPlugins/PeerToPeer_DHTremove/P2PDHTremove.cs @ 1507

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