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

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

o CrypP2P: refactored P2PBase, removed race condition and unused code

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
46        public P2PEditorPresentation(P2PEditor p2PEditor, JobListManager jobListManager)
47        {
48            P2PEditor = p2PEditor;
49            JobListManager = jobListManager;
50            P2PEditorPresentation = this;
51
52            P2PManager.OnP2PConnectionStateChangeOccurred += HandleChangedPeerToPeerConnectionState;
53
54            InitializeComponent();
55
56            UpdateDisplay();
57        }
58
59        private void HandleChangedPeerToPeerConnectionState(object sender, bool newState)
60        {
61            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(UpdateConnectionState));
62        }
63
64        private void UpdateConnectionState()
65        {
66            IsP2PConnected = P2PManager.Instance.IsP2PConnected();
67        }
68
69        public List<DistributedJob> Jobs
70        {
71            get { return (List<DistributedJob>) GetValue(JobsProperty); }
72            set { SetValue(JobsProperty, value); }
73        }
74
75        public Boolean IsP2PConnected
76        {
77            get { return (Boolean) GetValue(IsP2PConnectedProperty); }
78            set { SetValue(IsP2PConnectedProperty, value); }
79        }
80
81
82        internal void ConnectionWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
83        {
84            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(UpdateDisplay));
85        }
86
87        private void UpdateDisplay()
88        {
89            IsP2PConnected = P2PManager.Instance.IsP2PConnected();
90            Jobs = JobListManager.JobList();
91        }
92
93        internal void ShowJobCreation()
94        {
95            JobTabControl.SelectedItem = JobCreationTab;
96        }
97
98        internal void ShowActiveJobs()
99        {
100            UpdateDisplay();
101            JobTabControl.SelectedItem = ActiveJobsTab;
102        }
103    }
104}
Note: See TracBrowser for help on using the repository browser.