/// <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">&nbsp; 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());
        }
Exemplo n.º 2
0
        /// <summary>
        /// @see IJobParametersExtractor#GetJobParameters(Job, StepExecution).
        /// </summary>
        /// <param name="job"></param>
        /// <param name="stepExecution"></param>
        /// <returns></returns>
        public JobParameters GetJobParameters(IJob job, StepExecution stepExecution)
        {
            JobParametersBuilder builder = new JobParametersBuilder();
            IDictionary <string, JobParameter> jobParameters = stepExecution.GetJobParameters().GetParameters();
            ExecutionContext executionContext = stepExecution.ExecutionContext;

            if (_useAllParentParameters)
            {
                foreach (string key in jobParameters.Keys)
                {
                    builder.AddParameter(key, jobParameters[key]);
                }
            }
            foreach (string akey in _keys)
            {
                string key = akey;
                if (key.EndsWith("(long)") || key.EndsWith("(int)"))
                {
                    HandleLongOrIntKey(key, executionContext, builder, jobParameters);
                }
                else if (key.EndsWith("(double)"))
                {
                    HandleDoubleKey(key, executionContext, builder, jobParameters);
                }
                else if (key.EndsWith("(string)"))
                {
                    HandleStringKey(key, executionContext, builder, jobParameters);
                }
                else if (key.EndsWith("(date)"))
                {
                    HandleDateKey(key, executionContext, builder, jobParameters);
                }
                else
                {
                    DefaultHandle(executionContext, key, builder, jobParameters);
                }
            }
            return(builder.ToJobParameters());
        }
        /// <summary>
        /// @see IJobParametersExtractor#GetJobParameters(Job, StepExecution).
        /// </summary>
        /// <param name="job"></param>
        /// <param name="stepExecution"></param>
        /// <returns></returns>
        public JobParameters GetJobParameters(IJob job, StepExecution stepExecution)
        {
            JobParametersBuilder builder = new JobParametersBuilder();
            IDictionary<string, JobParameter> jobParameters = stepExecution.GetJobParameters().GetParameters();
            ExecutionContext executionContext = stepExecution.ExecutionContext;
            if (_useAllParentParameters)
            {
                foreach (string key in jobParameters.Keys)
                {
                    builder.AddParameter(key, jobParameters[key]);
                }
            }
            foreach (string akey in _keys)
            {
                string key = akey;
                if (key.EndsWith("(long)") || key.EndsWith("(int)"))
                {
                    HandleLongOrIntKey(key, executionContext, builder, jobParameters);
                }
                else if (key.EndsWith("(double)"))
                {
                    HandleDoubleKey(key, executionContext, builder, jobParameters);
                }
                else if (key.EndsWith("(string)"))
                {
                    HandleStringKey(key, executionContext, builder, jobParameters);
                }
                else if (key.EndsWith("(date)"))
                {
                    HandleDateKey(key, executionContext, builder, jobParameters);
                }
                else
                {
                    DefaultHandle(executionContext, key, builder, jobParameters);
                }
            }
            return builder.ToJobParameters();

        }
        /// <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">&nbsp; 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();
        }