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

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

+ P2PEditor: Own jobs can be deleted, new jobs are displayed on top and after creation of a job, it is selected in the list

File size: 2.7 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;
8
9namespace Cryptool.P2PEditor.GUI.Controls
10{
11    /// <summary>
12    /// Interaction logic for JobCreation.xaml
13    /// </summary>
14    public partial class JobCreation
15    {
16        private DistributedJob _newDistributedJob;
17
18        public JobCreation()
19        {
20            InitializeComponent();
21        }
22
23        private void UserControl_Loaded(object sender, RoutedEventArgs e)
24        {
25            DataContext = new DistributedJob();
26        }
27
28        private void BrowseFileButton_OnClick(object sender, RoutedEventArgs e)
29        {
30            using (var dialog = new OpenFileDialog())
31            {
32                if (dialog.ShowDialog() == DialogResult.OK)
33                {
34                    try
35                    {
36                        ((DistributedJob) DataContext).LocalFilePath = dialog.FileName;
37                    }
38                    catch (FileNotFoundException)
39                    {
40                        P2PEditor.GuiLogMessage("File not found.", NotificationLevel.Error);
41                    }
42                }
43            }
44        }
45
46        private void ShareButton_Click(object sender, RoutedEventArgs e)
47        {
48            // Validate input
49            _newDistributedJob = (DistributedJob) DataContext;
50
51            if (_newDistributedJob.JobDescription == null || _newDistributedJob.JobName == null)
52            {
53                P2PEditor.GuiLogMessage("Please fill all fields.", NotificationLevel.Error);
54                return;
55            }
56
57            if (!File.Exists(_newDistributedJob.LocalFilePath))
58            {
59                // TODO validate that selected file contains a workspace
60                P2PEditor.GuiLogMessage("Selected workspace does not exist.", NotificationLevel.Error);
61                return;
62            }
63
64            var backgroundCreationWorker = new JobCreationWorker(JobListManager, _newDistributedJob);
65            backgroundCreationWorker.RunWorkerCompleted += BackgroundCreationWorkerCompleted;
66            backgroundCreationWorker.RunWorkerAsync();
67        }
68
69        private void BackgroundCreationWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
70        {
71            P2PEditor.GuiLogMessage("Distributed job " + _newDistributedJob.JobGuid, NotificationLevel.Debug);
72            DataContext = new DistributedJob();
73
74            P2PEditorPresentation.ShowActiveJobs();
75            P2PEditorPresentation.ActiveJobsControl.JobListBox.SelectedIndex = 0;
76        }
77    }
78}
Note: See TracBrowser for help on using the repository browser.