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

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

o Refactoring in CrypP2P
o AES: NullReference in AES-Plugin fixed
o Small fixes in KeySearcher, StorageKeyGenerator uses IV and truncates input data

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