/// <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"); } 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( sequence, parameters); blastRequest.appxml = APPXMLYES; blastRequest.async = true; data[] mydata = new data[1]; mydata[0] = new data(); mydata[0].type = SEQUENCETYPE; mydata[0].content = sequence.ToString(); requestIdentifier = _blastClient.runWUBlast(blastRequest, mydata); // 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> /// 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"); } string requestIdentifier; // Validate the Parameter ParameterValidationResult valid = ValidateParameters(parameters); if (!valid.IsValid) { throw new Exception(valid.ValidationErrors); } // Submit the job to server BlastSerivceRequest blastRequest = GetRequestParameter( sequence, parameters); try { requestIdentifier = _blastClient.SubmitJob(blastRequest).ToString(); } catch (FaultException <BlastFault> fault) { throw new Exception(fault.Detail.Detail); } // 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> /// Process the request. This method takes care of executing the rest of the steps /// to complete the blast search request in a background thread. Which involves /// 1. Submit the job to server /// 2. Ping the service with the request identifier to get the status of request. /// 3. Repeat step 1, at "RetryInterval" for "RetryCount" till a "success"/"failure" /// status. /// 4. If the status is a "failure" raise an completed event to notify the user /// with appropriate details. /// 5. If the status "success". Get the output of search from server in xml format. /// 6. Parse the xml and the framework object model. /// 7. Raise the completed event and notify user with the output. /// </summary> /// <param name="sender">Client request EBIWU Blast search</param> /// <param name="argument">Thread event argument</param> private void ProcessRequestThread(object sender, DoWorkEventArgs argument) { ThreadParameter threadParameter = (ThreadParameter)argument.Argument; string requestIdentifier = threadParameter.RequestIdentifier; try { ServiceRequestInformation requestInfo = new ServiceRequestInformation(); requestInfo.Status = ServiceRequestStatus.Queued; int retryCount = 0; do { requestInfo = GetRequestStatus(requestIdentifier); if (requestInfo.Status == ServiceRequestStatus.Ready || requestInfo.Status == ServiceRequestStatus.Error || _workerThread.CancellationPending) { break; } retryCount++; Thread.Sleep(RetryInterval * retryCount); }while (retryCount < RetryCount); if (_workerThread.CancellationPending) { argument.Cancel = true; } else { RequestCompletedEventArgs eventArgument = null; string message; if (requestInfo.Status == ServiceRequestStatus.Ready) { string output = GetResult( requestIdentifier, threadParameter.Parameters); IList <BlastResult> result = Parser.Parse(new StringReader(output)); eventArgument = new RequestCompletedEventArgs( requestIdentifier, true, result, null, string.Empty, _workerThread.CancellationPending); argument.Result = eventArgument; } else if (requestInfo.Status == ServiceRequestStatus.Error) { message = String.Format( Resource.BLASTREQUESTFAILED, requestIdentifier, requestInfo.Status, requestInfo.StatusInformation); eventArgument = new RequestCompletedEventArgs( requestIdentifier, false, null, new Exception(message), message, _workerThread.CancellationPending); argument.Result = eventArgument; } else { message = String.Format( Resource.BLASTRETRIESEXCEEDED, requestIdentifier, requestInfo.Status, requestInfo.StatusInformation); eventArgument = new RequestCompletedEventArgs( requestIdentifier, false, null, new TimeoutException(message), message, _workerThread.CancellationPending); argument.Result = eventArgument; } } } catch (Exception ex) { RequestCompletedEventArgs eventArgument = new RequestCompletedEventArgs( string.Empty, false, null, ex, ex.Message, _workerThread.CancellationPending); argument.Result = eventArgument; } }
/// <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); }