Changeset 1563


Ignore:
Timestamp:
Jun 2, 2010, 12:14:49 AM (12 years ago)
Author:
Paul Lelgemann
Message:

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

Location:
trunk/CrypPlugins/P2PEditor
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/P2PEditor/Distributed/DistributedJob.cs

    r1549 r1563  
    1515        {
    1616            JobGuid = Guid.NewGuid();
     17            JobOwner = P2PSettings.Default.PeerName;
     18            JobDate = new DateTime();
    1719        }
    1820
  • trunk/CrypPlugins/P2PEditor/Distributed/JobListManager.cs

    r1549 r1563  
    5353            }
    5454
    55             List<DistributedJob> currentJobList = JobList();
     55            var currentJobList = JobList();
    5656            currentJobList.Add(distributedJob);
    5757
     
    6262            P2PManager.Store(JoblistKey, memoryStream.ToArray());
    6363
    64             byte[] workspaceData = File.ReadAllBytes(distributedJob.LocalFilePath);
     64            var workspaceData = File.ReadAllBytes(distributedJob.LocalFilePath);
    6565            _p2PEditor.GuiLogMessage(
    6666                "Workspace size: " + workspaceData.Length + ", storing at " + GenerateWorkspaceKey(distributedJob),
     
    6969
    7070            _p2PEditor.GuiLogMessage("Distributed job " + distributedJob.JobName, NotificationLevel.Info);
     71        }
     72
     73        public void DeleteDistributedJob(DistributedJob distributedJobToDelete)
     74        {
     75            _p2PEditor.GuiLogMessage("Deleting job...", NotificationLevel.Debug);
     76
     77            if (!P2PManager.Instance.IsP2PConnected())
     78            {
     79                _p2PEditor.GuiLogMessage("P2P not connected, cannot distribute job.", NotificationLevel.Error);
     80                return;
     81            }
     82
     83            var currentJobList = JobList();
     84            currentJobList.RemoveAll(x => x.JobGuid == distributedJobToDelete.JobGuid);
     85
     86            var memoryStream = new MemoryStream();
     87            var bformatter = new BinaryFormatter();
     88
     89            bformatter.Serialize(memoryStream, currentJobList);
     90            P2PManager.Store(JoblistKey, memoryStream.ToArray());
     91
     92            // Retrieve job first to satify versioned DHT
     93            P2PManager.Retrieve(GenerateWorkspaceKey(distributedJobToDelete));
     94            P2PManager.Remove(GenerateWorkspaceKey(distributedJobToDelete));
     95
     96            _p2PEditor.GuiLogMessage("Deleted distributed job " + distributedJobToDelete.JobName, NotificationLevel.Info);
    7197        }
    7298
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/JobCreation.xaml

    r1527 r1563  
    44             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    55             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:GUI="clr-namespace:Cryptool.P2PEditor.GUI" mc:Ignorable="d"
    6              d:DesignHeight="264" d:DesignWidth="442" Loaded="UserControl_Loaded" >
     6             d:DesignHeight="186" d:DesignWidth="334" Loaded="UserControl_Loaded">
    77    <Grid>
    8         <Label Content="Name:" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="12,12,0,0" />
    9         <TextBox Text="{Binding JobName}" Height="26" Margin="89,14,9,0" VerticalAlignment="Top" />
    10         <TextBox Text="{Binding LocalFilePath}" Height="28" Margin="89,46,40,0" Name="LocalFilePath" VerticalAlignment="Top" />
    11         <Button Content="..." Click="BrowseFileButton_OnClick"  Height="28" HorizontalAlignment="Right" Margin="0,45,9,0" Name="BrowseFileButton" VerticalAlignment="Top" Width="28" />
    12         <Label Content="Workspace:" Height="28" HorizontalAlignment="Left" Margin="12,46,0,0" VerticalAlignment="Top" />
    13         <Label Content="Description:" Height="28" HorizontalAlignment="Left" Margin="12,80,0,0" VerticalAlignment="Top" />
    14         <TextBox Text="{Binding JobDescription}" Margin="89,80,9,42" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" />
    15         <Button Content="Share" Click="ShareButton_Click"  Margin="0,0,9,12" Name="ShareButton" Height="24" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="79" />
     8        <Grid.ColumnDefinitions>
     9            <ColumnDefinition Width="284*" />
     10            <ColumnDefinition Width="197*" />
     11        </Grid.ColumnDefinitions>
     12        <Label Content="Name:" Height="28" HorizontalAlignment="Left" VerticalAlignment="Top" />
     13        <TextBox Text="{Binding JobName}" Height="26" VerticalAlignment="Top" Grid.ColumnSpan="2" Margin="74,0,0,0" />
     14        <TextBox Text="{Binding LocalFilePath}" Margin="74,33,34,0" Name="LocalFilePath" Grid.ColumnSpan="2" Height="28" VerticalAlignment="Top" />
     15        <Button Content="..." Click="BrowseFileButton_OnClick"  Height="28" HorizontalAlignment="Right" Margin="0,34,0,0" Name="BrowseFileButton" VerticalAlignment="Top" Width="28" Grid.Column="1" />
     16        <Label Content="Workspace:" Height="28" HorizontalAlignment="Left" Margin="0,34,0,0" VerticalAlignment="Top" />
     17        <Label Content="Description:" Height="28" HorizontalAlignment="Left" Margin="-2,68,0,0" VerticalAlignment="Top" />
     18        <TextBox Text="{Binding JobDescription}" Margin="74,70,0,36" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Grid.ColumnSpan="2" />
     19        <Button Content="Share" Click="ShareButton_Click"  Margin="0,0,0,7" Name="ShareButton" HorizontalAlignment="Right" Width="80" Grid.Column="1" Height="23" VerticalAlignment="Bottom" />
    1620    </Grid>
    1721</GUI:P2PUserControl>
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/JobCreation.xaml.cs

    r1527 r1563  
    7373
    7474            P2PEditorPresentation.ShowActiveJobs();
     75            P2PEditorPresentation.ActiveJobsControl.JobListBox.SelectedIndex = 0;
    7576        }
    7677    }
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/JobDisplay.xaml

    r1549 r1563  
    77            <Style x:Key="jobListDisplayStyle" TargetType="{x:Type ListBox}">
    88                <Style.Resources>
    9                     <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="AliceBlue" />
     9                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue" />
    1010                </Style.Resources>
    1111            </Style>
     
    1313    </GUI:P2PUserControl.Resources>
    1414        <Grid Background="White">
    15         <ListBox x:Name="JobListBox" ItemsSource="{Binding Jobs,RelativeSource ={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" ItemTemplate="{StaticResource jobDisplayTemplate}" Style="{StaticResource jobListDisplayStyle}" Margin="0,0,0,35">
     15        <ListBox x:Name="JobListBox" ItemsSource="{Binding Jobs,RelativeSource ={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" ItemTemplate="{StaticResource jobDisplayTemplate}" Style="{StaticResource jobListDisplayStyle}" KeyUp="JobListBox_KeyUp" Margin="0,0,0,35">
    1616            <ListBox.ItemContainerStyle>
    1717                <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
     
    2222        <Grid DataContext="{Binding SelectedItem,ElementName=JobListBox}">
    2323            <Button Content="Participate" HorizontalAlignment="Right" Margin="0,0,0,6" Name="ParticipateButton" Width="75" Height="23" VerticalAlignment="Bottom" Click="ParticipateButton_Click" />
    24             <Button Content="Refresh" Click="RefreshButton_Click" HorizontalAlignment="Right" Margin="0,0,81,6" Name="RefreshButton" Width="75" Height="23" VerticalAlignment="Bottom" />
     24            <Button Content="Refresh" Click="RefreshButton_Click" Margin="0,0,0,6" Name="RefreshButton" Height="23" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="75" />
     25            <Button Content="Delete" Click="DeleteButton_Click" Margin="0,0,81,6" Name="DeleteButton" HorizontalAlignment="Right" Width="75" Height="23" VerticalAlignment="Bottom" />
    2526        </Grid>
    2627    </Grid>
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/JobDisplay.xaml.cs

    r1549 r1563  
    55using System.Windows.Input;
    66using System.Windows.Threading;
     7using Cryptool.P2P;
    78using Cryptool.P2PEditor.Distributed;
    89using Cryptool.P2PEditor.Worker;
     
    4445        }
    4546
    46         private void UpdateJobList()
     47        public void UpdateJobList()
    4748        {
    4849            Jobs = JobListManager.JobList();
     50            Jobs.Reverse();
    4951        }
    5052
     
    7375            new JobParticipationWorker(P2PEditor, JobListManager, jobToParticipateIn, Dispatcher).RunWorkerAsync();
    7476        }
     77
     78        private void DeleteButton_Click(object sender, RoutedEventArgs e)
     79        {
     80            DeleteSelectedJob();
     81        }
     82
     83        private void JobListBox_KeyUp(object sender, KeyEventArgs e)
     84        {
     85            switch (e.Key)
     86            {
     87                case Key.Enter:
     88                    ParticipateInSelectedJob();
     89                    break;
     90                case Key.Delete:
     91                    DeleteSelectedJob();
     92                    break;
     93            }
     94           
     95        }
     96
     97        private void DeleteSelectedJob()
     98        {
     99            var jobToDelete = (DistributedJob)JobListBox.SelectedItem;
     100
     101            if (jobToDelete == null || jobToDelete.JobOwner != P2PSettings.Default.PeerName)
     102            {
     103                return;
     104            }
     105
     106            P2PEditor.GuiLogMessage(
     107                string.Format("Deleting job {0} ({1}).", jobToDelete.JobName, jobToDelete.JobGuid),
     108                NotificationLevel.Info);
     109
     110            var backgroundCreationWorker = new JobDeletionWorker(JobListManager, jobToDelete);
     111            backgroundCreationWorker.RunWorkerCompleted += BackgroundDeletionWorkerCompleted;
     112            backgroundCreationWorker.RunWorkerAsync();
     113        }
     114
     115        private void BackgroundDeletionWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
     116        {
     117            P2PEditorPresentation.ShowActiveJobs();
     118        }
    75119    }
    76120}
  • trunk/CrypPlugins/P2PEditor/GUI/P2PEditorPresentation.xaml

    r1527 r1563  
    33                <TabControl TabStripPlacement="Top" Name="JobTabControl" IsEnabled="{Binding IsP2PConnected, ElementName=P2PEditorControl}">
    44                        <TabItem Header="Active jobs" Name="ActiveJobsTab">
    5                                 <controls:JobDisplay Jobs="{Binding Jobs,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
     5                                <controls:JobDisplay x:Name="ActiveJobsControl" Jobs="{Binding Jobs,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
    66                        </TabItem>
    77                        <TabItem Header="New job" Name="JobCreationTab">
  • trunk/CrypPlugins/P2PEditor/GUI/P2PEditorPresentation.xaml.cs

    r1545 r1563  
    6262        }
    6363
    64         private void UpdateConnectionState()
    65         {
    66             IsP2PConnected = P2PManager.Instance.IsP2PConnected();
    67         }
    68 
    6964        public List<DistributedJob> Jobs
    7065        {
     
    8782        private void UpdateDisplay()
    8883        {
     84            UpdateConnectionState();
     85            ActiveJobsControl.UpdateJobList();
     86        }
     87
     88        private void UpdateConnectionState()
     89        {
    8990            IsP2PConnected = P2PManager.Instance.IsP2PConnected();
    90             Jobs = JobListManager.JobList();
    9191        }
    9292
  • trunk/CrypPlugins/P2PEditor/P2PEditor.csproj

    r1549 r1563  
    9393      <DesignTime>True</DesignTime>
    9494    </Compile>
     95    <Compile Include="Worker\JobDeletionWorker.cs">
     96      <SubType>Component</SubType>
     97    </Compile>
    9598    <Compile Include="Worker\JobParticipationWorker.cs">
    9699      <SubType>Component</SubType>
Note: See TracChangeset for help on using the changeset viewer.