示例#1
0
        private IDataPacket RescanDataPackets(IEnumerable <IDataPacket> dataPackets, IDataReaderPool dataReaderPool, IProgressReporter progressReporter)
        {
            IDataPacket concatenatedDataPacket = null;

            long totalByteCount = dataPackets.Sum(x => x.Length);
            long bytesSaved     = 0L;

            foreach (IDataPacket dataPacket in dataPackets)
            {
                if (progressReporter.CancellationPending)
                {
                    return(null);
                }

                IDataPacket rescannedDataPacket = dataPacket;
                if (dataPacket is ICodecStream)
                {
                    // FIXME: This check should not be necessary, but the user interface is not
                    //        consistent in rescanning data packets: either in the user interface
                    //        itself, or in the framework!
                    if (dataPacket is RescannedCodecStream)
                    {
                        // Note: data packet is already rescanned, so just append it ...
                        rescannedDataPacket = dataPacket;
                    }
                    else
                    {
                        IProgressReporter rescanProgressReporter = _createSubProgressReporter(progressReporter, bytesSaved, dataPacket.Length, totalByteCount);
                        rescannedDataPacket = _dataBlockScanner.GetData(dataPacket as ICodecStream, rescanProgressReporter, dataReaderPool);
                    }
                }

                concatenatedDataPacket = (concatenatedDataPacket == null) ? rescannedDataPacket : concatenatedDataPacket.Append(rescannedDataPacket);

                bytesSaved += dataPacket.Length;
            }
            return(concatenatedDataPacket);
        }
示例#2
0
        /// <summary>
        /// Gets the data of the entire detectable using all related fragments.
        /// </summary>
        /// <param name="detectable">the detectable</param>
        /// <returns>the complete data of the detectable</returns>
        private IDataPacket GetCompleteFragmentData(IFragment detectable, IProgressReporter progressReporter, IDataReaderPool dataReaderPool)
        {
            if ((detectable is IDataBlock) && (detectable.FragmentContainer == null))
            {
                // Unfragmented data block
                return(detectable);
            }

            IDataPacket data = null;

            if (detectable is IDataBlock)
            {
                // Fragmented data block
                foreach (IFragment fragment in detectable.FragmentContainer)
                {
                    data = (data == null) ? fragment : data.Append(fragment);
                }
                return(data);
            }

            if (!(detectable is ICodecStream))
            {
                throw new ArgumentException("Not an IDataBlock or ICodecStream", "detectable");
            }

            ICodecStream codecStream = (detectable as ICodecStream);
            IDataBlock   parent      = codecStream.DataBlock;

            if (parent.FragmentContainer == null)
            {
                if (detectable.FragmentContainer == null)
                {
                    // Unfragmented codec stream
                    return(_dataBlockScanner.GetData(detectable as ICodecStream, progressReporter, dataReaderPool));
                }

                // Fragmented codec stream
                foreach (IFragment fragment in detectable.FragmentContainer)
                {
                    IDataPacket fragmentData = _dataBlockScanner.GetData(fragment as ICodecStream, progressReporter, dataReaderPool);
                    if (progressReporter.CancellationPending)
                    {
                        return(null);
                    }

                    data = (data == null) ? fragmentData : data.Append(fragmentData);
                }
                return(data);
            }

            int streamIndex = codecStream.StreamNumber;

            // Fragmented codec stream in a fragmented data block
            foreach (IFragment dbFragment in parent.FragmentContainer)
            {
                foreach (ICodecStream fragment in ((IDataBlock)dbFragment).CodecStreams)
                {
                    if (fragment.StreamNumber == streamIndex)
                    {
                        IDataPacket fragmentData = _dataBlockScanner.GetData(fragment, progressReporter, dataReaderPool);
                        if (progressReporter.CancellationPending)
                        {
                            return(null);
                        }

                        data = (data == null) ? fragmentData : data.Append(fragmentData);
                    }
                }
            }
            return(data);
        }