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

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

+ Added P2P connection to CrypP2P based on PeerToPeerBase plugin (using default settings)
+ Added MD5Collider to CoreDeveloper solution

File size: 3.1 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                newImage.Source = new BitmapImage(new Uri(P2PManager.P2PDisconnectImageURI, UriKind.RelativeOrAbsolute));
69            }
70            else
71            {
72                P2PManager.Instance.GuiLogMessage("Connection to P2P network terminated.", NotificationLevel.Info);
73                newImage.Source = new BitmapImage(new Uri(P2PManager.P2PConnectImageURI, UriKind.RelativeOrAbsolute));
74            }
75
76            newImage.Stretch = Stretch.Uniform;
77            newImage.Width = 40;
78            newImage.Height = 40;
79            p2pButton.Image = newImage;
80
81            p2pButton.IsEnabled = true;
82        }
83
84        protected override void PrePerformWork()
85        {
86            p2pButton.IsEnabled = false;
87        }
88    }
89}
Note: See TracBrowser for help on using the repository browser.