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

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

o CrypP2P: Code cleanup
o P2PEditor: job list will be reloaded in a BackgroundWorker

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