Ejemplo n.º 1
0
        public ChromatogramCache GenerateChromatograms(ChorusAccount chorusAccount,
                                                       ChorusUrl chorusUrl,
                                                       ChromatogramRequestDocument chromatogramRequestDocument)
        {
            var webRequest = (HttpWebRequest)WebRequest.Create(chorusUrl.GetChromExtractionUri());

            AddAuthHeader(chorusAccount, webRequest);
            webRequest.Method = "POST"; // Not L10N
            var xmlSerializer = new XmlSerializer(typeof(ChromatogramRequestDocument));

            xmlSerializer.Serialize(webRequest.GetRequestStream(), chromatogramRequestDocument);
            webRequest.GetRequestStream().Close();
            return(SendRequest(webRequest, response =>
            {
                MemoryStream memoryStream = new MemoryStream();
                var responseStream = response.GetResponseStream();
                if (responseStream != null)
                {
                    byte[] buffer = new byte[65536];
                    int count;
                    while ((count = responseStream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        memoryStream.Write(buffer, 0, count);
                    }
                }
                if (0 == memoryStream.Length)
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new IOException(string.Format("Empty response: status = {0}", response.StatusCode)); // Not L10N
                    }
                    Debug.WriteLine("Zero byte response");                                                         // Not L10N
                    return null;
                }
                ChromatogramCache.RawData rawData;
                ChromatogramCache.LoadStructs(memoryStream, out rawData);
                var chromCacheFile = rawData.ChromCacheFiles[0];
                rawData.ChromCacheFiles = new[]
                {
                    new ChromCachedFile(chorusUrl, chromCacheFile.Flags, chromCacheFile.FileWriteTime,
                                        chromCacheFile.RunStartTime, chromCacheFile.MaxRetentionTime, chromCacheFile.MaxIntensity,
                                        chromCacheFile.InstrumentInfoList),
                };
                return new ChromatogramCache(string.Empty, rawData,
                                             new ChromatogramGeneratorTask.MemoryPooledStream(memoryStream));
            }));
        }
Ejemplo n.º 2
0
        public ChorusResponseChromDataProvider(SrmDocument document, ChromFileInfo chromFileInfo, IProgressStatus progressStatus, int startPercent,
                                               int endPercent, ILoadMonitor loader) : base(chromFileInfo, progressStatus, startPercent, endPercent, loader)
        {
            ChromatogramCache.RawData rawData;
            MsDataFilePath            msDataFilePath = (MsDataFilePath)chromFileInfo.FilePath;
            IPooledStream             stream         = loader.StreamManager.CreatePooledStream(msDataFilePath.FilePath, false);

            ChromatogramCache.LoadStructs(stream.Stream, out rawData);
            var chromCacheFile = rawData.ChromCacheFiles[0];

            rawData.ChromCacheFiles = new[]
            {
                new ChromCachedFile(chromFileInfo.FilePath, chromCacheFile.Flags, chromCacheFile.FileWriteTime,
                                    chromCacheFile.RunStartTime, chromCacheFile.MaxRetentionTime, chromCacheFile.MaxIntensity,
                                    chromCacheFile.InstrumentInfoList),
            };
            var cache = new ChromatogramCache("cachePath", rawData, stream); // Not L10N

            _cachedChromatogramDataProvider = new CachedChromatogramDataProvider(cache, document,
                                                                                 chromFileInfo.FilePath, chromFileInfo, null, progressStatus, startPercent, endPercent, loader);
        }
