Beispiel #1
0
                protected override void Dispose(bool isDisposing)
                {
                    if (_isDisposed)
                    {
                        return;
                    }
                    _isDisposed = true;

                    if (isDisposing)
                    {
                        if (_bitmapManager != null)
                        {
                            try
                            {
                                _bitmapManager.Dispose();
                            }
                            catch (Exception)
                            {
                            }

                            _bitmapManager = null;
                        }
                    }
                }
Beispiel #2
0
            public Task CheckBlocks(Action <CheckBlocksProgressReport> progress, CancellationToken token)
            {
                return(Task.Run(() =>
                {
                    // 重複するセクタを確保したブロックを検出しRemoveする。
                    lock (_lockObject)
                    {
                        using (var bitmapManager = new BitmapManager(_bufferManager))
                        {
                            bitmapManager.SetLength(this.Size / SectorSize);

                            var hashes = new List <Hash>();

                            foreach (var(hash, clusterInfo) in _clusterIndex)
                            {
                                foreach (var sector in clusterInfo.Indexes)
                                {
                                    if (!bitmapManager.Get(sector))
                                    {
                                        bitmapManager.Set(sector, true);
                                    }
                                    else
                                    {
                                        hashes.Add(hash);

                                        break;
                                    }
                                }
                            }

                            foreach (var hash in hashes)
                            {
                                this.Remove(hash);
                            }
                        }
                    }

                    // 読めないブロックを検出しRemoveする。
                    {
                        var list = this.ToArray();

                        int badCount = 0;
                        int checkedCount = 0;
                        int blockCount = list.Length;

                        token.ThrowIfCancellationRequested();

                        progress.Invoke(new CheckBlocksProgressReport(badCount, checkedCount, blockCount));

                        foreach (var hash in list)
                        {
                            token.ThrowIfCancellationRequested();

                            ArraySegment <byte>?block = null;

                            try
                            {
                                lock (_lockObject)
                                {
                                    if (this.Contains(hash))
                                    {
                                        block = this.Get(hash);

                                        if (block == null)
                                        {
                                            badCount++;
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }
                            finally
                            {
                                if (block != null)
                                {
                                    _bufferManager.ReturnBuffer(block.Value.Array);
                                }
                            }

                            checkedCount++;

                            if (checkedCount % 32 == 0)
                            {
                                progress.Invoke(new CheckBlocksProgressReport(badCount, checkedCount, blockCount));
                            }
                        }

                        progress.Invoke(new CheckBlocksProgressReport(badCount, checkedCount, blockCount));
                    }
                }, token));
            }
Beispiel #3
0
 public SectorsManager(BufferManager bufferManager)
 {
     _bitmapManager = new BitmapManager(bufferManager);
     _bufferManager = bufferManager;
 }