Пример #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 resultUri = _blastClient.GetJobResult(new Guid(requestIdentifier));

            WebAccessor         accessor            = new WebAccessor();
            WebAccessorResponse webAccessorResponse = null;

            if (Configuration.UseBrowserProxy)
            {
                accessor.GetBrowserProxy();
            }

            webAccessorResponse = accessor.SubmitHttpRequest(
                new Uri(resultUri),
                false,          // POST request
                new Dictionary <string, string>());
            if (!webAccessorResponse.IsSuccessful)
            {
                // failure
                accessor.Close();
                return(null);
            }

            accessor.Close();
            return(webAccessorResponse.ResponseString);
        }
Пример #2
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 resultUri = _blastClient.GetJobResult(new Guid(requestIdentifier));

            Stream      responseStream    = null;
            string      statusDescription = string.Empty;
            WebAccessor accessor          = new WebAccessor();

            if (Configuration.UseBrowserProxy)
            {
                accessor.GetBrowserProxy();
            }

            if (!accessor.SubmitHttpRequest(
                    resultUri,
                    false, // POST request
                    new Dictionary <string, string>(),
                    out statusDescription,
                    out responseStream))
            {
                // failure
                accessor.Close();
                return(null);
            }

            string response = string.Empty;

            using (StreamReader r = new StreamReader(responseStream))
            {
                response = r.ReadToEnd();
                r.Close();
            }

            accessor.Close();
            return(response);
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        /// <summary>
        /// Return the status of a submitted job.
        /// </summary>
        /// <param name="requestIdentifier">Identifier for the request of interest.</param>
        /// <returns>The status of the request.</returns>
        public ServiceRequestInformation GetRequestStatus(string requestIdentifier)
        {
            string                      information         = string.Empty;
            string                      errorInformation    = string.Empty;
            WebAccessor                 accessor            = new WebAccessor();
            WebAccessorResponse         webAccessorResponse = null;
            ServiceRequestInformation   status   = new ServiceRequestInformation();
            Dictionary <string, string> settings = new Dictionary <string, string>();

            settings.Add(PARAMETERCMD, "GET");
            settings.Add(PARAMETERRID, System.Web.HttpUtility.UrlEncode(requestIdentifier));

            if (Configuration.UseBrowserProxy)
            {
                accessor.GetBrowserProxy();
            }

            webAccessorResponse = accessor.SubmitHttpRequest(
                ServiceUri,
                true,
                settings);
            if (!webAccessorResponse.IsSuccessful)
            {
                // failure
                accessor.Close();
                status.Status            = ServiceRequestStatus.Error;
                status.StatusInformation = webAccessorResponse.StatusDescription;
                return(status);
            }

            webAccessorResponse.StatusDescription = string.Empty;
            information = ExtractInfoSection(webAccessorResponse.ResponseString);
            if (String.IsNullOrEmpty(information))
            {
                status.Status = ServiceRequestStatus.Error;
                // see if we got an error message
                errorInformation = ExtractBlastErrorSection(webAccessorResponse.ResponseString);
                if (string.IsNullOrEmpty(errorInformation))
                {
                    status.StatusInformation = "An unknown server error has occurred.";
                }
                else
                {
                    status.StatusInformation = errorInformation;
                }

                return(status);
            }
            else
            {
                int statusStart = information.IndexOf("Status=", StringComparison.OrdinalIgnoreCase);
                if (statusStart >= 0)
                {
                    statusStart += "Status=".Length;
                    int statusEnd = information.IndexOf('\n', statusStart);
                    if (statusEnd >= 0)
                    {
                        webAccessorResponse.StatusDescription = information.Substring(statusStart, statusEnd - statusStart);
                    }
                }
            }

            if (webAccessorResponse.StatusDescription == STATUSWAITING)
            {
                status.Status = ServiceRequestStatus.Waiting;
                return(status);
            }
            else if (webAccessorResponse.StatusDescription == STATUSREADY)
            {
                status.Status = ServiceRequestStatus.Ready;
                return(status);
            }

            status.Status            = ServiceRequestStatus.Error;
            status.StatusInformation = webAccessorResponse.StatusDescription;

            return(status);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        /// <summary>
        /// Validate general SubmitHttpRequest() method by passing 
        /// differnt XML node name
        /// <param name="nodeName">xml node name.</param>
        /// </summary>
        void ValidateSubmitHttpRequestMethod(string nodeName)
        {
            // Gets the search query parameter and their values.
            string querySequence = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequency);
            string queryDatabaseValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseValue);
            string queryProgramValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramValue);
            string queryDatabaseParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseParameter);
            string queryProgramParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramParameter);
            string queryParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequencyparameter);
            string webUri = utilityObj.xmlUtil.GetTextValue(
                Constants.BlastRequestParametersNode, Constants.BlastWebServiceUri);
            WebAccessorResponse requestResult = null;

            // Set Service confiruration parameters true.
            IBlastServiceHandler blastService = null;
            try
            {
                blastService = new NCBIBlastHandler();
                ConfigParameters configParameters = new ConfigParameters();
                configParameters.UseBrowserProxy = true;
                blastService.Configuration = configParameters;

                // Create search parameters object.
                BlastParameters queryParams = new BlastParameters();

                // Add mandatory parameter values to search query parameters.
                queryParams.Add(queryParameter, querySequence);
                queryParams.Add(queryDatabaseParameter, queryDatabaseValue);
                queryParams.Add(queryProgramParameter, queryProgramValue);

                //Submit Http request
                WebAccessor webAccessor = new WebAccessor();
                webAccessor.GetBrowserProxy();
                requestResult = webAccessor.SubmitHttpRequest(new Uri(webUri), true,
                    queryParams.Settings);

                // Validate the Submitted request.
                Assert.IsTrue(requestResult.IsSuccessful);
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Http Request was submitted successfully"));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Blast P1: DataBase Value {0} is as expected.",
                    queryDatabaseValue));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Blast P1: Program Value {0} is as expected.",
                    queryProgramValue));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Blast P1: Query sequence {0} is as expected.",
                    querySequence));
                webAccessor.Close();
            }
            finally
            {
                if (blastService != null)
                    ((IDisposable)blastService).Dispose();
            }

        }
Пример #7
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)
        {
            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);
        }
Пример #8
0
        /// <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);
        }