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); }
public void Login(ChorusAccount chorusAccount, CookieContainer cookieContainer) { var webRequest = (HttpWebRequest)WebRequest.Create(new Uri(chorusAccount.ServerUrl + "/j_spring_security_check")); // Not L10N // ReSharper disable NonLocalizedString webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.Method = "POST"; webRequest.CookieContainer = cookieContainer; string postData = "j_username="******"&j_password="******"login.html")); // Not L10N if (!loginSuccessful) { throw new ChorusServerException(Resources.ChorusSession_Login_Unable_to_log_in___Username_or_password_is_incorrect_); } }
private void FetchAndStoreContents(ChorusAccount chorusAccount, Uri requestUri) { ChorusContents contents = new ChorusContents(); var key = new RequestKey(chorusAccount, requestUri); try { StoreContentsResponse(key, new ChorusContentsResponse(FetchContents(chorusAccount, requestUri), true)); } catch (Exception exception) { ChorusServerException chorusException = exception as ChorusServerException; // ReSharper disable once ConvertIfStatementToNullCoalescingExpression if (null == chorusException) { chorusException = new ChorusServerException( Resources.ChorusSession_FetchContents_There_was_an_error_communicating_with_the_server__ + exception.Message, exception); } StoreContentsResponse(key, new ChorusContentsResponse(contents, true) { ChorusException = chorusException, }); } finally { lock (_lock) { _fetchRequests.Remove(key); } } }
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); }
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; }
public void AddAuthHeader(ChorusAccount chorusAccount, HttpWebRequest webRequest) { if (null != chorusAccount) { // ReSharper disable NonLocalizedString byte[] authBytes = Encoding.UTF8.GetBytes(chorusAccount.Username + ':' + chorusAccount.Password); var authHeader = "Basic " + Convert.ToBase64String(authBytes); // ReSharper restore NonLocalizedString webRequest.Headers.Add(HttpRequestHeader.Authorization, authHeader); } }
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(); })); }
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)); })); }
public ChorusContents FetchContents(ChorusAccount chorusAccount, Uri uri) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri); // Not L10N AddAuthHeader(chorusAccount, webRequest); return(SendRequest(webRequest, webResponse => { string strResponse = string.Empty; var responseStream = webResponse.GetResponseStream(); if (responseStream != null) { var streamReader = new StreamReader(responseStream); strResponse = streamReader.ReadToEnd(); } var chorusContents = JsonConvert.DeserializeObject <ChorusContents>(strResponse); return chorusContents; })); }
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>(); }
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); } }
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)); }
public RequestKey(ChorusAccount chorusAccount, Uri requestUri) : this() { ChorusAccount = chorusAccount; RequestUri = requestUri; }
private ChorusAccount(ChorusAccount chorusAccount) { ServerUrl = chorusAccount.ServerUrl; Username = chorusAccount.Username; Password = chorusAccount.Password; }
private bool Equals(ChorusAccount other) { return(string.Equals(Username, other.Username) && string.Equals(Password, other.Password) && Equals(ServerUrl, other.ServerUrl)); }