Changeset 1178


Ignore:
Timestamp:
Feb 24, 2010, 1:24:59 PM (12 years ago)
Author:
arnold
Message:

P2PManager: Added a job distribution Expander in the QuickWatchPresentation
Bug fixes: Cyclic Register-Message-Sending, Allocating more than one job to each worker

Location:
trunk/CrypPlugins
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeyPatternJob/DistributableKeyPatternJob.cs

    r1137 r1178  
    4646        /// Use the JobId existing in the KeyPatternJobPart-Element.
    4747        /// </summary>
    48         BigInteger jobIdCounter = 1;
     48        BigInteger jobIdCounter = 0;
    4949        /// <summary>
    5050        /// main pattern stack
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManagerBase_NEW.cs

    r1173 r1178  
    4444        public delegate void NewJobAllocated(BigInteger jobId);
    4545        public delegate void ResultReceived(BigInteger jobId);
     46        public delegate void JobCanceled(BigInteger jobId);
    4647        public delegate void NoMoreJobsLeft();
    4748        public delegate void AllJobResultsReceived(BigInteger lastJobId);
     
    5657        /// </summary>
    5758        public event ResultReceived OnResultReceived;
     59        /// <summary>
     60        /// is thrown when an active worker leaves the network and the jobs come back
     61        /// </summary>
     62        public event JobCanceled OnJobCanceled;
    5863        /// <summary>
    5964        /// When the last job from the DistributableJob-Stack is allocated, but
     
    383388                    this.distributableJobControl.Push(jobId);
    384389                    this.jobsInProgress.Remove(jobId);
     390                    if (OnJobCanceled != null)
     391                        OnJobCanceled(jobId);
    385392                    GuiLogging("Pushed job '" + jobId.ToString() + "' back to the stack, because peer left the network.", NotificationLevel.Debug);
    386393                }
     
    414421            int i = 0;
    415422            BigInteger temp_jobId = null;
    416             List<PeerId> freePeers = ((WorkersManagement)this.peerManagement).GetAllSubscribers();
     423            List<PeerId> freePeers = ((WorkersManagement)this.peerManagement).GetFreeWorkers();
    417424
    418425            GuiLogging("Trying to allocate " + freePeers.Count + " job(s) to workers.", NotificationLevel.Debug);
     
    428435                {
    429436                    this.jobsWaitingForAcceptanceInfo.Add(temp_jobId, worker);
     437
     438                    // set free worker to busy in the peerManagement class
     439                    ((WorkersManagement)this.peerManagement).SetFreeWorkerToBusy(worker);
     440
    430441                    // get actual subscriber/worker and send the new job
    431442                    base.p2pControl.SendToPeer(JobMessages.CreateJobPartMessage(temp_jobId, serializedNewJob), worker);
     
    433444                    if (OnNewJobAllocated != null)
    434445                        OnNewJobAllocated(temp_jobId);
    435 
    436                     // set free worker to busy in the peerManagement class
    437                     ((WorkersManagement)this.peerManagement).SetFreeWorkerToBusy(worker);
    438446
    439447                    GuiLogging("Job '" + temp_jobId.ToString() + "' were sent to worker id '" + worker.ToString() + "'", NotificationLevel.Info);
     
    446454                        OnNoMoreJobsLeft();
    447455                }
    448                 GuiLogging(i + " Job(s) allocated to worker(s).", NotificationLevel.Debug);
    449456            } // end foreach
     457            GuiLogging(i + " Job(s) allocated to worker(s).", NotificationLevel.Debug);
    450458        }
    451459
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManagerPresentation.xaml

    r1173 r1178  
    22    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    33    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     4    xmlns:my="clr-namespace:Cryptool.Plugins.PeerToPeer"
    45    HorizontalAlignment="Stretch"
    56    VerticalAlignment="Stretch"
     
    1011
    1112    <Canvas Name="Canvas" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
    12         <Grid Name="Grid" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
     13        <Grid Name="Grid1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
    1314            <Grid.RowDefinitions>
     15                <RowDefinition Height="Auto"/>
    1416                <RowDefinition Height="Auto"/>
    1517                <RowDefinition Height="Auto"/>
     
    8486            </Expander>
    8587
    86             <Expander Name="Expander_List" Header="Global Top 10 List" IsExpanded="True" FontSize="10" Grid.Row="1">
     88            <Expander Name="Expander_List" Header="Global Top 10 List" IsExpanded="True" FontSize="10" Grid.Row="2">
    8789                <ListView Name="ListView" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Auto"  ScrollViewer.VerticalScrollBarVisibility="Auto" FontSize="7" MaxWidth="200">
    8890                    <ListView.View>
     
    9799            </Expander>
    98100
    99             <Expander Name="Expander_WorkerInfo" Header="Worker Info" IsExpanded="False" FontSize="10" Grid.Row="2">
     101            <Expander Name="Expander_WorkerInfo" Header="Worker Info" IsExpanded="False" FontSize="10" Grid.Row="3">
    100102                <Grid Name="WorkerGrid">
    101103                    <Grid.RowDefinitions>
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManagerPresentation.xaml.cs

    r1173 r1178  
    4444        }
    4545
     46        public ProgressChunks PrgChunks = new ProgressChunks();
     47
    4648        #endregion
    4749
     
    5153            this.SizeChanged += new SizeChangedEventHandler(P2PManagerPresentation_SizeChanged);
    5254            this.DataContext = entries;
    53             // when expanding Expanders, resize layout
    54             this.Expander_JobStatus.MouseLeftButtonUp += new MouseButtonEventHandler(Expander_JobStatus_MouseLeftButtonUp);
    55             this.Expander_List.MouseLeftButtonUp += new MouseButtonEventHandler(Expander_List_MouseLeftButtonUp);
    56             this.Expander_WorkerInfo.MouseLeftButtonUp += new MouseButtonEventHandler(Expander_WorkerInfo_MouseLeftButtonUp);
    5755
     56            this.txtTotal.SizeChanged += new SizeChangedEventHandler(txtTotal_SizeChanged);
     57            //this.txtTotal.TextChanged += new TextChangedEventHandler(txtTotal_TextChanged);
     58
     59
     60            this.Expander_WorkerInfo.SizeChanged += new SizeChangedEventHandler(Expander_WorkerInfo_SizeChanged);
     61            this.Expander_List.SizeChanged += new SizeChangedEventHandler(Expander_List_SizeChanged);
     62            this.Expander_JobStatus.SizeChanged += new SizeChangedEventHandler(Expander_JobStatus_SizeChanged);
    5863
    5964            this.SourceUpdated += new EventHandler<DataTransferEventArgs>(P2PManagerPresentation_SourceUpdated);
    6065            // when you uncomment this line, you burn 70% of the whole CPU time for Resizing this view...
    6166            //this.LayoutUpdated += new EventHandler(P2PManagerPresentation_LayoutUpdated);
    62             this.Expander_JobStatus.Expanded += new RoutedEventHandler(Expander_JobStatus_Expanded);
    63             this.Expander_List.Expanded += new RoutedEventHandler(Expander_List_Expanded);
    64             this.Expander_WorkerInfo.Expanded += new RoutedEventHandler(Expander_WorkerInfo_Expanded);
    65             //this.ListView.DataContextChanged += new DependencyPropertyChangedEventHandler(ListView_DataContextChanged);
    66             //this.ListView.SizeChanged += new SizeChangedEventHandler(ListView_SizeChanged);
    6767            this.ListView.SourceUpdated += new EventHandler<DataTransferEventArgs>(ListView_SourceUpdated);
    6868
    6969            LinearGradientBrush blueBrush = GetGradientBlue();
     70            LinearGradientBrush grayBrush = GetGradientGray();
    7071
    7172            this.MngrMain.Background = blueBrush;
    7273            this.Expander_JobStatus.Background = blueBrush;
    73             this.Expander_WorkerInfo.Background = blueBrush;
    74             this.Expander_List.Background = GetGradientGray();
     74           
     75            Expander exp_chunk = new Expander();
     76            exp_chunk.Content = PrgChunks;
     77            exp_chunk.Header = "Visual Job Distribution";
     78            exp_chunk.FontSize = 10;
     79            exp_chunk.Background = grayBrush;
     80            this.PrgChunks.Width = 200;
     81            this.PrgChunks.Height = 55;
     82            Grid.SetRow(exp_chunk, 1);
     83            this.Grid1.Children.Add(exp_chunk);
     84
     85            this.Expander_List.Background = blueBrush;
     86            this.Expander_WorkerInfo.Background = grayBrush;
    7587        }
    7688
    77         void Expander_WorkerInfo_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
     89        //void txtTotal_TextChanged(object sender, TextChangedEventArgs e)
     90        //{
     91        //    int iResult;
     92        //    if (Int32.TryParse(this.txtTotal.Text, out iResult))
     93        //    {
     94        //        PrgChunks.JobCount = iResult;
     95        //        PrgChunks[0] = Brushes.HotPink;
     96        //        PrgChunks[iResult - 1] = Brushes.HotPink;
     97        //    }
     98        //}
     99
     100        void txtTotal_SizeChanged(object sender, SizeChangedEventArgs e)
    78101        {
    79102            FunnyResize();
    80103        }
    81104
    82         void Expander_List_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
     105        void Expander_JobStatus_SizeChanged(object sender, SizeChangedEventArgs e)
    83106        {
    84107            FunnyResize();
    85108        }
    86109
    87         void Expander_JobStatus_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
     110        void Expander_List_SizeChanged(object sender, SizeChangedEventArgs e)
    88111        {
    89112            FunnyResize();
    90113        }
    91114
    92         void txtTotal_TextChanged(object sender, TextChangedEventArgs e)
     115        void Expander_WorkerInfo_SizeChanged(object sender, SizeChangedEventArgs e)
    93116        {
    94117            FunnyResize();
     
    102125        private void FunnyResize()
    103126        {
    104             this.Canvas.RenderTransform = new ScaleTransform(this.ActualWidth / this.Grid.ActualWidth,
    105                                                        this.ActualHeight / this.Grid.ActualHeight);
     127            this.Canvas.RenderTransform = new ScaleTransform(this.ActualWidth / this.Grid1.ActualWidth,
     128                                                       this.ActualHeight / this.Grid1.ActualHeight);
    106129        }
    107130
     
    110133            FunnyResize();
    111134        }       
    112 
    113         void Expander_WorkerInfo_Expanded(object sender, RoutedEventArgs e)
    114         {
    115             FunnyResize();
    116         }
    117 
    118         void Expander_List_Expanded(object sender, RoutedEventArgs e)
    119         {
    120             FunnyResize();
    121         }
    122 
    123         void Expander_JobStatus_Expanded(object sender, RoutedEventArgs e)
    124         {
    125             FunnyResize();
    126         }
    127135
    128136        public void P2PManagerPresentation_SizeChanged(object sender, SizeChangedEventArgs e)
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManager_KeyPattern.cs

    r1173 r1178  
    276276        }
    277277
     278        private void UpdateProgressChunk(BigInteger jobId, System.Windows.Media.Brush color)
     279        {
     280            // new Progress Chunk - Arnold 2010.02.23
     281            if (jobId.LongValue() <= Int32.MaxValue)
     282            {
     283                int iJobId = (int)jobId.LongValue();
     284                if (QuickWatchPresentation.IsVisible)
     285                {
     286                    ((P2PManagerPresentation)QuickWatchPresentation).Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     287                    {
     288                        if (((P2PManagerPresentation)QuickWatchPresentation).PrgChunks[iJobId] != null)
     289                            ((P2PManagerPresentation)QuickWatchPresentation).PrgChunks[iJobId] = color;
     290                    }, null);
     291                }
     292            }
     293        }
     294
     295        private void SetProgressChunkJobCount(BigInteger bigInteger)
     296        {
     297            if (bigInteger.LongValue() <= Int32.MaxValue)
     298            {
     299                int count = (int)bigInteger.LongValue();
     300                if (QuickWatchPresentation.IsVisible)
     301                {
     302                    ((P2PManagerPresentation)QuickWatchPresentation).Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     303                    {
     304                        ((P2PManagerPresentation)QuickWatchPresentation).PrgChunks.JobCount = count;
     305                    }, null);
     306                }
     307            }
     308        }
     309
    278310        #endregion
    279311
     
    476508                    (kp, this.settings.KeyPatternSize * 10000, byteEncryptedData, this.InitVector);
    477509
     510                //set progress chunk job count
     511                SetProgressChunkJobCount(this.distributableKeyPatternJob.TotalAmount);
     512
    478513                this.p2pManager = new P2PManagerBase_NEW(this.P2PControl, distributableKeyPatternJob);
    479514                this.p2pManager.OnGuiMessage += new P2PPublisherBase.GuiMessage(p2pManager_OnGuiMessage);
     
    482517                this.p2pManager.OnNoMoreJobsLeft += new P2PManagerBase_NEW.NoMoreJobsLeft(p2pManager_OnNoMoreJobsLeft);
    483518                this.p2pManager.OnResultReceived += new P2PManagerBase_NEW.ResultReceived(p2pManager_OnResultReceived);
     519                this.p2pManager.OnJobCanceled += new P2PManagerBase_NEW.JobCanceled(p2pManager_OnJobCanceled);
    484520            }
    485521
     
    491527        }
    492528
     529        void p2pManager_OnJobCanceled(BigInteger jobId)
     530        {
     531            UpdateProgressChunk(jobId, System.Windows.Media.Brushes.Red);
     532        }
     533
    493534        void p2pManager_OnResultReceived(BigInteger jobId)
    494535        {
     536            UpdateProgressChunk(jobId, System.Windows.Media.Brushes.Green);
     537
    495538            this.settings.MngStatusChanged(P2PManager_KeyPatternSettings.MngStatus.Finished);
    496539        }
     
    503546        void p2pManager_OnNewJobAllocated(BigInteger jobId)
    504547        {
     548            UpdateProgressChunk(jobId, System.Windows.Media.Brushes.Yellow);
     549
    505550            this.settings.MngStatusChanged(P2PManager_KeyPatternSettings.MngStatus.Working);
    506551        }
    507 
    508552
    509553        #region INotifyPropertyChanged Members
  • trunk/CrypPlugins/PeerToPeerManager_NEW/PeerToPeerManager_NEW.csproj

    r1137 r1178  
    6363    <Compile Include="P2PManager_KeyPattern.cs" />
    6464    <Compile Include="P2PManager_KeyPatternSettings.cs" />
     65    <Compile Include="ProgressChunks.xaml.cs">
     66      <DependentUpon>ProgressChunks.xaml</DependentUpon>
     67    </Compile>
    6568    <Compile Include="Properties\AssemblyInfo.cs" />
    6669    <Compile Include="P2PManagerPresentation.xaml.cs">
     
    105108      <Generator>MSBuild:Compile</Generator>
    106109    </Page>
     110    <Page Include="ProgressChunks.xaml">
     111      <Generator>MSBuild:Compile</Generator>
     112      <SubType>Designer</SubType>
     113    </Page>
    107114  </ItemGroup>
    108115  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Note: See TracChangeset for help on using the changeset viewer.