Esempio n. 1
0
        public bool AsyncFetchContents(ChorusAccount chorusAccount, ChorusUrl chorusUrl, out ChorusServerException chorusException)
        {
            Uri requestUri = GetContentsUri(chorusAccount, chorusUrl);

            if (null == requestUri)
            {
                chorusException = null;
                return(true);
            }
            RequestKey requestKey = new RequestKey(chorusAccount, requestUri);

            lock (_lock)
            {
                ChorusContentsResponse chorusContentsResponse;
                if (_chorusContentsByServerUrl.TryGetValue(requestKey, out chorusContentsResponse))
                {
                    chorusException = chorusContentsResponse.ChorusException;
                    return(chorusContentsResponse.IsComplete);
                }
                chorusException = null;
                if (!_fetchRequests.Add(requestKey))
                {
                    return(false);
                }
            }
            ActionUtil.RunAsync(() => FetchAndStoreContents(chorusAccount, requestUri), "Fetch from Chorus");   // Not L10N
            return(false);
        }
Esempio n. 2
0
        private Uri GetContentsUri(ChorusAccount chorusAccount, ChorusUrl chorusUrl)
        {
            if (chorusUrl.FileId.HasValue)
            {
                return(null);
            }
            if (chorusUrl.ExperimentId.HasValue)
            {
                return(new Uri(chorusUrl.ServerUrl + "/skyline/api/contents/experiments/" + chorusUrl.ExperimentId + "/files")); // Not L10N
            }
            if (chorusUrl.ProjectId.HasValue)
            {
                return(new Uri(chorusUrl.ServerUrl + "/skyline/api/contents/projects/" + chorusUrl.ProjectId + "/experiments")); // Not L10N
            }
            if (!chorusUrl.GetPathParts().Any())
            {
                return(null);
            }
            string           topLevelName     = chorusUrl.GetPathParts().First();
            TopLevelContents topLevelContents = TOP_LEVEL_ITEMS.FirstOrDefault(item => item.Name.Equals(topLevelName));

            if (null != topLevelContents)
            {
                return(new Uri(chorusUrl.ServerUrl + "/skyline/api/contents" + topLevelContents.ContentsPath)); // Not L10N
            }
            return(null);
        }
Esempio n. 3
0
        private IEnumerable <ChorusItem> ListItems(ChorusUrl chorusUrl, ChorusContents chorusContents)
        {
            IEnumerable <ChorusItem> items = new ChorusItem[0];

            if (null != chorusContents.experiments)
            {
                items = items.Concat(chorusContents.experiments.Select(experiment =>
                                                                       new ChorusItem(chorusUrl.SetExperimentId(experiment.id).AddPathPart(experiment.GetName()),
                                                                                      experiment.GetName(), DataSourceUtil.FOLDER_TYPE, null, 0)));
            }
            if (null != chorusContents.files)
            {
                items = items.Concat(chorusContents.files.Select(
                                         file =>
                {
                    ChorusUrl fileUrl = chorusUrl.SetFileId(file.id)
                                        .AddPathPart(file.GetName())
                                        .SetFileWriteTime(file.GetModifiedDateTime())
                                        .SetRunStartTime(file.GetAcquisitionDateTime());
                    return(new ChorusItem(fileUrl, file.GetName(),
                                          GetFileType(file), file.GetModifiedDateTime(), file.fileSizeBytes));
                }
                                         ));
            }
            if (null != chorusContents.projects)
            {
                items = items.Concat(chorusContents.projects.Select(project =>
                                                                    new ChorusItem(chorusUrl.SetProjectId(project.id).AddPathPart(project.GetName()),
                                                                                   project.GetName(), DataSourceUtil.FOLDER_TYPE, null, project.GetSize())));
            }
            return(items);
        }
Esempio n. 4
0
        public MsDataSpectrum[] GetMsDataFileSpectraWithCommonRetentionTime(int dataFileSpectrumStartIndex)
        {
            double        precursor     = Transitions.Select(transition => transition.PrecursorMz).FirstOrDefault();
            ChorusAccount chorusAccount = ChorusUrl.FindChorusAccount(Settings.Default.ChorusAccountList);

            return(_chorusSession.GetSpectra(chorusAccount, ChorusUrl, Source, precursor, dataFileSpectrumStartIndex));
        }
 public ChromatogramGeneratorTask(ChromTaskList chromTaskList, ChorusAccount chorusAccount, ChorusUrl chorusUrl,
     ChromatogramRequestDocument chromatogramRequestDocument)
 {
     ChromTaskList = chromTaskList;
     ChorusAccount = chorusAccount;
     ChorusUrl = chorusUrl;
     ChromatogramRequestDocument = chromatogramRequestDocument;
 }
