source: trunk/CrypP2P/Worker/ConnectionWorker.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: 2.5 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.ComponentModel;
18using Cryptool.P2P.Helper;
19using Cryptool.P2P.Internal;
20using Cryptool.PluginBase;
21
22namespace Cryptool.P2P.Worker
23{
24    public class ConnectionWorker : WorkerBase
25    {
26        private readonly P2PBase _p2PBase;
27
28        public ConnectionWorker(P2PBase p2PBase)
29        {
30            _p2PBase = p2PBase;
31        }
32
33        protected override void WorkComplete(object sender, RunWorkerCompletedEventArgs e)
34        {
35            P2PManager.Instance.GuiLogMessage(
36                P2PManager.Instance.IsP2PConnected()
37                    ? "Connection to P2P network established."
38                    : "Connection to P2P network terminated.", NotificationLevel.Info);
39            P2PManager.Instance.IsP2PConnecting = false;
40            P2PManager.Instance.FireConnectionStatusChange();
41        }
42
43        protected override void PerformWork(object sender, DoWorkEventArgs e)
44        {
45            if (!_p2PBase.Started)
46            {
47                P2PManager.Instance.GuiLogMessage("Connecting to P2P network...", NotificationLevel.Info);
48
49                // Validate certificats
50                if (!PAPCertificate.CheckAndInstallPAPCertificates())
51                {
52                    P2PManager.Instance.GuiLogMessage("Certificates not validated, P2P might not be working!",
53                                                      NotificationLevel.Error);
54                    return;
55                }
56
57                _p2PBase.Initialize();
58                _p2PBase.SynchStart();
59            }
60            else
61            {
62                P2PManager.Instance.GuiLogMessage("Disconnecting from P2P network...", NotificationLevel.Info);
63                _p2PBase.SynchStop();
64            }
65        }
66
67        protected override void PrePerformWork()
68        {
69            P2PManager.Instance.IsP2PConnecting = true;
70        }
71    }
72}
Note: See TracBrowser for help on using the repository browser.