source: trunk/CrypP2P/Worker/ConnectionWorker.cs @ 1378

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

o Fixed solutions and broken plugins, which had missing/broken dependencies
+ Added debug output after connecting about our local peer to CrypP2P
+ Prepared PeerToPeer plugin for later use

File size: 3.2 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.Linq;
20using System.Text;
21using DevComponents.WpfRibbon;
22using System.Windows.Controls;
23using System.Windows.Media.Imaging;
24using System.Windows.Media;
25using Cryptool.PluginBase;
26using Cryptool.P2P.Internal;
27
28namespace Cryptool.P2P.Worker
29{
30    class ConnectionWorker : WorkerBase
31    {
32        P2PBase p2pBase;
33        P2PSettings p2pSettings;
34        ButtonDropDown p2pButton;
35
36        public ConnectionWorker(P2PBase p2pBase, P2PSettings p2pSettings, ButtonDropDown p2pButton)
37        {
38            this.p2pBase = p2pBase;
39            this.p2pSettings = p2pSettings;
40            this.p2pButton = p2pButton;
41        }
42
43        protected override void PerformWork(object sender, System.ComponentModel.DoWorkEventArgs e)
44        {
45            //p2pButton.IsEnabled = false;
46
47            if (!p2pBase.Started)
48            {
49                P2PManager.Instance.GuiLogMessage("Connecting to P2P network...", NotificationLevel.Info);
50                p2pBase.Initialize(p2pSettings);
51                p2pBase.SynchStart();
52            }
53            else
54            {
55                P2PManager.Instance.GuiLogMessage("Disconnecting from P2P network...", NotificationLevel.Info);
56                p2pBase.SynchStop();
57            }
58        }
59
60        protected override void WorkComplete(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
61        {
62            // Update image according to new state
63            Image newImage = new Image();
64
65            if (P2PManager.Instance.P2PConnected())
66            {
67                P2PManager.Instance.GuiLogMessage("Connection to P2P network established.", NotificationLevel.Info);
68                P2PManager.Instance.GuiLogMessage("P2P user info: " + P2PManager.Instance.UserInfo(), NotificationLevel.Debug);
69                newImage.Source = new BitmapImage(new Uri(P2PManager.P2PDisconnectImageURI, UriKind.RelativeOrAbsolute));
70            }
71            else
72            {
73                P2PManager.Instance.GuiLogMessage("Connection to P2P network terminated.", NotificationLevel.Info);
74                newImage.Source = new BitmapImage(new Uri(P2PManager.P2PConnectImageURI, UriKind.RelativeOrAbsolute));
75            }
76
77            newImage.Stretch = Stretch.Uniform;
78            newImage.Width = 40;
79            newImage.Height = 40;
80            p2pButton.Image = newImage;
81
82            p2pButton.IsEnabled = true;
83        }
84
85        protected override void PrePerformWork()
86        {
87            p2pButton.IsEnabled = false;
88        }
89    }
90}
Note: See TracBrowser for help on using the repository browser.