Esempio n. 6
0
 private ChorusAccount GetChorusAccount(ChorusUrl chorusUrl)
 {
     return
         (_chorusAccounts.FirstOrDefault(
              chorusAccount =>
              Equals(chorusAccount.ServerUrl, chorusUrl.ServerUrl) &&
              Equals(chorusAccount.Username, chorusUrl.Username)));
 }
Esempio n. 7
0
 public ChorusItem(ChorusUrl chorusUrl, string label, string type, DateTime?lastModified, long fileSizeBytes)
 {
     ChorusUrl    = chorusUrl;
     Label        = label;
     Type         = type;
     LastModified = lastModified;
     FileSize     = (ulong)fileSizeBytes;
 }
Esempio n. 8
0
 public ChorusItem(ChorusUrl chorusUrl, string label, string type, DateTime? lastModified, long fileSizeBytes)
 {
     ChorusUrl = chorusUrl;
     Label = label;
     Type = type;
     LastModified = lastModified;
     FileSize = (ulong) fileSizeBytes;
 }
Esempio n. 9
0
 public ChromatogramGeneratorTask(ChromTaskList chromTaskList, ChorusAccount chorusAccount, ChorusUrl chorusUrl,
                                  ChromatogramRequestDocument chromatogramRequestDocument)
 {
     ChromTaskList = chromTaskList;
     ChorusAccount = chorusAccount;
     ChorusUrl     = chorusUrl;
     ChromatogramRequestDocument = chromatogramRequestDocument;
 }
 public ChromatogramRequestProvider(SrmDocument srmDocument, ChorusUrl chorusUrl, IRetentionTimePredictor retentionTimePredictor, bool firstPass)
 {
     _srmDocument = srmDocument;
     _chorusUrl = chorusUrl;
     _retentionTimePredictor = retentionTimePredictor;
     _firstPass = firstPass;
     // Create a SpectrumFilter without an IRetentionTimeProvider in order to get the list of ChromKeys that we will eventually provide.
     SpectrumFilter spectrumFilter = new SpectrumFilter(_srmDocument, _chorusUrl, null);
     _chromKeys = ImmutableList.ValueOf(ListChromKeys(GetChromatogramRequestDocument(spectrumFilter)));
 }
Esempio n. 11
0
 public ChorusScanProvider(string docFilePath, ChorusUrl chorusUrl, ChromSource source, float[] times,
     TransitionFullScanInfo[] transitions)
 {
     ChorusUrl = chorusUrl;
     DocFilePath = docFilePath;
     DataFilePath = chorusUrl;
     Source = source;
     Times = times;
     Transitions = transitions;
     _chorusSession = new ChorusSession();
 }
Esempio n. 12
0
        public ChromatogramRequestProvider(SrmDocument srmDocument, ChorusUrl chorusUrl, IRetentionTimePredictor retentionTimePredictor, bool firstPass)
        {
            _srmDocument            = srmDocument;
            _chorusUrl              = chorusUrl;
            _retentionTimePredictor = retentionTimePredictor;
            _firstPass              = firstPass;
            // Create a SpectrumFilter without an IRetentionTimeProvider in order to get the list of ChromKeys that we will eventually provide.
            SpectrumFilter spectrumFilter = new SpectrumFilter(_srmDocument, _chorusUrl, null);

            _chromKeys = ImmutableList.ValueOf(ListChromKeys(GetChromatogramRequestDocument(spectrumFilter)));
        }
Esempio n. 13
0
 public ChorusScanProvider(string docFilePath, ChorusUrl chorusUrl, ChromSource source, float[] times,
                           TransitionFullScanInfo[] transitions)
 {
     ChorusUrl      = chorusUrl;
     DocFilePath    = docFilePath;
     DataFilePath   = chorusUrl;
     Source         = source;
     Times          = times;
     Transitions    = transitions;
     _chorusSession = new ChorusSession();
 }
