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

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

P2P DHT Operations

File size: 6.0 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_DHTremove", "Removing data from the DHT", "", "PeerToPeer_DHTremove/ct2_dht_remove_icon_medium.png")]
36    public class P2P_DHTremove : IInput
37    {
38        private P2PDHTremoveSettings 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        #endregion
93
94        #region Events
95
96        public event StatusChangedEventHandler OnPluginStatusChanged;
97
98        public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
99
100        public event PluginProgressChangedEventHandler OnPluginProgressChanged;
101
102        #endregion
103
104        public P2P_DHTremove()
105        {
106            this.settings = new P2PDHTremoveSettings(this);
107        }
108
109        public ISettings Settings
110        {
111            set { this.settings = (P2PDHTremoveSettings)value; }
112            get { return this.settings; }
113        }
114
115        public System.Windows.Controls.UserControl Presentation
116        {
117            get { return null; }
118        }
119
120        public System.Windows.Controls.UserControl QuickWatchPresentation
121        {
122            get { return null; }
123        }
124
125        public void PreExecution()
126        {
127        }
128
129        public void Execute()
130        {
131            // if no P2P Slave PlugIn is connected with this PlugIn --> No execution!
132            if (P2PMaster == null)
133            {
134                GuiLogMessage("No P2P_Peer connected with this PlugIn!", NotificationLevel.Error);
135                return;
136            }
137            if (DhtKey != null)
138            {
139                P2PMaster.DHTremove(DhtKey);
140                GuiLogMessage("Entry with the key '" + DhtKey + "' will be removed from the DHT", NotificationLevel.Info);
141            }
142            else
143            {
144                GuiLogMessage("No key in input. Removing isn't possible.", NotificationLevel.Error);
145            }
146        }
147
148        public void PostExecution()
149        {
150            //throw new NotImplementedException();
151        }
152
153        public void Pause()
154        {
155            //throw new NotImplementedException();
156        }
157
158        public void Stop()
159        {
160            //throw new NotImplementedException();
161        }
162
163        public void Initialize()
164        {
165        }
166
167        public void Dispose()
168        {
169        }
170
171        #region INotifyPropertyChanged Members
172
173        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
174
175        public void OnPropertyChanged(string name)
176        {
177            EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
178        }
179
180        public event PluginProgressChangedEventHandler OnPluginProcessChanged;
181
182        private void ProgressChanged(double value, double max)
183        {
184            EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(value, max));
185        }
186
187        private void GuiLogMessage(string p, NotificationLevel notificationLevel)
188        {
189            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(p, this, notificationLevel));
190        }
191
192        #endregion
193    }
194}
Note: See TracBrowser for help on using the repository browser.