/// <summary> /// This method would validate and add the params to the service /// parameters for the requested search /// </summary> /// <param name="serviceParam">Service parameter</param> /// <param name="paramName">Param name</param> /// <param name="paramValue">Param value</param> /// <returns>whether the parameter was valid</returns> private static bool CheckNAddServiceParams(ref BlastParameters serviceParam, string paramName, string paramValue) { RequestParameter param = BlastParameters.Parameters[paramName]; if (string.IsNullOrEmpty(paramValue)) { return(true); } else if (param.DataType == "int" && param.Validator == null) { int number; // Validate the int and double values which doesnot have validators. if (!Int32.TryParse(paramValue, out number)) { MessageDialogBox.Show(Resource.INVALID_TEXT + paramName + Resource.VALUE_TEXT, Properties.Resource.CAPTION, MessageDialogButton.OK); return(false); } } else if (param.DataType == "double" && param.Validator == null) { double number; if (!Double.TryParse(paramValue, out number)) { MessageDialogBox.Show(Resource.INVALID_TEXT + paramName + Resource.VALUE_TEXT, Properties.Resource.CAPTION, MessageDialogButton.OK); return(false); } } if (param.IsValid(paramValue)) { serviceParam.Add(paramName, paramValue); return(true); } else { MessageDialogBox.Show(Resource.INVALID_TEXT + paramName + Resource.VALUE_TEXT, Properties.Resource.CAPTION, MessageDialogButton.OK); return(false); } }
/// <summary> /// This method would validate and add the params to the service /// parameters for the requested search /// </summary> /// <param name="serviceParam">Service parameter</param> /// <param name="paramName">Param name</param> /// <param name="paramValue">Param value</param> /// <returns>whether the parameter was valid</returns> private static bool AddValidServiceParams(ref BlastParameters serviceParam, string paramName, string paramValue) { RequestParameter param = BlastParameters.Parameters[paramName]; if (string.IsNullOrEmpty(paramValue)) { return(true); } else if (param.DataType == PARAMTYPEINT && param.Validator == null) { int number; // Validate the int and double values which doesnot have validators. if (!Int32.TryParse(paramValue, out number)) { MessageBox.Show(Properties.Resources.INVALID_TEXT + paramName + Properties.Resources.VALUE_TEXT, Properties.Resources.CAPTION, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } } else if (param.DataType == PARAMTYPEDOUBLE && param.Validator == null) { double number; if (!Double.TryParse(paramValue, out number)) { MessageBox.Show(Properties.Resources.INVALID_TEXT + paramName + Properties.Resources.VALUE_TEXT, Properties.Resources.CAPTION, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } } if (param.IsValid(paramValue)) { serviceParam.Add(paramName, paramValue); return(true); } else { MessageBox.Show(Properties.Resources.INVALID_TEXT + paramName + Properties.Resources.VALUE_TEXT, Properties.Resources.CAPTION, MessageBoxButton.OK, MessageBoxImage.Error); return(false); } }
/// <summary> /// Validate a parameter/value pair, and add them to Values, /// replacing any value already present for that parameter. /// </summary> /// <param name="parameterName">The parameter name</param> /// <param name="parameterValue">The parameter value</param> public void Add(string parameterName, string parameterValue) { if (!parameters.ContainsKey(parameterName)) { string message = String.Format(CultureInfo.InvariantCulture, Properties.Resource.PARAMETER_UNKNOWN, parameterName); throw new Exception(message); } RequestParameter param = parameters[parameterName]; if (!param.IsValid(parameterValue)) { string message = String.Format(CultureInfo.InvariantCulture, Properties.Resource.PARAMETER_VALUE_INVALID, parameterValue, parameterName); throw new Exception(message); } Values[param.SubmitName] = parameterValue; }
/// <summary> /// Validate a parameter/value pair, then add it to the Settings collection. /// The overwrite value determines whether the new value can overwrite an /// existing value for the same parameter. /// </summary> /// <param name="paramName">The parameter to set</param> /// <param name="paramValue">The parameter value</param> /// <param name="overwrite">If true, overwrite any existing value.</param> private void Add(string paramName, string paramValue, bool overwrite) { if (!parameters.ContainsKey(paramName)) { string message = String.Format(CultureInfo.InvariantCulture, Properties.Resource.NcbiBlastUnknownParam, paramName); Trace.Report(message); throw new Exception(message); } RequestParameter param = parameters[paramName]; if (!param.IsValid(paramValue)) { string message = String.Format(CultureInfo.InvariantCulture, Properties.Resource.NcbiBlastInvalidValue, paramValue, paramName); Trace.Report(message); throw new Exception(message); } if (Settings.ContainsKey(param.SubmitName)) { if (overwrite) { Settings[param.SubmitName] = paramValue; } // else leave existing value } else { Settings.Add(param.SubmitName, paramValue); } }
/// <summary> /// Validate a parameter/value pair, then add it to the Settings collection. /// The overwrite value determines whether the new value can overwrite an /// existing value for the same parameter. /// </summary> /// <param name="paramName">The parameter to set</param> /// <param name="paramValue">The parameter value</param> /// <param name="overwrite">If true, overwrite any existing value.</param> private void Add(string paramName, string paramValue, bool overwrite) { if (!_parameters.ContainsKey(paramName)) { string message = String.Format(CultureInfo.InvariantCulture, "NcbiBlastParameters: Unknown parameter name {0}.", paramName); Trace.Report(message); throw new Exception(message); } RequestParameter param = _parameters[paramName]; if (!param.IsValid(paramValue)) { string message = String.Format(CultureInfo.InvariantCulture, "NcbiBlastParameters: Invalid parameter value {0} for parameter {0}.", paramValue, paramName); Trace.Report(message); throw new Exception(message); } if (Settings.ContainsKey(param.SubmitName)) { if (overwrite) { Settings[param.SubmitName] = paramValue; } // else leave existing value } else { Settings.Add(param.SubmitName, paramValue); } }