Esempio n. 14
0
        public MsDataSpectrum[] GetSpectra(ChorusAccount chorusAccount, ChorusUrl chorusUrl, ChromSource source,
                                           SignedMz precursor, int scanId)
        {
            string strSource;
            int    msLevel = 1;

            // ReSharper disable NonLocalizedString
            switch (source)
            {
            case ChromSource.ms1:
                strSource = "ms1";
                break;

            case ChromSource.sim:
                strSource = "sim";
                break;

            case ChromSource.fragment:
                strSource = "ms2";
                msLevel   = 2;
                break;

            default:
                throw new ArgumentException("Unknown source " + source);
            }

            string strUri = string.Format(CultureInfo.InvariantCulture,
                                          "{0}/skyline/api/chroextract-drift/file/{1}/source/{2}/precursor/{3}/{4}",
                                          chorusUrl.ServerUrl,
                                          chorusUrl.FileId,
                                          strSource,
                                          precursor.RawValue, // This will be a negative value for negative ion mode data
                                          scanId);
            // ReSharper restore NonLocalizedString

            var webRequest = (HttpWebRequest)WebRequest.Create(new Uri(strUri));

            AddAuthHeader(chorusAccount, webRequest);
            return(SendRequest(webRequest, response =>
            {
                string strResponse = string.Empty;
                var responseStream = response.GetResponseStream();
                if (null != responseStream)
                {
                    var streamReader = new StreamReader(responseStream);
                    strResponse = streamReader.ReadToEnd();
                }
                JObject jObject = JsonConvert.DeserializeObject <JObject>(strResponse);
                JArray array = (JArray)jObject["results"];  // Not L10N
                return array.OfType <JObject>().Select(obj => GetSpectrumFromJObject(obj, msLevel)).ToArray();
            }));
        }
Esempio n. 15
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));
            }));
        }
Esempio n. 16
0
 public ChromTaskList(Action checkCancelledAction, SrmDocument srmDocument, ChorusAccount chorusAccount, ChorusUrl chorusUrl, IEnumerable<ChromatogramRequestDocument> chromatogramRequestDocuments)
 {
     SrmDocument = srmDocument;
     ChorusSession = new ChorusSession();
     _checkCancelledAction = checkCancelledAction;
     _chromatogramGeneratorTasks = new List<ChromatogramGeneratorTask>();
     _chromKeys = new Dictionary<ChromKey, ChromatogramGeneratorTask>();
     foreach (var chunk in chromatogramRequestDocuments)
     {
         ChromatogramGeneratorTask task = new ChromatogramGeneratorTask(this, chorusAccount, chorusUrl, chunk);
         _chromatogramGeneratorTasks.Add(task);
         foreach (ChromKey chromKey in ListChromKeys(chunk))
         {
             _chromKeys[chromKey] = task;
         }
     }
     _executingTasks = new HashSet<ChromatogramGeneratorTask>();
 }
Esempio n. 17
0
        public void RetryFetchContents(ChorusAccount chorusAccount, ChorusUrl chorusUrl)
        {
            Uri requestUri = GetContentsUri(chorusAccount, chorusUrl);

            if (null == requestUri)
            {
                return;
            }
            RequestKey requestKey = new RequestKey(chorusAccount, requestUri);

            lock (_lock)
            {
                if (_fetchRequests.Contains(requestKey))
                {
                    return;
                }
                _chorusContentsByServerUrl.Remove(requestKey);
                ChorusServerException exceptionIgnore;
                AsyncFetchContents(chorusAccount, chorusUrl, out exceptionIgnore);
            }
        }
Esempio n. 18
0
        public IEnumerable <ChorusItem> ListContents(ChorusAccount chorusAccount, ChorusUrl chorusUrl)
        {
            if (!chorusUrl.GetPathParts().Any())
            {
                return(TOP_LEVEL_ITEMS.Select(
                           item => new ChorusItem(chorusUrl.AddPathPart(item.Name), item.Label, DataSourceUtil.FOLDER_TYPE, null, 0)));
            }
            Uri            requestUri = GetContentsUri(chorusAccount, chorusUrl);
            ChorusContents contents;
            var            key = new RequestKey(chorusAccount, requestUri);

            lock (_lock)
            {
                ChorusContentsResponse chorusContentsResponse;
                if (!_chorusContentsByServerUrl.TryGetValue(key, out chorusContentsResponse))
                {
                    return(new ChorusItem[0]);
                }
                contents = chorusContentsResponse.Data;
            }
            return(ListItems(chorusUrl, contents));
        }
