示例#1
0
        /// <summary>
        /// Adds items from a list of items.  This allows non-sequence values to be added. Eg.
        /// { "91352", 66202", "34761" }   // zip codes
        /// { "Fred", "Harry", "Sally" }
        ///
        /// </summary>
        /// <param name="name">The iteration item name</param>
        /// <param name="itemValues"></param>
        /// <returns></returns>
        public int AddListItems(string name, List <string> itemValues)
        {
            if (IterationItemNameExists(name))
            {
                throw new ArgumentException(string.Format("The name \"{0}\" is already used by another itermation item.", name));
            }

            if (itemValues == null || itemValues.Count == 0)
            {
                throw new ArgumentException(string.Format("The list of items to add can not be empty.", name));
            }

            int           result = 0;
            IterationItem item   = new IterationItem();

            item.Name            = name;
            item.IterationValues = new SerializableDictionary <int, string>();
            foreach (string value in itemValues)
            {
                item.IterationValues.Add(item.IterationValues.Count, value);
            }
            result = item.IterationValues.Count;
            if (result == 0)
            {
                throw new ArgumentException(string.Format("The name \"{0}\" has no items: at least one must be defined.", name));
            }
            _IterationItems.Add(_IterationItems.Count, item);
            _TotalIterationCount = (_TotalIterationCount == 0L ? 1L : _TotalIterationCount) * item.IterationValues.Count;
            return(result);
        }
示例#2
0
        /// <summary>
        /// Add numbers by start and loop count.
        /// </summary>
        /// <param name="name">Name of the parameter</param>
        /// <param name="initialValue">the starting value</param>
        /// <param name="incrementValue">the step or increment to the next value</param>
        /// <param name="iterationCount">the number of times to increment the value and add the new value to list.</param>
        /// <returns>The number of items created for the iteration item.</returns>
        public int AddNumberSequence(string name, double initialValue, double incrementValue, int iterationCount)
        {
            if (IterationItemNameExists(name))
            {
                throw new ArgumentException(string.Format("The name \"{0}\" is already used by another itermation item.", name));
            }

            if (Math.Sign(incrementValue) == 0.0)
            {
                throw new ArgumentException(string.Format("The increment value for \"{0}\" can not be zero.", name));
            }

            int           result = 0;
            IterationItem item   = new IterationItem();

            item.Name            = name;
            item.IterationValues = new SerializableDictionary <int, string>();
            double v = initialValue;

            while (iterationCount > 0)
            {
                item.IterationValues.Add(item.IterationValues.Count, v.ToString());
                v += incrementValue;
                iterationCount--;
            }
            result = item.IterationValues.Count;
            if (result == 0)
            {
                throw new ArgumentException(string.Format("The name \"{0}\" has no items: at least one must be defined.", name));
            }
            _IterationItems.Add(_IterationItems.Count, item);
            _TotalIterationCount = (_TotalIterationCount == 0L ? 1L : _TotalIterationCount) * item.IterationValues.Count;
            return(result);
        }
示例#3
0
        /// <summary>
        /// Add numbers by range and increment as an iteration item.  This is equivalent to:
        /// for (double value = initialValue, value &lt; limitValue, value += incrementValue)  // when increment is positive
        /// for (double value = initialValue, value &gt; limitValue, value -= incrementValue)  // when increment is negative
        /// </summary>
        /// <param name="name">Name of the parameter</param>
        /// <param name="initialValue">the starting value</param>
        /// <param name="incrementValue">the step or increment to the next value</param>
        /// <param name="limitValue">the end value</param>
        /// <param name="endValueEval">whether the end value itself can be included in the list of items.</param>
        /// <returns>The number of items created for the iteration item.</returns>
        public int AddNumberRange(string name, double initialValue, double incrementValue, double limitValue, EndValueEval endValueEval)
        {
            if (IterationItemNameExists(name))
            {
                throw new ArgumentException(string.Format("The name \"{0}\" is already used by another itermation item.", name));
            }

            if (Math.Sign(incrementValue) == 1 && initialValue > limitValue)
            {
                throw new ArgumentException(string.Format("The increment value for \"{0}\" can not be zero.", name));
            }

            if ((limitValue > initialValue && Math.Sign(incrementValue) == -1) || (initialValue > limitValue && Math.Sign(incrementValue) == 1))
            {
                throw new ArgumentException(string.Format(
                                                "The increment value must be {0} to iterate from {1} to {2}",
                                                Math.Sign(incrementValue) == -1 ? "positive" : "negative",
                                                initialValue,
                                                limitValue));
            }

            int           result = 0;
            IterationItem item   = new IterationItem();

            item.Name            = name;
            item.IterationValues = new SerializableDictionary <int, string>();
            double v = initialValue;

            if (Math.Sign(incrementValue) == -1)
            {
                limitValue += endValueEval == EndValueEval.Inclusive ? -1 : 0;
            }
            else
            {
                limitValue += endValueEval == EndValueEval.Inclusive ? 1 : 0;
            }

            bool keepGoing = true;

            while (keepGoing)
            {
                keepGoing = Math.Sign(incrementValue) == -1 ? (v > limitValue) : (v < limitValue);
                if (!keepGoing)
                {
                    break;
                }
                item.IterationValues.Add(item.IterationValues.Count, v.ToString());
                v += incrementValue;
            }
            result = item.IterationValues.Count;
            if (result == 0)
            {
                throw new ArgumentException(string.Format("The name \"{0}\" has no items: at least one must be defined.", name));
            }
            _IterationItems.Add(_IterationItems.Count, item);
            _TotalIterationCount = (_TotalIterationCount == 0L ? 1L : _TotalIterationCount) * item.IterationValues.Count;
            return(result);
        }
示例#4
0
 /// <summary>
 /// Loads the existing instance with replacement values for its properties.
 /// </summary>
 /// <param name="obj"></param>
 public void Load(IterationItem obj)
 {
     this._Name            = obj.Name;
     this._IterationValues = obj.IterationValues;
 }
示例#5
0
 /// <summary>
 /// Created an iteration item from an existing object.
 /// </summary>
 /// <param name="obj"></param>
 public IterationItem(IterationItem obj)
 {
     this.Load(obj);
 }