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

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

o Updated Peers@Play libraries to 5432

override-bad-extension: Bootstrapper.pdb
override-bad-extension: CertServices.pdb
override-bad-extension: FullMeshDHT.pdb
override-bad-extension: FullMeshOverlay.pdb
override-bad-extension: Gears4Net.pdb
override-bad-extension: LinkManager.pdb
override-bad-extension: PeersAtPlayBase.pdb
override-bad-extension: RUDP.pdb
override-bad-extension: Stun.pdb
override-bad-extension: Util.pdb
override-bad-extension: log4net.pdb

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