Esempio n. 19
0
        private void populateListViewFromDirectory(MsDataFileUri directory)
        {
            _abortPopulateList = false;
            listView.Cursor    = Cursors.Default;
            _waitingForData    = false;
            listView.Items.Clear();

            var listSourceInfo = new List <SourceInfo>();

            if (null == directory || directory is MsDataFilePath && string.IsNullOrEmpty(((MsDataFilePath)directory).FilePath))
            {
                foreach (DriveInfo driveInfo in DriveInfo.GetDrives())
                {
                    string     label      = string.Empty;
                    string     sublabel   = driveInfo.Name;
                    ImageIndex imageIndex = ImageIndex.Folder;
                    _driveReadiness[sublabel] = false;
                    try
                    {
                        switch (driveInfo.DriveType)
                        {
                        case DriveType.Fixed:
                            imageIndex = ImageIndex.LocalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Local_Drive;
                            if (driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.CDRom:
                            imageIndex = ImageIndex.OpticalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Optical_Drive;
                            if (driveInfo.IsReady && driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.Removable:
                            imageIndex = ImageIndex.OpticalDrive;
                            label      = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Removable_Drive;
                            if (driveInfo.IsReady && driveInfo.VolumeLabel.Length > 0)
                            {
                                label = driveInfo.VolumeLabel;
                            }
                            break;

                        case DriveType.Network:
                            label = Resources.OpenDataSourceDialog_populateListViewFromDirectory_Network_Share;
                            break;
                        }
                        _driveReadiness[sublabel] = IsDriveReady(driveInfo);
                    }
                    catch (Exception)
                    {
                        label += string.Format(" ({0})", Resources.OpenDataSourceDialog_populateListViewFromDirectory_access_failure); // Not L10N
                    }

                    string name = driveInfo.Name;
                    if (label != string.Empty)
                    {
                        name = string.Format("{0} ({1})", label, name); // Not L10N
                    }
                    listSourceInfo.Add(new SourceInfo(new MsDataFilePath(driveInfo.RootDirectory.FullName))
                    {
                        type         = DataSourceUtil.FOLDER_TYPE,
                        imageIndex   = imageIndex,
                        name         = name,
                        dateModified = GetDriveModifiedTime(driveInfo)
                    });
                }
            }
            else if (directory is ChorusUrl)
            {
                ChorusUrl chorusUrl = directory as ChorusUrl;
                if (null == _chorusSession)
                {
                    _chorusSession = new ChorusSession();
                    _chorusSession.ContentsAvailable += ChorusContentsAvailable;
                }
                if (string.IsNullOrEmpty(chorusUrl.ServerUrl))
                {
                    foreach (var chorusAccount in _chorusAccounts)
                    {
                        listSourceInfo.Add(new SourceInfo(chorusAccount.GetChorusUrl())
                        {
                            name       = chorusAccount.GetKey(),
                            type       = DataSourceUtil.FOLDER_TYPE,
                            imageIndex = ImageIndex.Chorus,
                        });
                    }
                }
                else
                {
                    ChorusAccount         chorusAccount = GetChorusAccount(chorusUrl);
                    ChorusServerException exception;
                    bool isComplete = _chorusSession.AsyncFetchContents(chorusAccount, chorusUrl, out exception);
                    foreach (var item in _chorusSession.ListContents(chorusAccount, chorusUrl))
                    {
                        var imageIndex = DataSourceUtil.IsFolderType(item.Type)
                            ? ImageIndex.Folder
                            : ImageIndex.MassSpecFile;
                        listSourceInfo.Add(new SourceInfo(item.ChorusUrl)
                        {
                            name         = item.Label,
                            type         = item.Type,
                            imageIndex   = imageIndex,
                            dateModified = item.LastModified,
                            size         = item.FileSize
                        });
                    }
                    if (null != exception)
                    {
                        if (MultiButtonMsgDlg.Show(this, exception.Message, Resources.OpenDataSourceDialog_populateListViewFromDirectory_Retry) != DialogResult.Cancel)
                        {
                            _chorusSession.RetryFetchContents(chorusAccount, chorusUrl);
                            isComplete = false;
                        }
                    }
                    if (!isComplete)
                    {
                        listView.Cursor = Cursors.WaitCursor;
                        _waitingForData = true;
                    }
                }
            }
            else if (directory is MsDataFilePath)
            {
                MsDataFilePath msDataFilePath = (MsDataFilePath)directory;
                DirectoryInfo  dirInfo        = new DirectoryInfo(msDataFilePath.FilePath);

                DirectoryInfo[] arraySubDirInfo;
                FileInfo[]      arrayFileInfo;
                try
                {
                    // subitems: Name, Type, Spectra, Size, Date Modified
                    arraySubDirInfo = dirInfo.GetDirectories();
                    Array.Sort(arraySubDirInfo, (d1, d2) => string.Compare(d1.Name, d2.Name, StringComparison.CurrentCultureIgnoreCase));
                    arrayFileInfo = dirInfo.GetFiles();
                    Array.Sort(arrayFileInfo, (f1, f2) => string.Compare(f1.Name, f2.Name, StringComparison.CurrentCultureIgnoreCase));
                }
                catch (Exception x)
                {
                    var message = TextUtil.LineSeparate(
                        Resources.OpenDataSourceDialog_populateListViewFromDirectory_An_error_occurred_attempting_to_retrieve_the_contents_of_this_directory,
                        x.Message);
                    // Might throw access violation.
                    MessageBox.Show(this, message, Program.Name);
                    return;
                }

                // Calculate information about the files, allowing the user to cancel
                foreach (var info in arraySubDirInfo)
                {
                    listSourceInfo.Add(getSourceInfo(info));
                    Application.DoEvents();
                    if (_abortPopulateList)
                    {
                        //MessageBox.Show( "abort" );
                        break;
                    }
                }

                if (!_abortPopulateList)
                {
                    foreach (var info in arrayFileInfo)
                    {
                        listSourceInfo.Add(getSourceInfo(info));
                        Application.DoEvents();
                        if (_abortPopulateList)
                        {
                            //MessageBox.Show( "abort" );
                            break;
                        }
                    }
                }
            }

            // Populate the list
            var items = new List <ListViewItem>();

            foreach (var sourceInfo in listSourceInfo)
            {
                if (sourceInfo != null &&
                    (sourceTypeComboBox.SelectedIndex == 0 ||
                     sourceTypeComboBox.SelectedItem.ToString() == sourceInfo.type ||
                     // Always show folders
                     sourceInfo.isFolder))
                {
                    ListViewItem item = new ListViewItem(sourceInfo.ToArray(), (int)sourceInfo.imageIndex)
                    {
                        Tag = sourceInfo,
                    };
                    item.SubItems[2].Tag = sourceInfo.size;
                    item.SubItems[3].Tag = sourceInfo.dateModified;

                    items.Add(item);
                }
            }
            listView.Items.AddRange(items.ToArray());
        }
Esempio n. 20
0
 public ChromTaskList(Action checkCancelledAction, SrmDocument srmDocument, ChorusAccount chorusAccount, ChorusUrl chorusUrl, IEnumerable <ChromatogramRequestDocument> chromatogramRequestDocuments)
 {
     SrmDocument                 = srmDocument;
     ChorusSession               = new ChorusSession();
     _checkCancelledAction       = checkCancelledAction;
     _chromatogramGeneratorTasks = new List <ChromatogramGeneratorTask>();
     _chromKeys = new Dictionary <ChromKey, ChromatogramGeneratorTask>();
     foreach (var chunk in chromatogramRequestDocuments)
     {
         ChromatogramGeneratorTask task = new ChromatogramGeneratorTask(this, chorusAccount, chorusUrl, chunk);
         _chromatogramGeneratorTasks.Add(task);
         foreach (ChromKey chromKey in ListChromKeys(chunk))
         {
             _chromKeys[chromKey] = task;
         }
     }
     _executingTasks = new HashSet <ChromatogramGeneratorTask>();
 }