Exemple #1
0
        /// <summary>
        /// One 'Produce' task generates chunks for one BackupRootDrive (ie 1 mountpoint/filesystem).
        /// </summary>
        /// <param name='bdr'>
        /// the BackupRootDrive to scan for items
        /// </param>
        private void Produce(Queue <BackupRootDrive> queue /*, BlockingCollection<BChunk> myFeed*/)
        {
            BlockingCollection <BChunk> myFeed = new BlockingCollection <BChunk>(new ConcurrentQueue <BChunk>(), 1);

            Console.WriteLine("    ------- Producer() has " + queue.Count + " drive items in its queue");
            chunksFeeds.Add(myFeed);
            //IEnumerator<BChunk> chunkEnumerator = bdh.GetNextChunk().GetEnumerator();//backup.GetNextChunk().GetEnumerator();
            while (queue.Count > 0)
            {
                BackupRootDrive bdr = queue.Dequeue();
                Logger.Append(Severity.INFO, "Collecting items to backup for drive " + bdr.SystemDrive.MountPoint);
                BackupRootDriveHandler bdh = new BackupRootDriveHandler(bdr, this.backup.Id, backup.BackupSet.MaxChunkSize, backup.BackupSet.MaxChunkSize, backup.BackupSet.MaxChunkFiles, backup.Level, backup.RefStartDate, backup.RefEndDate, backup.ParentTrackingId);
                bdh.LogEvent           += LogReceived;
                bdh.SubCompletionEvent += new BackupRootDriveHandler.SubCompletionHandler(IncrementSubCompletion);
                foreach (P2PBackup.Common.BasePath baseP in bdr.Paths)
                {
                    bdh.SetCurrentPath(baseP);
                    IEnumerator <BChunk> chunkEnumerator = bdh.GetNextChunk().GetEnumerator();
                    while (chunkEnumerator.MoveNext() && !cancellationTokenSource.IsCancellationRequested)
                    {
                        BChunk chunk = chunkEnumerator.Current;
                        try{
                            myFeed.Add(chunk, cancellationTokenSource.Token);
                        }
                        catch (OperationCanceledException) {
                            Logger.Append(Severity.TRIVIA, "Producer has been manually cancelled on purpose, stopping...");
                            return;
                        }
                        catch (Exception e) {
                            Logger.Append(Severity.ERROR, "###################### Produce()	: add refused : " + e.Message + " ---- " + e.StackTrace);
                            return;
                        }
                        // stats
                        foreach (IFSEntry item in chunk.Items)
                        {
                            backup.ItemsByType[(int)item.Kind]++;
                        }
                        Logger.Append(Severity.DEBUG, "Basepath " + baseP.Path + " : Added chunk " + chunk.Name + " containing " + chunk.Items.Count + " items ");
                    }
                }
                bdh.SubCompletionEvent -= new BackupRootDriveHandler.SubCompletionHandler(IncrementSubCompletion);
                bdh.LogEvent           -= LogReceived;
                if (!cancellationTokenSource.IsCancellationRequested)
                {
                    ContinueProducing();
                }
                else
                {
                    bdh.Dispose();
                }
            }
            Console.WriteLine("------------------------- PRODUCE(): done collecting ALL, complete feed adding, cancellationTokenSource.IsCancellationRequested=" + cancellationTokenSource.IsCancellationRequested);
            myFeed.CompleteAdding();
        }
Exemple #2
0
        /// <summary>
        /// One 'Produce' task generates chunks for one BackupRootDrive (ie 1 mountpoint).
        /// </summary>
        /// <param name='bdr'>
        /// the BackupRootDrive to scan for items
        /// </param>
        private void Produce(BackupRootDrive bdr)
        {
            Logger.Append(Severity.INFO, "Collecting items to backup for drive " + bdr.SystemDrive.MountPoint);
            BackupRootDriveHandler bdh = new BackupRootDriveHandler(bdr, this.backup.TaskId, backup.MaxChunkSize, backup.MaxChunkSize, backup.MaxChunkFiles, backup.Level, backup.RefStartDate, backup.RefEndDate, backup.RefTaskId);

            bdh.LogEvent           += LogReceived;
            bdh.SubCompletionEvent += new BackupRootDriveHandler.SubCompletionHandler(IncrementSubCompletion);

            //IEnumerator<BChunk> chunkEnumerator = bdh.GetNextChunk().GetEnumerator();//backup.GetNextChunk().GetEnumerator();

            foreach (P2PBackup.Common.BasePath baseP in bdr.Paths)
            {
                bdh.SetCurrentPath(baseP);
                IEnumerator <BChunk> chunkEnumerator = bdh.GetNextChunk().GetEnumerator();
                while (chunkEnumerator.MoveNext() && !cancellationTokenSource.IsCancellationRequested)
                {
                    BChunk chunk = chunkEnumerator.Current;
                    try{
                        chunkBuilderFeed.Add(chunk, cancellationTokenSource.Token);
                    }
                    catch (OperationCanceledException) {
                        Logger.Append(Severity.DEBUG2, "Producer has been manually cancelled on purpose, stopping...");
                        return;
                    }
                    catch (Exception e) {
                        Logger.Append(Severity.ERROR, "###################### Produce()	: add refused : " + e.Message + " ---- " + e.StackTrace);
                        return;
                    }
                    // stats
                    foreach (IFSEntry item in chunk.Files)
                    {
                        backup.ItemsByType[(int)item.Kind]++;
                    }
                    Logger.Append(Severity.DEBUG, "Added chunk " + chunk.Name + " containing " + chunk.Files.Count + " items ");
                }
            }
            bdh.SubCompletionEvent -= new BackupRootDriveHandler.SubCompletionHandler(IncrementSubCompletion);
            bdh.LogEvent           -= LogReceived;
            Logger.Append(Severity.INFO, "Producer has done collecting items to backup for drive " + bdr.SystemDrive.MountPoint);
            if (!cancellationTokenSource.IsCancellationRequested)
            {
                ContinueProducing();
            }
            else
            {
                bdh.Dispose();
            }
        }