public void TestChorusContents() { ChorusSession chorusSession = new ChorusSession(); ChorusContents chorusContents = chorusSession.FetchContents(TEST_ACCOUNT, new Uri(TEST_ACCOUNT.ServerUrl + "/skyline/api/contents/my/projects")); Assert.IsNotNull(chorusContents); }
private bool TestChorusAccount(ChorusAccount chorusAccount) { using (ChorusSession chorusSession = new ChorusSession(chorusAccount)) { try { CookieContainer cookieContainer = new CookieContainer(); try { chorusSession.Login(chorusAccount, cookieContainer); MessageDlg.Show(this, Resources.EditChorusAccountDlg_TestSettings_Settings_are_correct); return(true); } catch (RemoteServerException chorusException) { MessageDlg.ShowException(this, chorusException); textPassword.Focus(); return(false); } } catch (Exception x) { MessageDlg.ShowWithException(this, Resources.EditChorusAccountDlg_TestSettings_Error_connecting_to_server__ + x.Message, x); textServerURL.Focus(); return(false); } } }
public bool TestSettings() { if (!ValidateValues()) { return(false); } ChorusAccount chorusAccount = GetChorusAccount(); ChorusSession chorusSession = new ChorusSession(); try { CookieContainer cookieContainer = new CookieContainer(); try { chorusSession.Login(chorusAccount, cookieContainer); MessageDlg.Show(this, Resources.EditChorusAccountDlg_TestSettings_Settings_are_correct); return(true); } catch (ChorusServerException chorusException) { MessageDlg.ShowException(this, chorusException); textPassword.Focus(); return(false); } } catch (Exception x) { MessageDlg.ShowWithException(this, Resources.EditChorusAccountDlg_TestSettings_Error_connecting_to_server__ + x.Message, x); textServerURL.Focus(); return(false); } }
public void TestChorusInstrumentModels() { var accounts = new[] { new ChorusAccount("https://chorusproject.org", "*****@*****.**", "pwd"), }; ChorusSession chorusSession = new ChorusSession(); var instrumentModels = new HashSet <string>(); foreach (var account in accounts) { ChorusContents chorusContents = chorusSession.FetchContents(account, new Uri(account.ServerUrl + "/skyline/api/contents/my/files")); Assert.IsNotNull(chorusContents); foreach (var file in ListAllFiles(chorusContents)) { instrumentModels.Add(file.instrumentModel); } } Assert.AreNotEqual(0, instrumentModels.Count); var unknownInstrumentModels = new List <string>(); foreach (var instrumentModel in instrumentModels) { if (null == ChorusSession.GetFileTypeFromInstrumentModel(instrumentModel)) { unknownInstrumentModels.Add(instrumentModel); } } Assert.AreEqual(0, unknownInstrumentModels.Count, "Unknown instrument models {0}", string.Join(",", unknownInstrumentModels)); }
/// <summary> /// Tests that all instrument models are identified as something by ChorusSession.GetFileTypeFromInstrumentModel /// </summary> // Disabled 20170123 because Skyline Chorus API is offline //[TestMethod] public void TestChorusInstrumentModels() { var accounts = new[] { new ChorusAccount("https://chorusproject.org", "*****@*****.**", "pwd"), }; ChorusSession chorusSession = new ChorusSession(TEST_ACCOUNT); var instrumentModels = new HashSet <string>(); foreach (var account in accounts) { ChorusContents chorusContents; for (int retry = 4;; retry--) { try { chorusContents = chorusSession.FetchContents( new Uri(account.ServerUrl + "/skyline/api/contents/my/files")); break; } catch (WebException webException) { if (retry == 0 || webException.Status != WebExceptionStatus.Timeout) { throw; } } } Assert.IsNotNull(chorusContents); foreach (var file in ListAllFiles(chorusContents)) { instrumentModels.Add(file.instrumentModel); } } Assert.AreNotEqual(0, instrumentModels.Count); var unknownInstrumentModels = new List <string>(); foreach (var instrumentModel in instrumentModels) { if (null == ChorusSession.GetFileTypeFromInstrumentModel(instrumentModel)) { unknownInstrumentModels.Add(instrumentModel); } } if (0 != unknownInstrumentModels.Count) { String message = string.Format("Unknown instrument models {0}", string.Join(",", unknownInstrumentModels)); try { TestContext.WriteLine(message); } catch (Exception) { Console.Error.WriteLine(message); } } }
//[TestMethod] public void TestAuthenticate() { CookieContainer cookieContainer = new CookieContainer(); ChorusSession chorusSession = new ChorusSession(); Assert.AreEqual(0, cookieContainer.Count); chorusSession.Login(TEST_ACCOUNT, cookieContainer); Assert.AreEqual(1, cookieContainer.Count); }
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(); }
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>(); }
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()); }
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); } } 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()); }
public bool TestSettings() { if (!ValidateValues()) { return false; } ChorusAccount chorusAccount = GetChorusAccount(); ChorusSession chorusSession = new ChorusSession(); try { CookieContainer cookieContainer = new CookieContainer(); try { chorusSession.Login(chorusAccount, cookieContainer); MessageDlg.Show(this, Resources.EditChorusAccountDlg_TestSettings_Settings_are_correct); return true; } catch (ChorusServerException chorusException) { MessageDlg.ShowException(this, chorusException); textPassword.Focus(); return false; } } catch (Exception x) { MessageDlg.ShowWithException(this, Resources.EditChorusAccountDlg_TestSettings_Error_connecting_to_server__ + x.Message, x); textServerURL.Focus(); return false; } }