/// <summary> /// CreateJob() to get job id and control id and Submit job /// using input sequence with job id and control id /// </summary> /// <param name="sequence">input sequences</param> /// <param name="parameters">input params</param> /// <returns>result params with job id and control id</returns> public ServiceParameters SubmitRequest(IList <ISequence> sequence, ClustalWParameters parameters) { ServiceParameters result = new ServiceParameters(); if (null == sequence) { throw new ArgumentNullException("Sequence"); } if (null == parameters) { throw new ArgumentNullException("Parameters"); } // ClusterOption = biosim cbsum1 cbsum2k8 cbsusrv05 cbsum2 or Auto string[] output = _baseClient.CreateJob(tAppId.P_CLUSTALW, "test_BioHPC_Job", "1", parameters.Values[ClustalWParameters.Email].ToString(), string.Empty, parameters.Values[ClustalWParameters.ClusterOption].ToString()); if (!output[0].Contains(ERROR)) { result.JobId = output[1]; result.Parameters.Add(CONTROLID, output[2]); AppInputData inputData = _baseClient.InitializeApplicationParams(tAppId.P_CLUSTALW, "test_BioHPC_Job"); StringBuilder inputSequence = new StringBuilder(); foreach (ISequence seq in sequence) { inputSequence.AppendLine(FastAFormatter.FormatString(seq)); } inputData.clustalw.inputsource = QuerySrcType.paste; inputData.clustalw.inputstring = inputSequence.ToString(); inputData.clustalw.isDNA = false; inputData.clustalw.action = (ClwActions)Enum.Parse(typeof(ClwActions), parameters.Values[ClustalWParameters.ActionAlign].ToString()); inputData.clustalw.email_notify = true; _baseClient.SubmitJob(result.JobId, result.Parameters[CONTROLID].ToString(), inputData); result.Parameters.Add(SUBMISSONRESULT, SUCCESS); // Only if the event is registered, invoke the thread if (null != RequestCompleted) { // 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(result); } } else { result.Parameters.Add(SUBMISSONRESULT, output[0]); } return(result); }
/// <summary> /// Validate Submit Job and Fetch ResultSync() using multiple input sequences /// </summary> /// <param name="nodeName">xml node name</param> void ValidateFetchResultSync(string nodeName) { // Read input from config file string filepath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string emailId = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.EmailIDNode); string clusterOption = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ClusterOptionNode); string actionAlign = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ActionAlignNode); // Initialize with parser and config params ConfigParameters configparams = new ConfigParameters(); ClustalWParser clustalparser = new ClustalWParser(); configparams.UseBrowserProxy = true; TestIClustalWServiceHandler handler = new TestIClustalWServiceHandler(clustalparser, configparams); ClustalWParameters parameters = new ClustalWParameters(); parameters.Values[ClustalWParameters.Email] = emailId; parameters.Values[ClustalWParameters.ClusterOption] = clusterOption; parameters.Values[ClustalWParameters.ActionAlign] = actionAlign; IEnumerable <ISequence> sequence = null; // Get the input sequences using (FastAParser parser = new FastAParser(filepath)) { sequence = parser.Parse(); // Submit job and validate it returned valid job id and control id ServiceParameters svcparameters = handler.SubmitRequest(sequence.ToList(), parameters); Assert.IsFalse(string.IsNullOrEmpty(svcparameters.JobId)); ApplicationLog.WriteLine(string.Concat("JobId", svcparameters.JobId)); foreach (string key in svcparameters.Parameters.Keys) { Assert.IsFalse(string.IsNullOrEmpty(svcparameters.Parameters[key].ToString())); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "{0}:{1}", key, svcparameters.Parameters[key].ToString())); } // Get the results and validate it is not null. ClustalWResult result = handler.FetchResultsSync(svcparameters); Assert.IsNotNull(result); Assert.IsNotNull(result.SequenceAlignment); foreach (IAlignedSequence alignSeq in result.SequenceAlignment.AlignedSequences) { ApplicationLog.WriteLine("Aligned Sequence Sequences :"); foreach (ISequence seq in alignSeq.Sequences) { ApplicationLog.WriteLine(string.Concat("Sequence:", seq.ToString())); } } } ApplicationLog.WriteLine(@"ClustalWServiceHandler BVT : Submit job and Get Results is successfully completed using FetchResultSync()"); }
/// <summary> /// Validate if the connection is successful /// </summary> /// <returns>True, if connection is successful</returns> static bool ValidateWebServiceConnection() { // Read input from config file string filepath = Utility._xmlUtil.GetTextValue( Constants.DefaultOptionNode, Constants.FilePathNode); string emailId = Utility._xmlUtil.GetTextValue( Constants.DefaultOptionNode, Constants.EmailIDNode); string clusterOption = Utility._xmlUtil.GetTextValue( Constants.DefaultOptionNode, Constants.ClusterOptionNode); string actionAlign = Utility._xmlUtil.GetTextValue( Constants.DefaultOptionNode, Constants.ActionAlignNode); // Initialize with parser and config params ConfigParameters configparams = new ConfigParameters(); ClustalWParser clustalparser = new ClustalWParser(); configparams.UseBrowserProxy = true; TestIClustalWServiceHandler handler = new TestIClustalWServiceHandler(clustalparser, configparams); ClustalWParameters parameters = new ClustalWParameters(); parameters.Values[ClustalWParameters.Email] = emailId; parameters.Values[ClustalWParameters.ClusterOption] = clusterOption; parameters.Values[ClustalWParameters.ActionAlign] = actionAlign; // Get the input sequences FastaParser parser = new FastaParser(); IList <ISequence> sequence = parser.Parse(filepath); try { // Submit job and validate it returned valid job id and control id ServiceParameters svcparameters = handler.SubmitRequest(sequence, parameters); if (string.IsNullOrEmpty(svcparameters.JobId)) { Console.WriteLine( "ClustalW BVT : Connection not successful with no Job ID"); ApplicationLog.WriteLine( "ClustalW BVT : Connection not successful with no Job ID"); return(false); } handler.FetchResultsSync(svcparameters); } catch (Exception ex) { Console.WriteLine(string.Format( "ClustalW BVT : Connection not successful with error '{0}'", ex.Message)); ApplicationLog.WriteLine(string.Format( "ClustalW BVT : Connection not successful with error '{0}'", ex.Message)); return(false); } Console.WriteLine("ClustalW BVT : Connection Successful"); return(true); }
/// <summary> /// Validate the CancelRequest() /// </summary> /// <param name="nodeName">xml node name</param> void ValidateCancelRequest(string nodeName) { // Read input from config file string filepath = _utilityObj._xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string emailId = _utilityObj._xmlUtil.GetTextValue(nodeName, Constants.EmailIDNode); string clusterOption = _utilityObj._xmlUtil.GetTextValue(nodeName, Constants.ClusterOptionNode); string actionAlign = _utilityObj._xmlUtil.GetTextValue(nodeName, Constants.ActionAlignNode); ClustalWParameters parameters = new ClustalWParameters(); parameters.Values[ClustalWParameters.Email] = emailId; parameters.Values[ClustalWParameters.ClusterOption] = clusterOption; parameters.Values[ClustalWParameters.ActionAlign] = actionAlign; IList <ISequence> sequence = null; // Get the input sequences using (FastaParser parser = new FastaParser()) { sequence = parser.Parse(filepath); } // Submit job and cancel job // Validate cancel job is working as expected ConfigParameters configparams = new ConfigParameters(); ClustalWParser clustalparser = new ClustalWParser(); configparams.UseBrowserProxy = true; TestIClustalWServiceHandler handler = new TestIClustalWServiceHandler(clustalparser, configparams); ServiceParameters svcparams = handler.SubmitRequest(sequence, parameters); bool result = handler.CancelRequest(svcparams); Assert.IsTrue(result); Console.WriteLine(string.Concat("JobId:", svcparams.JobId)); ApplicationLog.WriteLine(string.Concat("JobId:", svcparams.JobId)); Assert.IsTrue(string.IsNullOrEmpty(svcparams.JobId)); foreach (string key in svcparams.Parameters.Keys) { Assert.IsTrue(string.IsNullOrEmpty(svcparams.Parameters[key].ToString())); Console.WriteLine(string.Format((IFormatProvider)null, "{0} : {1}", key, svcparams.Parameters[key].ToString())); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "{0} : {1}", key, svcparams.Parameters[key].ToString())); } Console.WriteLine( "ClustalWServiceHandler BVT : Cancel job is submitted as expected"); ApplicationLog.WriteLine( "ClustalWServiceHandler BVT : Cancel job is submitted as expected"); }
/// <summary> /// Validate submit job and Get Results using event handler /// </summary> /// <param name="nodeName">xml node name</param> void ValidateFetchResultsUsingEvent(string nodeName) { // Read input from config file string filepath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string emailId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.EmailIDNode); string clusterOption = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ClusterOptionNode); string actionAlign = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ActionAlignNode); ClustalWParameters parameters = new ClustalWParameters(); parameters.Values[ClustalWParameters.Email] = emailId; parameters.Values[ClustalWParameters.ClusterOption] = clusterOption; parameters.Values[ClustalWParameters.ActionAlign] = actionAlign; IEnumerable <ISequence> sequence = null; // Get the input sequences using (FastAParser parser = new FastAParser(filepath)) { sequence = parser.Parse(); // Register event and submit request ConfigParameters configparams = new ConfigParameters(); ClustalWParser clustalparser = new ClustalWParser(); configparams.UseBrowserProxy = true; TestIClustalWServiceHandler handler = new TestIClustalWServiceHandler(clustalparser, configparams); handler.RequestCompleted += new EventHandler <ClustalWCompletedEventArgs>(handler_RequestCompleted); ServiceParameters svcparams = handler.SubmitRequest(sequence.ToList(), parameters); WaitHandle[] aryHandler = new WaitHandle[1]; aryHandler[0] = _resetEvent; WaitHandle.WaitAny(aryHandler); // Validate the submit job results Assert.IsFalse(string.IsNullOrEmpty(svcparams.JobId)); Console.WriteLine("JobId:" + svcparams.JobId); foreach (string key in svcparams.Parameters.Keys) { Assert.IsFalse(string.IsNullOrEmpty(svcparams.Parameters[key].ToString())); Console.WriteLine(string.Format((IFormatProvider)null, "{0} : {1}", key, svcparams.Parameters[key].ToString())); } aryHandler = null; _resetEvent.Close(); _resetEvent.Dispose(); } }
/// <summary> /// Validate submit job and FetchResultAsync() using multiple input sequences /// </summary> /// <param name="nodeName">xml node name</param> void ValidateFetchResultAsync(string nodeName) { // Read input from config file string filepath = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string emailId = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.EmailIDNode); string clusterOption = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.ClusterOptionNode); string actionAlign = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.ActionAlignNode); ConfigParameters configparams = new ConfigParameters(); ClustalWParser clustalparser = new ClustalWParser(); configparams.UseBrowserProxy = true; TestIClustalWServiceHandler handler = new TestIClustalWServiceHandler(clustalparser, configparams); ClustalWParameters parameters = new ClustalWParameters(); parameters.Values[ClustalWParameters.Email] = emailId; parameters.Values[ClustalWParameters.ClusterOption] = clusterOption; parameters.Values[ClustalWParameters.ActionAlign] = actionAlign; IList <ISequence> sequence = null; // Get input sequences using (FastaParser parser = new FastaParser()) { sequence = parser.Parse(filepath); } // Submit job and validate it returned valid job id and control id ServiceParameters svcparameters = handler.SubmitRequest(sequence, parameters); Assert.IsTrue(string.IsNullOrEmpty(svcparameters.JobId)); Console.WriteLine(string.Concat("JobId:", svcparameters.JobId)); foreach (string key in svcparameters.Parameters.Keys) { Assert.IsTrue(string.IsNullOrEmpty(svcparameters.Parameters[key].ToString())); Console.WriteLine(string.Format((IFormatProvider)null, "{0}:{1}", key, svcparameters.Parameters[key].ToString())); } // Get the results and validate it is not null. ClustalWResult result = null; int retrycount = 0; ServiceRequestInformation info; do { info = handler.GetRequestStatus(svcparameters); if (info.Status == ServiceRequestStatus.Ready) { break; } Thread.Sleep( info.Status == ServiceRequestStatus.Waiting || info.Status == ServiceRequestStatus.Queued ? Constants.ClusterRetryInterval * retrycount : 0); retrycount++; }while (retrycount < 10); if (info.Status == ServiceRequestStatus.Ready) { result = handler.FetchResultsAsync(svcparameters); } Assert.IsNotNull(result); Assert.IsNotNull(result.SequenceAlignment); foreach (IAlignedSequence alignSeq in result.SequenceAlignment.AlignedSequences) { Console.WriteLine("Aligned Sequence Sequences : "); ApplicationLog.WriteLine("Aligned Sequence Sequences : "); foreach (ISequence seq in alignSeq.Sequences) { Console.WriteLine(string.Concat("Sequence:", seq.ToString())); ApplicationLog.WriteLine(string.Concat("Sequence:", seq.ToString())); } } Console.WriteLine(@"ClustalWServiceHandler BVT : Submit job and Get Results is successfully completed using FetchResultAsync()"); ApplicationLog.WriteLine(@"ClustalWServiceHandler BVT : Submit job and Get Results is successfully completed using FetchResultAsync()"); }
void ValidateCancelRequest(string nodeName) { // Read input from config file string filepath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string emailId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.EmailIDNode); string clusterOption = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ClusterOptionNode); string actionAlign = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ActionAlignNode); ClustalWParameters parameters = new ClustalWParameters(); parameters.Values[ClustalWParameters.Email] = emailId; parameters.Values[ClustalWParameters.ClusterOption] = clusterOption; parameters.Values[ClustalWParameters.ActionAlign] = actionAlign; IEnumerable<ISequence> sequence = null; // Get the input sequences using (FastAParser parser = new FastAParser(filepath)) { sequence = parser.Parse(); // Submit job and cancel job // Validate cancel job is working as expected ConfigParameters configparams = new ConfigParameters(); ClustalWParser clustalparser = new ClustalWParser(); configparams.UseBrowserProxy = true; TestIClustalWServiceHandler handler = new TestIClustalWServiceHandler(clustalparser, configparams); ServiceParameters svcparams = handler.SubmitRequest(sequence.ToList(), parameters); bool result = handler.CancelRequest(svcparams); Assert.IsTrue(result); ApplicationLog.WriteLine(string.Concat("JobId:", svcparams.JobId)); Assert.IsFalse(string.IsNullOrEmpty(svcparams.JobId)); foreach (string key in svcparams.Parameters.Keys) { Assert.IsFalse(string.IsNullOrEmpty(svcparams.Parameters[key].ToString())); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "{0} : {1}", key, svcparams.Parameters[key].ToString())); } } ApplicationLog.WriteLine( "ClustalWServiceHandler BVT : Cancel job is submitted as expected"); }
/// <summary> /// Validate submit job and Get Results using event handler /// </summary> /// <param name="nodeName">xml node name</param> void ValidateFetchResultsUsingEvent(string nodeName) { // Read input from config file string filepath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string emailId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.EmailIDNode); string clusterOption = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ClusterOptionNode); string actionAlign = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ActionAlignNode); ClustalWParameters parameters = new ClustalWParameters(); parameters.Values[ClustalWParameters.Email] = emailId; parameters.Values[ClustalWParameters.ClusterOption] = clusterOption; parameters.Values[ClustalWParameters.ActionAlign] = actionAlign; IEnumerable<ISequence> sequence = null; // Get the input sequences using (FastAParser parser = new FastAParser(filepath)) { sequence = parser.Parse(); // Register event and submit request ConfigParameters configparams = new ConfigParameters(); ClustalWParser clustalparser = new ClustalWParser(); configparams.UseBrowserProxy = true; TestIClustalWServiceHandler handler = new TestIClustalWServiceHandler(clustalparser, configparams); handler.RequestCompleted += new EventHandler<ClustalWCompletedEventArgs>(handler_RequestCompleted); ServiceParameters svcparams = handler.SubmitRequest(sequence.ToList(), parameters); WaitHandle[] aryHandler = new WaitHandle[1]; aryHandler[0] = _resetEvent; WaitHandle.WaitAny(aryHandler); // Validate the submit job results Assert.IsFalse(string.IsNullOrEmpty(svcparams.JobId)); foreach (string key in svcparams.Parameters.Keys) { Assert.IsFalse(string.IsNullOrEmpty(svcparams.Parameters[key].ToString())); } _resetEvent.Close(); _resetEvent.Dispose(); } }
/// <summary> /// Validate submit job and FetchResultAsync() using multiple input sequences /// </summary> /// <param name="nodeName">xml node name</param> void ValidateFetchResultAsync(string nodeName) { // Read input from config file string filepath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); string emailId = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.EmailIDNode); string clusterOption = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ClusterOptionNode); string actionAlign = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ActionAlignNode); ConfigParameters configparams = new ConfigParameters(); ClustalWParser clustalparser = new ClustalWParser(); configparams.UseBrowserProxy = true; TestIClustalWServiceHandler handler = new TestIClustalWServiceHandler(clustalparser, configparams); ClustalWParameters parameters = new ClustalWParameters(); parameters.Values[ClustalWParameters.Email] = emailId; parameters.Values[ClustalWParameters.ClusterOption] = clusterOption; parameters.Values[ClustalWParameters.ActionAlign] = actionAlign; // Get input sequences using (FastAParser parser = new FastAParser(filepath)) { IEnumerable<ISequence> sequence = parser.Parse(); // Submit job and validate it returned valid job id and control id ServiceParameters svcparameters = handler.SubmitRequest(sequence.ToList(), parameters); Assert.IsFalse(string.IsNullOrEmpty(svcparameters.JobId)); foreach (string key in svcparameters.Parameters.Keys) { Assert.IsFalse(string.IsNullOrEmpty(svcparameters.Parameters[key].ToString())); } // Get the results and validate it is not null. int retrycount = 0; ServiceRequestInformation info; do { info = handler.GetRequestStatus(svcparameters); if (info.Status == ServiceRequestStatus.Ready) { break; } Thread.Sleep( info.Status == ServiceRequestStatus.Waiting || info.Status == ServiceRequestStatus.Queued ? Constants.ClusterRetryInterval * retrycount : 0); retrycount++; } while (retrycount < 10); ClustalWResult result = null; if (info.Status == ServiceRequestStatus.Ready) { result = handler.FetchResultsAsync(svcparameters); } Assert.IsNotNull(result, "Failed to retrieve results from submitted task, Server may be offline or slow."); Assert.IsNotNull(result.SequenceAlignment); foreach (IAlignedSequence alignSeq in result.SequenceAlignment.AlignedSequences) { ApplicationLog.WriteLine("Aligned Sequence Sequences : "); foreach (ISequence seq in alignSeq.Sequences) { ApplicationLog.WriteLine(string.Concat("Sequence:", seq.ToString())); } } } ApplicationLog.WriteLine(@"ClustalWServiceHandler BVT : Submit job and Get Results is successfully completed using FetchResultAsync()"); }
/// <summary> /// Validate Submit Job and Fetch ResultSync() using multiple input sequences /// </summary> /// <param name="nodeName">xml node name</param> void ValidateFetchResultSync(string nodeName) { // Read input from config file string filepath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string emailId = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.EmailIDNode); string clusterOption = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ClusterOptionNode); string actionAlign = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ActionAlignNode); // Initialize with parser and config params ConfigParameters configparams = new ConfigParameters(); ClustalWParser clustalparser = new ClustalWParser(); configparams.UseBrowserProxy = true; TestIClustalWServiceHandler handler = new TestIClustalWServiceHandler(clustalparser, configparams); ClustalWParameters parameters = new ClustalWParameters(); parameters.Values[ClustalWParameters.Email] = emailId; parameters.Values[ClustalWParameters.ClusterOption] = clusterOption; parameters.Values[ClustalWParameters.ActionAlign] = actionAlign; IEnumerable<ISequence> sequence = null; // Get the input sequences using (FastAParser parser = new FastAParser(filepath)) { sequence = parser.Parse(); // Submit job and validate it returned valid job id and control id ServiceParameters svcparameters = handler.SubmitRequest(sequence.ToList(), parameters); Assert.IsFalse(string.IsNullOrEmpty(svcparameters.JobId)); ApplicationLog.WriteLine(string.Concat("JobId", svcparameters.JobId)); foreach (string key in svcparameters.Parameters.Keys) { Assert.IsFalse(string.IsNullOrEmpty(svcparameters.Parameters[key].ToString())); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "{0}:{1}", key, svcparameters.Parameters[key].ToString())); } // Get the results and validate it is not null. ClustalWResult result = handler.FetchResultsSync(svcparameters); Assert.IsNotNull(result); Assert.IsNotNull(result.SequenceAlignment); foreach (IAlignedSequence alignSeq in result.SequenceAlignment.AlignedSequences) { ApplicationLog.WriteLine("Aligned Sequence Sequences :"); foreach (ISequence seq in alignSeq.Sequences) { ApplicationLog.WriteLine(string.Concat("Sequence:", seq.ToString())); } } } ApplicationLog.WriteLine(@"ClustalWServiceHandler BVT : Submit job and Get Results is successfully completed using FetchResultSync()"); }