source: trunk/CrypPlugins/P2PEditor/GUI/Controls/JobCreation.xaml.cs @ 1727

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

+ P2PEditor can display the status of jobs, if available; Participating displays overlay while loading workspace data
+ KeySearcher can upload status for P2PEditor display

File size: 3.0 KB
Line 
1using System.ComponentModel;
2using System.IO;
3using System.Windows;
4using System.Windows.Forms;
5using Cryptool.P2PEditor.Distributed;
6using Cryptool.P2PEditor.Worker;
7using Cryptool.PluginBase;
8using Clipboard = System.Windows.Clipboard;
9using TextDataFormat = System.Windows.TextDataFormat;
10
11namespace Cryptool.P2PEditor.GUI.Controls
12{
13    public partial class JobCreation
14    {
15        private DistributedJob newDistributedJob;
16
17        public JobCreation()
18        {
19            InitializeComponent();
20        }
21
22        private void UserControl_Loaded(object sender, RoutedEventArgs e)
23        {
24            DataContext = new DistributedJob();
25
26            if (!Clipboard.ContainsText(TextDataFormat.Text)) return;
27            var clipboardData = Clipboard.GetText(TextDataFormat.Text);
28            if (clipboardData.EndsWith("-status"))
29            {
30                ((DistributedJob)DataContext).StatusKey = clipboardData;
31            }
32        }
33
34        private void BrowseFileButton_OnClick(object sender, RoutedEventArgs e)
35        {
36            using (var dialog = new OpenFileDialog())
37            {
38                if (dialog.ShowDialog() == DialogResult.OK)
39                {
40                    try
41                    {
42                        ((DistributedJob) DataContext).LocalFilePath = dialog.FileName;
43                    }
44                    catch (FileNotFoundException)
45                    {
46                        P2PEditor.GuiLogMessage("File not found.", NotificationLevel.Error);
47                    }
48                }
49            }
50        }
51
52        private void ShareButton_Click(object sender, RoutedEventArgs e)
53        {
54            // Validate input
55            newDistributedJob = (DistributedJob) DataContext;
56
57            if (newDistributedJob.Description == null || newDistributedJob.Name == null)
58            {
59                P2PEditor.GuiLogMessage("Please fill all fields.", NotificationLevel.Error);
60                return;
61            }
62
63            if (!File.Exists(newDistributedJob.LocalFilePath))
64            {
65                // TODO validate that selected file contains a workspace
66                P2PEditor.GuiLogMessage("Selected workspace does not exist.", NotificationLevel.Error);
67                return;
68            }
69
70            var backgroundCreationWorker = new JobCreationWorker(JobListManager, newDistributedJob);
71            backgroundCreationWorker.RunWorkerCompleted += BackgroundCreationWorkerCompleted;
72            backgroundCreationWorker.RunWorkerAsync();
73        }
74
75        private void BackgroundCreationWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
76        {
77            P2PEditor.GuiLogMessage("Distributed job " + newDistributedJob.Guid, NotificationLevel.Debug);
78            DataContext = new DistributedJob();
79
80            P2PEditorPresentation.ShowActiveJobs();
81            P2PEditorPresentation.ActiveJobsControl.JobListBox.SelectedIndex = 0;
82        }
83    }
84}
Note: See TracBrowser for help on using the repository browser.