source: trunk/CrypPlugins/P2PEditor/Worker/JobParticipationWorker.cs @ 1917

Last change on this file since 1917 was 1917, checked in by Paul Lelgemann, 11 years ago

o KeySearcher: fixed "+unendlich years" as estimated finish date display bug
o P2PEditor: fixed behavior of new button without p2p connection and participate button with not job selected
o P2PEditor: minor refactoring, removed unused code and classes

File size: 2.0 KB
Line 
1using System;
2using System.ComponentModel;
3using System.Windows.Threading;
4using Cryptool.P2PEditor.Distributed;
5using Cryptool.PluginBase;
6
7namespace Cryptool.P2PEditor.Worker
8{
9    public class JobParticipationWorker : BackgroundWorker
10    {
11        private readonly P2PEditor p2PEditor;
12        private readonly JobListManager jobListManager;
13        private readonly DistributedJob jobToParticipateIn;
14        private readonly Dispatcher dispatcher;
15
16        public JobParticipationWorker(P2PEditor p2PEditor, JobListManager jobListManager, DistributedJob jobToParticipateIn, Dispatcher dispatcher)
17        {
18            this.p2PEditor = p2PEditor;
19            this.jobListManager = jobListManager;
20            this.jobToParticipateIn = jobToParticipateIn;
21            this.dispatcher = dispatcher;
22
23            DoWork += JobParticipationWorkerDoWork;
24        }
25
26        private void JobParticipationWorkerDoWork(object sender, DoWorkEventArgs e)
27        {
28            try
29            {
30                jobListManager.CompleteDistributedJob(jobToParticipateIn);
31            }
32            catch (Exception ex)
33            {
34                p2PEditor.GuiLogMessage("Error completing job: " + ex.Message, NotificationLevel.Error);
35                return;
36            }
37
38            p2PEditor.GuiLogMessage("Local workspace: " + jobToParticipateIn.LocalFilePath, NotificationLevel.Debug);
39            p2PEditor.GuiLogMessage(
40                string.Format("Workspace {0} ready to participate, dispatching with CrypTool...",
41                              jobToParticipateIn.Name),
42                NotificationLevel.Info);
43
44            jobListManager.IncreaseDownloadCount(jobToParticipateIn);
45
46            dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(DispatchOpenFileEvent));
47        }
48
49        private void DispatchOpenFileEvent()
50        {
51            p2PEditor.SendOpenProjectFileEvent(jobToParticipateIn.LocalFilePath);
52        }
53    }
54}
Note: See TracBrowser for help on using the repository browser.