private static void HandleDoubleKey(string key, ExecutionContext executionContext, JobParametersBuilder builder, IDictionary <string, JobParameter> jobParameters) { string akey = key.Replace("(double)", ""); if (executionContext.ContainsKey(akey)) { builder.AddDouble(akey, executionContext.GetDouble(akey)); } else if (jobParameters.ContainsKey(akey)) { builder.AddDouble(akey, (Double)jobParameters[akey].Value); } }
/// <summary> /// Checks for suffix on keys and use those to decide how to convert the value. /// </summary> /// <param name="props"></param> /// <returns></returns> /// <exception cref="ArgumentException"> if a number or date is passed in that cannot be parsed, or cast to the correct type.</exception> public JobParameters GetJobParameters(NameValueCollection props) { if (props == null || props.Count == 0) { return(new JobParameters()); } JobParametersBuilder propertiesBuilder = new JobParametersBuilder(); foreach (string pkey in props.Keys) { string key = pkey; string value = props[pkey]; bool identifying = IsIdentifyingKey(key); if (!identifying) { key = StringUtils.ReplaceFirst(key, NonIdentifyingFlag, ""); } else if (key.StartsWith(IdentifyingFlag)) { key = StringUtils.ReplaceFirst(key, IdentifyingFlag, ""); } if (key.EndsWith(DateType)) { DateTime?date; try { date = DateTime.ParseExact(value, _dateFormat, CultureInfo.InvariantCulture); } catch (FormatException) { throw new ArgumentException(string.Format("Date Format is invalid :[{0}] {1}", value, _dateFormat)); } propertiesBuilder.AddDate(key.Replace(DateType, string.Empty), date, identifying); } else if (key.EndsWith(LongType)) { long result = ParseLong(value); propertiesBuilder.AddLong(key.Replace(LongType, string.Empty), result, identifying); } else if (key.EndsWith(DoubleType)) { double result = ParseDouble(value); propertiesBuilder.AddDouble(key.Replace(DoubleType, string.Empty), result, identifying); } else if (StringUtils.EndsWithIgnoreCase(key, StringType)) { propertiesBuilder.AddString(key.Replace(StringType, string.Empty), value, identifying); } else { propertiesBuilder.AddString(key, value, identifying); } } return(propertiesBuilder.ToJobParameters()); }
private static void HandleDoubleKey(string key, ExecutionContext executionContext, JobParametersBuilder builder, IDictionary<string, JobParameter> jobParameters) { string akey = key.Replace("(double)", ""); if (executionContext.ContainsKey(akey)) { builder.AddDouble(akey, executionContext.GetDouble(akey)); } else if (jobParameters.ContainsKey(akey)) { builder.AddDouble(akey, (Double)jobParameters[akey].Value); } }
/// <summary> /// Checks for suffix on keys and use those to decide how to convert the value. /// </summary> /// <param name="props"></param> /// <returns></returns> /// <exception cref="ArgumentException"> if a number or date is passed in that cannot be parsed, or cast to the correct type.</exception> public JobParameters GetJobParameters(NameValueCollection props) { if (props == null || props.Count == 0) { return new JobParameters(); } JobParametersBuilder propertiesBuilder = new JobParametersBuilder(); foreach (string pkey in props.Keys) { string key = pkey; string value = props[pkey]; bool identifying = IsIdentifyingKey(key); if (!identifying) { key = StringUtils.ReplaceFirst(key, NonIdentifyingFlag, ""); } else if (key.StartsWith(IdentifyingFlag)) { key = StringUtils.ReplaceFirst(key, IdentifyingFlag, ""); } if (key.EndsWith(DateType)) { DateTime? date; try { date = DateTime.ParseExact(value, _dateFormat, CultureInfo.InvariantCulture); } catch (FormatException) { throw new ArgumentException(string.Format("Date Format is invalid :[{0}] {1}" ,value, _dateFormat)); } propertiesBuilder.AddDate(key.Replace(DateType, string.Empty), date, identifying); } else if (key.EndsWith(LongType)) { long result = ParseLong(value); propertiesBuilder.AddLong(key.Replace(LongType, string.Empty), result, identifying); } else if (key.EndsWith(DoubleType)) { double result = ParseDouble(value); propertiesBuilder.AddDouble(key.Replace(DoubleType, string.Empty), result, identifying); } else if (StringUtils.EndsWithIgnoreCase(key, StringType)) { propertiesBuilder.AddString(key.Replace(StringType, string.Empty), value, identifying); } else { propertiesBuilder.AddString(key, value, identifying); } } return propertiesBuilder.ToJobParameters(); }