source: trunk/CrypPlugins/PeerToPeerSubscriber/P2PSubscriberSettings.cs @ 1892

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

Vulminous changes and updates (for example: enabling replacement of the publisher, WPF QuickWatchPresentation in P2PManager, etc.)

File size: 6.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Cryptool.PluginBase;
6using System.ComponentModel;
7using Cryptool.PluginBase.Control;
8using System.Windows;
9using Cryptool.Plugins.PeerToPeer;
10
11namespace Cryptool.Plugins.PeerToPeer
12{
13    public class P2PSubscriberSettings : ISettings
14    {
15        public event TaskPaneAttributeChangedHandler TaskPaneAttributeChanged;
16        private bool hasChanges = false;
17        private P2PSubscriber p2pSubscriber;
18
19        #region ISettings Members
20
21        public bool HasChanges
22        {
23            get
24            {
25                return this.hasChanges;
26            }
27            set
28            {
29                this.hasChanges = true;
30            }
31        }
32
33        #endregion
34
35        public P2PSubscriberSettings (P2PSubscriber p2pSubscriber)
36            {
37            this.p2pSubscriber = p2pSubscriber;
38            if (TaskPaneAttributeChanged != null)
39            {
40                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnSolutionFound", Visibility.Collapsed)));
41                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnUnregister", Visibility.Collapsed)));
42                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnRegister", Visibility.Visible)));
43            }
44            }
45
46        private string sTopic = "NewTopic";
47        [TaskPane("Topic Name", "Choose a topic name with which this subscriber shall be registered.", null, 0, false, DisplayLevel.Beginner, ControlType.TextBox)]
48        public string TopicName
49        {
50            get { return this.sTopic; }
51            set
52            {
53                if (this.sTopic != value && value != String.Empty && value != null)
54                {
55                    this.sTopic = value;
56                    HasChanges = true;
57                    OnPropertyChanged(TopicName);
58                }
59            }
60        }
61
62        /* FOR TESTING ISSUES */
63        [TaskPane("Unregister", "Click here to Unregister the publisher from all registered subscribers!", "Control region", 0, true, DisplayLevel.Beginner, ControlType.Button)]
64        public void BtnUnregister()
65        {
66            TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnSolutionFound", Visibility.Collapsed)));
67            TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnUnregister", Visibility.Collapsed)));
68            TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnRegister", Visibility.Visible)));
69            OnPropertyChanged("BtnUnregister");
70        }
71        [TaskPane("Register", "Click here to Register the publisher pro-active with all formely registered subscribers!", "Control region", 1, true, DisplayLevel.Beginner, ControlType.Button)]
72        public void BtnRegister()
73        {
74            TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnSolutionFound", Visibility.Visible)));
75            TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnRegister", Visibility.Collapsed)));
76            TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnUnregister", Visibility.Visible)));
77            OnPropertyChanged("BtnRegister");
78        }
79
80        [TaskPane("Solution found", "TESTING: Emulate solution-found-case!", "Control region", 2, true, DisplayLevel.Beginner, ControlType.Button)]
81        public void BtnSolutionFound()
82        {
83            TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnSolutionFound", Visibility.Collapsed)));
84            TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnUnregister", Visibility.Collapsed)));
85            TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnRegister", Visibility.Visible)));
86            OnPropertyChanged("BtnSolutionFound");
87        }
88        /* FOR TESTING ISSUES */
89
90        private int checkPublishersAvailability = 240;
91        [TaskPane("Check Publisher Interval (in sec)","To check liveness or possibly changed publishing peer in intervals","Intervals",0,false,DisplayLevel.Beginner,ControlType.NumericUpDown, ValidationType.RangeInteger,20,int.MaxValue)]
92        public int CheckPublishersAvailability
93        {
94            get
95            {
96                // multiplied with thousand because the interval is denoted in milliseconds!
97                return this.checkPublishersAvailability;
98            }
99            set
100            {
101                if (value != this.checkPublishersAvailability)
102                {
103                    this.checkPublishersAvailability = value;
104                    OnPropertyChanged("CheckPublishersAvailability");
105                }
106            }
107        }
108
109        private int publishersReplyTimespan = 10;
110        [TaskPane("Publisher Reply Timespan (in sec)", "When checking publishers availability, ping message is sent. The publisher must answer with a pong message in the timespan!", "Intervals", 0, false, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 2, 120)]
111        public int PublishersReplyTimespan
112        {
113            get
114            {
115                // multiplied with thousand because the interval is denoted in milliseconds!
116                return this.publishersReplyTimespan;
117            }
118            set
119            {
120                if (value != this.publishersReplyTimespan)
121                {
122                    this.publishersReplyTimespan = value;
123                    OnPropertyChanged("PublishersReplyTimespan");
124                }
125            }
126        }
127        #region INotifyPropertyChanged Members
128
129        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
130
131        private void OnPropertyChanged(string p)
132        {
133            if (PropertyChanged != null)
134            {
135                PropertyChanged(this, new PropertyChangedEventArgs(p));
136            }
137        }
138
139        #endregion
140    }
141}
Note: See TracBrowser for help on using the repository browser.