Ejemplo n.º 1
0
            public void WriteEndOfFile()
            {
                _originalCache.WriteScanIds(_outputStreamScans);

                ChromatogramCache.WriteStructs(_outputStream,
                                               _outputStreamScans,
                                               _outputStreamPeaks,
                                               _outputStreamScores,
                                               _originalCache.CachedFiles,
                                               _chromGroupHeaderInfos,
                                               _transitions,
                                               _scoreTypes,
                                               _scoreCount,
                                               _peakCount,
                                               _originalCache);
            }
Ejemplo n.º 2
0
        protected void Complete(Exception x)
        {
            lock (this)
            {
                ChromatogramCache result = null;
                try
                {
                    if (x == null && !_status.IsFinal)
                    {
                        long locationScanIds = 0, countBytesScanIds = 0;
                        if (_fs.Stream != null)
                        {
                            try
                            {
                                locationScanIds   = _fs.Stream.Position;
                                countBytesScanIds = _fsScans.Stream.Position;

                                ChromatogramCache.WriteStructs(_fs.Stream,
                                                               _fsScans.Stream,
                                                               _fsPeaks.Stream,
                                                               _fsScores.Stream,
                                                               _listCachedFiles,
                                                               _listGroups,
                                                               _listTransitions,
                                                               _listTextIdBytes,
                                                               _listScoreTypes,
                                                               _scoreCount,
                                                               _peakCount);

                                _loader.StreamManager.Finish(_fs.Stream);
                                _fs.Stream = null;
                                // Allow cancelation right up to the final commit
                                if (!_loader.IsCanceled)
                                {
                                    _fs.Commit(_destinationStream);
                                }
                                else
                                {
                                    _loader.UpdateProgress(_status = _status.Cancel());
                                }
                            }
                            catch (Exception xWrite)
                            {
                                throw new IOException(TextUtil.LineSeparate(string.Format(Resources.ChromCacheWriter_Complete_Failure_attempting_to_write_the_file__0_, _fs.RealName), xWrite.Message));
                            }
                        }

                        if (!_status.IsCanceled)
                        {
                            // Create stream identifier, but do not open.  The stream will be opened
                            // the first time the document uses it.
                            var readStream = _loader.StreamManager.CreatePooledStream(CachePath, false);

                            // DebugLog.Info("{0}. {1} - created", readStream.GlobalIndex, CachePath);

                            _fsPeaks.Stream.Seek(0, SeekOrigin.Begin);
                            _fsScores.Stream.Seek(0, SeekOrigin.Begin);
                            var rawData = new ChromatogramCache.RawData
                            {
                                FormatVersion       = ChromatogramCache.FORMAT_VERSION_CACHE,
                                ChromCacheFiles     = _listCachedFiles.ToArray(),
                                ChromatogramEntries = _listGroups.ToArray(),
                                ChromTransitions    = _listTransitions.ToArray(),
                                ChromatogramPeaks   = new BlockedArray <ChromPeak>(
                                    count => ChromPeak.ReadArray(_fsPeaks.FileStream, count), _peakCount,
                                    ChromPeak.SizeOf, ChromPeak.DEFAULT_BLOCK_SIZE),
                                ScoreTypes = _listScoreTypes.ToArray(),
                                Scores     = new BlockedArray <float>(
                                    count => PrimitiveArrays.Read <float>(_fsScores.FileStream, count), _scoreCount,
                                    sizeof(float), ChromatogramCache.DEFAULT_SCORES_BLOCK_SIZE),
                                TextIdBytes       = _listTextIdBytes.ToArray(),
                                LocationScanIds   = locationScanIds,
                                CountBytesScanIds = countBytesScanIds,
                            };
                            result  = new ChromatogramCache(CachePath, rawData, readStream);
                            _status = _status.Complete();
                            _loader.UpdateProgress(_status);
                        }
                    }
                }
                catch (Exception x2)
                {
                    x = x2;
                }
                finally
                {
                    Dispose();
                }

                try
                {
                    _completed(result, x == null ? _status : _status.ChangeErrorException(x));
                }
                catch (Exception x2)
                {
                    _completed(null, _status.ChangeErrorException(x2));
                }
            }
        }
Ejemplo n.º 3
0
        protected void Complete(Exception x)
        {
            lock (this)
            {
                ChromatogramCache result = null;
                try
                {
                    if (x == null && !_status.IsFinal)
                    {
                        long locationScanIds = 0, countBytesScanIds = 0;
                        if (_fs.Stream != null)
                        {
                            locationScanIds   = _fs.Stream.Position;
                            countBytesScanIds = _fsScans.Stream.Position;

                            ChromatogramCache.WriteStructs(_fs.Stream,
                                                           _fsScans.Stream,
                                                           _fsPeaks.Stream,
                                                           _fsScores.Stream,
                                                           _listCachedFiles,
                                                           _listGroups,
                                                           _listTransitions,
                                                           _listTextIdBytes,
                                                           _listScoreTypes,
                                                           _scoreCount,
                                                           _peakCount);

                            _loader.StreamManager.Finish(_fs.Stream);
                            _fs.Stream = null;
                            _fs.Commit(_destinationStream);
                        }

                        // Create stream identifier, but do not open.  The stream will be opened
                        // the first time the document uses it.
                        var readStream = _loader.StreamManager.CreatePooledStream(CachePath, false);

                        _fsPeaks.Stream.Seek(0, SeekOrigin.Begin);
                        _fsScores.Stream.Seek(0, SeekOrigin.Begin);
                        var rawData = new ChromatogramCache.RawData
                        {
                            FormatVersion       = ChromatogramCache.FORMAT_VERSION_CACHE,
                            ChromCacheFiles     = _listCachedFiles.ToArray(),
                            ChromatogramEntries = _listGroups.ToArray(),
                            ChromTransitions    = _listTransitions.ToArray(),
                            ChromatogramPeaks   = new BlockedArray <ChromPeak>(
                                count => ChromPeak.ReadArray(_fsPeaks.FileStream.SafeFileHandle, count), _peakCount,
                                ChromPeak.SizeOf, ChromPeak.DEFAULT_BLOCK_SIZE),
                            ScoreTypes = _listScoreTypes.ToArray(),
                            Scores     = new BlockedArray <float>(
                                count => PrimitiveArrays.Read <float>(_fsScores.FileStream, count), _scoreCount,
                                sizeof(float), ChromatogramCache.DEFAULT_SCORES_BLOCK_SIZE),
                            TextIdBytes       = _listTextIdBytes.ToArray(),
                            LocationScanIds   = locationScanIds,
                            CountBytesScanIds = countBytesScanIds,
                        };
                        result = new ChromatogramCache(CachePath, rawData, readStream);
                        _loader.UpdateProgress(_status.Complete());
                    }
                }
                catch (Exception x2)
                {
                    x = x2;
                }
                finally
                {
                    Dispose();
                }

                try
                {
                    _completed(result, x);
                }
                catch (Exception x2)
                {
                    _completed(null, x2);
                }
            }
        }