source: trunk/CrypPlugins/P2PEditor/GUI/P2PEditorPresentation.xaml.cs @ 1579

Last change on this file since 1579 was 1579, checked in by Paul Lelgemann, 12 years ago

+ P2PEditor: Timer-based refresh of the job list (configurable in seconds)
o CrypP2P: Restored bootstrapper to V2
+ P2PManager: Added asynchronous DHT message calls for completeness

File size: 3.7 KB
Line 
1/*
2   Copyright 2010 Paul Lelgemann, University of Duisburg-Essen
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15*/
16
17using System;
18using System.Collections.Generic;
19using System.ComponentModel;
20using System.Windows;
21using System.Windows.Threading;
22using Cryptool.P2P;
23using Cryptool.P2PEditor.Distributed;
24
25namespace Cryptool.P2PEditor.GUI
26{
27    /// <summary>
28    /// Interaction logic for P2PEditorPresentation.xaml
29    /// </summary>
30    public partial class P2PEditorPresentation
31    {
32        public static readonly DependencyProperty JobsProperty = DependencyProperty.Register("Jobs",
33                                                                                             typeof (
34                                                                                                 List<DistributedJob>),
35                                                                                             typeof (
36                                                                                                 P2PEditorPresentation));
37
38        public static readonly DependencyProperty IsP2PConnectedProperty =
39            DependencyProperty.Register("IsP2PConnected",
40                                        typeof (
41                                            Boolean),
42                                        typeof (
43                                            P2PEditorPresentation), new PropertyMetadata(false));
44
45        public P2PEditorPresentation(P2PEditor p2PEditor, JobListManager jobListManager)
46        {
47            P2PEditor = p2PEditor;
48            JobListManager = jobListManager;
49            P2PEditorPresentation = this;
50
51            P2PManager.OnP2PConnectionStateChangeOccurred += HandleChangedPeerToPeerConnectionState;
52
53            InitializeComponent();
54
55            UpdateDisplay();
56        }
57
58        private void HandleChangedPeerToPeerConnectionState(object sender, bool newState)
59        {
60            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(UpdateConnectionState));
61        }
62
63        public List<DistributedJob> Jobs
64        {
65            get { return (List<DistributedJob>) GetValue(JobsProperty); }
66            set { SetValue(JobsProperty, value); }
67        }
68
69        public Boolean IsP2PConnected
70        {
71            get { return (Boolean) GetValue(IsP2PConnectedProperty); }
72            set { SetValue(IsP2PConnectedProperty, value); }
73        }
74
75
76        internal void ConnectionWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
77        {
78            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(UpdateDisplay));
79        }
80
81        private void UpdateDisplay()
82        {
83            UpdateConnectionState();
84            ActiveJobsControl.UpdateJobList();
85        }
86
87        private void UpdateConnectionState()
88        {
89            IsP2PConnected = P2PManager.Instance.IsP2PConnected();
90        }
91
92        internal void ShowJobCreation()
93        {
94            JobTabControl.SelectedItem = JobCreationTab;
95        }
96
97        internal void ShowActiveJobs()
98        {
99            UpdateDisplay();
100            JobTabControl.SelectedItem = ActiveJobsTab;
101        }
102    }
103}
Note: See TracBrowser for help on using the repository browser.