Ejemplo n.º 1
0
        /// <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)
        {
            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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Submit the search request with the user supplied configuration parameters
        /// and sequence. Implementation should make use of the MBF.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;

            FastaFormatter formatter = new FastaFormatter();

            mydata[0].content = formatter.FormatString(sequence);

            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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Submit the search request with the user supplied configuration parameters
        /// and sequence. Implementation should make use of the MBF.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);

            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)
            {
                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);
        }