/// <summary> /// Constructs an array of cron values from the current settings of the control. /// </summary> /// <param name="valueIndex"> /// The index of the value column of the tree list store. /// </param> /// <param name="wildcardPattern"> /// The cron value pattern which indicates that the value represents all possible values. /// </param> /// <param name="creator"> /// The factory method that creates CronValues of the appropriate type. /// </param> /// <returns> /// An array cron values representing the current settings of the control. /// </returns> private ArrayList CreateSpecification(int valueIndex, string wildcardPattern, CronValueFactory.CronValueCreator creator) { ArrayList specArray = new ArrayList(); TreeIter iter = TreeIter.Zero; bool done = false; bool more = listStore.GetIterFirst(out iter); bool isChecked = false; while (! done) { string spec = ""; // Find the first checked item bool foundFirst = false; int firstValueInRange = -1; while (more && ! foundFirst) { isChecked = (bool) listStore.GetValue(iter, 0); if (isChecked) { foundFirst = true; firstValueInRange = (int) listStore.GetValue(iter, valueIndex); } else { more = listStore.IterNext(ref iter); } } if (foundFirst) { spec += firstValueInRange.ToString(); bool foundEndOfContiguous = false; int secondValueInRange = -1; if (more) { more = listStore.IterNext(ref iter); while (more && ! foundEndOfContiguous) { isChecked = (bool) listStore.GetValue(iter, 0); if (isChecked) { secondValueInRange = (int) listStore.GetValue(iter, valueIndex); more = listStore.IterNext(ref iter); } else { foundEndOfContiguous = true; } } if (foundEndOfContiguous) { if (secondValueInRange >= 0) { spec += string.Format("-{0}", secondValueInRange); } } else if (secondValueInRange >= 0) { spec += string.Format("-{0}", secondValueInRange); } specArray.Add(creator.CreateCronValue(spec)); if (more) { more = listStore.IterNext(ref iter); } else { done = true; } } else { done = true; } } else { done = true; } } if (specArray.Count == 0) { specArray.Add(creator.CreateCronValue("*")); } else if (specArray.Count == 1) { string specStr = specArray[0].ToString(); if (specStr.Equals(wildcardPattern)) { specArray.Clear(); specArray.Add(creator.CreateCronValue("*")); } } return specArray; }
/// <summary> /// Parses a single temporal component of the raw specification into the appropriate list of CronValues. /// </summary> /// <remarks> /// For example, you might pass the minute portion of the specification through to be parsed. /// </remarks> /// <param name="specification"> /// A portion of the raw specification to be parsed (e.g. the minutes portion) /// </param> /// <param name="cronValues"> /// The list of parsed cron values. /// </param> /// <param name="cronValueCreator"> /// An implementation of the appropriate creator for the type of cron specification being parsed. /// </param> private void ParseSpecification(string specification, ArrayList cronValues, CronValueFactory.CronValueCreator cronValueCreator) { if (specification == null) { throw new ArgumentNullException("specification"); } string[] specComponents = specification.Split(','); foreach (string specComponent in specComponents) { cronValues.Add(cronValueCreator.CreateCronValue(specComponent)); } }