/// <summary> /// Gets the search results for the pertinent request identifier. /// Implementation should have dedicated parsers to format the received results into Bio /// </summary> /// <remarks>An exception is thrown if the request does not succeed.</remarks> /// <param name="requestIdentifier">Identifier for the request of interest.</param> /// <param name="parameters">Blast input parameters</param> /// <returns>The search results</returns> public string GetResult( string requestIdentifier, BlastParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } string status = string.Empty; string information = string.Empty; WebAccessor accessor = new WebAccessor(); WebAccessorResponse webAccessorResponse = null; parameters.Add(PARAMETERCOMMAND, COMMANDGET); parameters.Add(PARAMETERJOBID, requestIdentifier); parameters.Add(PARAMETERFORMAT, FORMATXML); if (Configuration.UseBrowserProxy) { accessor.GetBrowserProxy(); } webAccessorResponse = accessor.SubmitHttpRequest( ServiceUri, true, // POST request parameters.Settings); if (!webAccessorResponse.IsSuccessful) { // failure accessor.Close(); return(null); } accessor.Close(); information = ExtractInfoSection(webAccessorResponse.ResponseString); if (!String.IsNullOrEmpty(information)) { int statusStart = information.IndexOf("Status=", StringComparison.OrdinalIgnoreCase); if (statusStart >= 0) { statusStart += "Status=".Length; int statusEnd = information.IndexOf('\n', statusStart); if (statusEnd >= 0) { status = information.Substring(statusStart, statusEnd - statusStart); } } } if (!string.IsNullOrEmpty(status)) { if (status == STATUSWAITING) { return(null); } else { string message = String.Format(CultureInfo.InvariantCulture, Resources.INVALIDNCBISTATUS, status); throw new Exception(message); } } return(webAccessorResponse.ResponseString); }
/// <summary> /// Submit the search request with the user supplied configuration parameters and sequence /// Implementation should make use of the Bio.IO formatters to convert the sequence into /// the web interface compliant sequence format /// </summary> /// <remarks>An exception is thrown if the request does not succeed.</remarks> /// <param name="sequences">List of sequence to search with</param> /// <param name="parameters">Blast input parameters</param> /// <returns>Request Identifier</returns> public string SubmitRequest(IList <ISequence> sequences, BlastParameters parameters) { if (null == parameters) { throw new ArgumentNullException("parameters"); } if (null != sequences) { StringBuilder sb = new StringBuilder(); foreach (ISequence seq in sequences) { sb.Append(FastAFormatter.FormatString(seq)); sb.Append("\n"); } parameters.Add("Query", sb.ToString()); } if (!string.IsNullOrEmpty(Configuration.EmailAddress)) { if (!parameters.Settings.ContainsKey(PARAMETEREMAIL)) { parameters.Add(PARAMETEREMAIL, Configuration.EmailAddress); } } string requestIdentifier = string.Empty; // Validate the Parameter ParameterValidationResult valid = ValidateParameters(parameters); if (!valid.IsValid) { throw new Exception(valid.ValidationErrors); } parameters.Add(PARAMETERCOMMAND, COMMANDPUT); WebAccessor accessor = new WebAccessor(); WebAccessorResponse webAccessorResponse; if (Configuration.UseBrowserProxy) { accessor.GetBrowserProxy(); } webAccessorResponse = accessor.SubmitHttpRequest( ServiceUri, true, // do POST parameters.Settings); // request parameters if (!webAccessorResponse.IsSuccessful) { // failed accessor.Close(); throw new Exception(String.Format(CultureInfo.InvariantCulture, Resources.HTTPSUBMITFAILED, webAccessorResponse.StatusDescription)); } string info = ExtractInfoSection(webAccessorResponse.ResponseString); if (!String.IsNullOrEmpty(info)) { int ridStart = info.IndexOf("RID = ", StringComparison.OrdinalIgnoreCase); if (ridStart >= 0) { ridStart += "RID = ".Length; int ridEnd = info.IndexOf('\n', ridStart); if (ridEnd >= 0) { requestIdentifier = info.Substring(ridStart, ridEnd - ridStart); } } } accessor.Close(); if (string.IsNullOrEmpty(requestIdentifier)) { string message = String.Format(CultureInfo.InvariantCulture, Resources.RIDEXTRACTFAILED, ExtractError(webAccessorResponse.ResponseString)); throw new Exception(message); } // Only if the event is registered, invoke the thread if (null != RequestCompleted) { BlastThreadParameter threadParameter = new BlastThreadParameter( requestIdentifier, null, // Sequence parameter is not used any where, hence passing null. parameters); // Start the BackGroundThread to check the status of job workerThread = new BackgroundWorker(); workerThread.WorkerSupportsCancellation = true; workerThread.DoWork += new DoWorkEventHandler(ProcessRequestThread); workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedRequestThread); workerThread.RunWorkerAsync(threadParameter); } return(requestIdentifier); }
/// <summary> /// Submit the search request with the user supplied configuration parameters /// and sequence. Implementation should make use of the Bio.IO formatters /// to convert the sequence into the web interface compliant sequence format. /// This method performs parameter validation and throw Exception on invalid input. /// </summary> /// <remarks>An exception is thrown if the request does not succeed.</remarks> /// <param name="sequence">The sequence to search with</param> /// <param name="parameters">Blast input parameters</param> /// <returns>Request Identifier</returns> public string SubmitRequest(ISequence sequence, BlastParameters parameters) { if (null != sequence) { parameters.Add("Query", sequence.ToString()); } if (null == parameters) { throw new ArgumentNullException("parameters"); } string requestIdentifier = string.Empty; // Validate the Parameter ParameterValidationResult valid = ValidateParameters(parameters); if (!valid.IsValid) { throw new Exception(valid.ValidationErrors); } parameters.Add(PARAMETERCOMMAND, COMMANDPUT); Stream responseStream = null; string statusDescription = string.Empty; WebAccessor accessor = new WebAccessor(); if (Configuration.UseBrowserProxy) { accessor.GetBrowserProxy(); } if (!accessor.SubmitHttpRequest( ServiceUri, true, // do POST parameters.Settings, // request parameters out statusDescription, out responseStream)) { // failed accessor.Close(); throw new Exception(String.Format( Resource.HTTPSUBMITFAILED, statusDescription)); } string response = string.Empty; using (StreamReader r = new StreamReader(responseStream)) { response = r.ReadToEnd(); string info = ExtractInfoSection(response); if (!String.IsNullOrEmpty(info)) { int ridStart = info.IndexOf("RID = "); if (ridStart >= 0) { ridStart += "RID = ".Length; int ridEnd = info.IndexOf('\n', ridStart); if (ridEnd >= 0) { requestIdentifier = info.Substring(ridStart, ridEnd - ridStart); } } } r.Close(); } accessor.Close(); if (string.IsNullOrEmpty(requestIdentifier)) { string message = String.Format( Resource.RIDEXTRACTFAILED, ExtractError(response)); throw new Exception(message); } // Only if the event is registered, invoke the thread if (null != RequestCompleted) { ThreadParameter threadParameter = new ThreadParameter( requestIdentifier, sequence, parameters); // Start the BackGroundThread to check the status of job _workerThread = new BackgroundWorker(); _workerThread.WorkerSupportsCancellation = true; _workerThread.DoWork += new DoWorkEventHandler(ProcessRequestThread); _workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedRequestThread); _workerThread.RunWorkerAsync(threadParameter); } return(requestIdentifier); }
/// <summary> /// Gets the search results for the pertinent request identifier. /// Implementation should have dedicated parsers to format the received results into MBF /// </summary> /// <remarks>An exception is thrown if the request does not succeed.</remarks> /// <param name="requestIdentifier">Identifier for the request of interest.</param> /// <param name="parameters">Blast input parameters</param> /// <returns>The search results</returns> public string GetResult( string requestIdentifier, BlastParameters parameters) { Stream responseStream = null; string status = string.Empty; string response = string.Empty; string information = string.Empty; string statusDescription = string.Empty; WebAccessor accessor = new WebAccessor(); parameters.Add(PARAMETERCOMMAND, COMMANDGET); parameters.Add(PARAMETERJOBID, requestIdentifier); parameters.Add(PARAMETERFORMAT, FORMATXML); if (Configuration.UseBrowserProxy) { accessor.GetBrowserProxy(); } if (!accessor.SubmitHttpRequest( ServiceUri, true, // POST request parameters.Settings, out statusDescription, out responseStream)) { // failure accessor.Close(); return(null); } using (StreamReader r = new StreamReader(responseStream)) { response = r.ReadToEnd(); r.Close(); } accessor.Close(); information = ExtractInfoSection(response); if (!String.IsNullOrEmpty(information)) { int statusStart = information.IndexOf("Status="); if (statusStart >= 0) { statusStart += "Status=".Length; int statusEnd = information.IndexOf('\n', statusStart); if (statusEnd >= 0) { status = information.Substring(statusStart, statusEnd - statusStart); } } } if (status != string.Empty) { if (status == STATUSWAITING) { return(null); } else { string message = String.Format( Resource.INVALIDNCBISTATUS, status); throw new Exception(message); } } return(response); }
/// <summary> /// Submit the search request with the user supplied configuration parameters /// and sequence. Implementation should make use of the Bio.IO formatters /// to convert the sequence into the web interface compliant sequence format. /// This method performs parameter validation and throw Exception on invalid input. /// </summary> /// <remarks>An exception is thrown if the request does not succeed.</remarks> /// <param name="sequence">The sequence to search with</param> /// <param name="parameters">Blast input parameters</param> /// <returns>Request Identifier</returns> public string SubmitRequest(ISequence sequence, BlastParameters parameters) { if (null == sequence) { throw new ArgumentNullException("sequence"); } if (null == parameters) { throw new ArgumentNullException("parameters"); } if (!string.IsNullOrEmpty(Configuration.EmailAddress)) { if (!parameters.Settings.ContainsKey(ParameterEmail)) { parameters.Add(ParameterEmail, Configuration.EmailAddress); } } string requestIdentifier = string.Empty; // Validate the Parameter ParameterValidationResult valid = ValidateParameters(parameters); if (!valid.IsValid) { throw new Exception(valid.ValidationErrors); } // Submit the job to server inputParams blastRequest = GetRequestParameter(parameters); blastRequest.appxml = AppXmlYes; blastRequest.async = true; data[] mydata = new data[1]; mydata[0] = new data(); mydata[0].type = SequenceType; mydata[0].content = FastAFormatter.FormatString(sequence); requestIdentifier = blastClient.runWUBlast(blastRequest, mydata); // Only if the event is registered, invoke the thread if (null != RequestCompleted) { BlastThreadParameter threadParameter = new BlastThreadParameter( requestIdentifier, sequence, parameters); // Start the BackGroundThread to check the status of job workerThread = new BackgroundWorker(); workerThread.WorkerSupportsCancellation = true; workerThread.DoWork += new DoWorkEventHandler(ProcessRequestThread); workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedRequestThread); workerThread.RunWorkerAsync(threadParameter); } return(requestIdentifier); }