Ejemplo n.º 3
0
        private bool JoinNextPart()
        {
            // Check for cancellation on every part.
            if (_loader.IsCanceled)
            {
                _loader.UpdateProgress(_status = _status.Cancel());
                Complete(null);
                return(false);
            }

            if (_currentPartIndex >= CacheFilePaths.Count)
            {
                Complete(null);
                return(false);
            }

            // If not cancelled, update progress.
            string cacheFilePath = CacheFilePaths[_currentPartIndex];
            string message       = string.Format(Resources.ChromCacheJoiner_JoinNextPart_Joining_file__0__, cacheFilePath);
            int    percent       = _currentPartIndex * 100 / CacheFilePaths.Count;

            _status = _status.ChangeMessage(message).ChangePercentComplete(percent);
            _loader.UpdateProgress(_status);

            try
            {
                using (var inStream = _loader.StreamManager.CreateStream(cacheFilePath, FileMode.Open, false))
                {
                    if (_fs.Stream == null)
                    {
                        _fs.Stream = _loader.StreamManager.CreateStream(_fs.SafeName, FileMode.Create, true);
                    }

                    ChromatogramCache.RawData rawData;
                    long bytesData = ChromatogramCache.LoadStructs(inStream, out rawData);

                    // If joining, then format version should have already been checked.
                    Assume.IsTrue(ChromatogramCache.IsVersionCurrent(rawData.FormatVersion) ||
                                  // WatersCacheTest uses older format partial caches
                                  rawData.FormatVersion == ChromatogramCache.FORMAT_VERSION_CACHE_2);

                    int  offsetFiles       = _listCachedFiles.Count;
                    int  offsetTransitions = _listTransitions.Count;
                    int  offsetPeaks       = _peakCount;
                    int  offsetScores      = _scoreCount;
                    long offsetPoints      = _fs.Stream.Position;

                    // Scan ids
                    long offsetScanIds = _fsScans.Stream.Position;
                    _listCachedFiles.AddRange(rawData.ChromCacheFiles.Select(f => f.RelocateScanIds(f.LocationScanIds + offsetScanIds)));
                    if (rawData.CountBytesScanIds > 0)
                    {
                        inStream.Seek(rawData.LocationScanIds, SeekOrigin.Begin);
                        inStream.TransferBytes(_fsScans.Stream, rawData.CountBytesScanIds);
                    }

                    _peakCount += rawData.ChromatogramPeaks.Length;
                    rawData.ChromatogramPeaks.WriteArray(block => ChromPeak.WriteArray(_fsPeaks.FileStream.SafeFileHandle, block));
                    _listTransitions.AddRange(rawData.ChromTransitions);
                    // Initialize the score types the first time through
                    if (_scoreTypesCount == -1)
                    {
                        _listScoreTypes.AddRange(rawData.ScoreTypes);
                        _scoreTypesCount = _listScoreTypes.Count;
                    }
                    else if (!ArrayUtil.EqualsDeep(_listScoreTypes, rawData.ScoreTypes))
                    {
                        // If the existing score types in the caches are not the same, the caches cannot be joined
                        if (_listScoreTypes.Intersect(rawData.ScoreTypes).Count() != _listScoreTypes.Count)
                        {
                            throw new InvalidDataException("Data cache files with different score types cannot be joined.");    // Not L10N
                        }
                    }
                    _scoreCount += rawData.Scores.Length;
                    rawData.Scores.WriteArray(block => PrimitiveArrays.Write(_fsScores.Stream, block));

                    for (int i = 0; i < rawData.ChromatogramEntries.Length; i++)
                    {
                        rawData.RecalcEntry(i,
                                            offsetFiles,
                                            offsetTransitions,
                                            offsetPeaks,
                                            offsetScores,
                                            offsetPoints,
                                            _dictTextIdToByteIndex,
                                            _listTextIdBytes);
                    }
                    _listGroups.AddRange(rawData.ChromatogramEntries);

                    inStream.Seek(0, SeekOrigin.Begin);

                    long copyBytes = bytesData;
                    while (copyBytes > 0)
                    {
                        int read = inStream.Read(_buffer, 0, (int)Math.Min(_buffer.Length, copyBytes));
                        _fs.Stream.Write(_buffer, 0, read);
                        copyBytes -= read;
                    }

                    _currentPartIndex++;
                    return(true);
                }
            }
            catch (InvalidDataException x)
            {
                Complete(x);
            }
            catch (IOException x)
            {
                Complete(x);
            }
            catch (Exception x)
            {
                Complete(new Exception(String.Format(Resources.ChromCacheJoiner_JoinNextPart_Failed_to_create_cache__0__, CachePath), x));
            }
            return(false);
        }