Пример #1
0
        public void Format(ICrontabField field, TextWriter writer, bool noNames)
        {
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }

            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            var next  = field.GetFirst();
            var count = 0;

            while (next != -1)
            {
                var first = next;
                int last;

                do
                {
                    last = next;
                    next = field.Next(last + 1);
                }while (next - last == 1);

                if (count == 0 &&
                    first == _minValue && last == _maxValue)
                {
                    writer.Write('*');
                    return;
                }

                if (count > 0)
                {
                    writer.Write(',');
                }

                if (first == last)
                {
                    FormatValue(first, writer, noNames);
                }
                else
                {
                    FormatValue(first, writer, noNames);
                    writer.Write('-');
                    FormatValue(last, writer, noNames);
                }

                count++;
            }
        }
Пример #2
0
 public void Format(ICrontabField field, TextWriter writer) =>
 Format(field, writer, false);
        /// <summary>
        /// Formats the specified field.	
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="writer">The writer.</param>
        /// <param name="noNames">The no names.</param>
        /// <remarks></remarks>
        public void Format(ICrontabField field, TextWriter writer, bool noNames)
        {
            if (field == null)
                throw new ArgumentNullException("field");

            if (writer == null)
                throw new ArgumentNullException("writer");

            var next = field.GetFirst();
            var count = 0;

            while (next != -1)
            {
                var first = next;
                int last;

                do
                {
                    last = next;
                    next = field.Next(last + 1);
                }
                while (next - last == 1);

                if (count == 0 
                    && first == _minValue && last == _maxValue)
                {
                    writer.Write('*');
                    return;
                }
                
                if (count > 0)
                    writer.Write(',');

                if (first == last)
                {
                    FormatValue(first, writer, noNames);
                }
                else
                {
                    FormatValue(first, writer, noNames);
                    writer.Write('-');
                    FormatValue(last, writer, noNames);
                }

                count++;
            }
        }
 /// <summary>
 /// Formats the specified field.	
 /// </summary>
 /// <param name="field">The field.</param>
 /// <param name="writer">The writer.</param>
 /// <remarks></remarks>
 public void Format(ICrontabField field, TextWriter writer)
 {
     Format(field, writer, false);
 }