Пример #1
0
        /// <summary>
        /// Builds the description for the specified type from the list of directives into the result StringBuilder
        /// </summary>
        /// <param name="directives">The directives.</param>
        /// <param name="result">The result StringBuilder.</param>
        /// <returns><c>true</c> if there should be a "skip" after building this description, otherwise <c>false</c>.</returns>
        public override bool BuildDescription(List <DescriptionDirective> directives, StringBuilder result)
        {
            DescriptionDirective directive = directives.FirstOrDefault(d => d.Field == this.FieldKind);

            if (directive != null)
            {
                if (directive.IsEvery)
                {
                    result.Append("every ");
                    result.Append(directive.PartialDescription);
                    result.Append(string.IsNullOrWhiteSpace(directive.PartialDescription) ? " hour " : " hours ");
                }
                else
                {
                    result.Append(this.SingularQualifierName + " ");

                    bool includeMinute = directives.Any(d => d.Field == CrontabFieldKind.Minute && !d.IsEvery);

                    if (includeMinute)
                    {
                        this.BuildSpecificTimes(directives, result);
                        return(true);
                    }
                    else
                    {
                        this.BuildSpecificHours(directive, result);
                    }
                }
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// Builds the specific times in the format hh:mm
        /// </summary>
        /// <param name="directives">The directives.</param>
        /// <param name="result">The result.</param>
        private void BuildSpecificTimes(List <DescriptionDirective> directives, StringBuilder result)
        {
            DescriptionDirective hourDirective   = directives.FirstOrDefault(d => d.Field == this.FieldKind);
            DescriptionDirective minuteDirective = directives.FirstOrDefault(d => d.Field == CrontabFieldKind.Minute);

            var hourParts   = SplitValues(hourDirective.PartialDescription);
            var minuteParts = SplitValues(minuteDirective.PartialDescription);

            for (int h = 0; h < hourParts.Count; h++)
            {
                var hourPart = hourParts[h];
                AppendTimeWithMinutes(result, minuteParts, hourPart.Item1);

                if (hourPart.Item2.HasValue)
                {
                    result.Append("-");
                    AppendTimeWithMinutes(result, minuteParts, hourPart.Item2.Value);
                }

                if (h < hourParts.Count - 1)
                {
                    result.Append(",");
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Builds the description for the specified type from the list of directives into the result StringBuilder
        /// </summary>
        /// <param name="directives">The directives.</param>
        /// <param name="result">The result StringBuilder.</param>
        /// <returns><c>true</c> if there should be a "skip" after building this description, otherwise <c>false</c>.</returns>
        public override bool BuildDescription(List <DescriptionDirective> directives, StringBuilder result)
        {
            DescriptionDirective directive = directives.FirstOrDefault(d => d.Field == this.FieldKind);

            if (directive != null)
            {
                result.Append(directive.IsEvery ? "every " : this.SingularQualifierName + " ");
                result.Append(directive.PartialDescription);
                result.Append(string.IsNullOrWhiteSpace(directive.PartialDescription) ? " minute " : " minutes ");
            }

            return(false);
        }
Пример #4
0
        /// <summary>
        /// Builds the specific hours.
        /// </summary>
        /// <param name="directive">The directive.</param>
        /// <param name="result">The result.</param>
        private void BuildSpecificHours(DescriptionDirective directive, StringBuilder result)
        {
            var parts = SplitValues(directive.PartialDescription);

            for (int i = 0; i < parts.Count; i++)
            {
                var hourPart = parts[i];
                result.Append(AddMeridian(hourPart.Item1));
                if (hourPart.Item2.HasValue)
                {
                    result.Append("-");
                    result.Append(AddMeridian(hourPart.Item2.Value));
                }

                if (i < parts.Count - 1)
                {
                    result.Append(",");
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Builds the description for the specified type from the list of directives into the result StringBuilder
        /// </summary>
        /// <param name="directives">The directives.</param>
        /// <param name="result">The result StringBuilder.</param>
        /// <returns><c>true</c> if there should be a "skip" after building this description, otherwise <c>false</c>.</returns>
        public override bool BuildDescription(List <DescriptionDirective> directives, StringBuilder result)
        {
            DescriptionDirective directive = directives.FirstOrDefault(d => d.Field == this.FieldKind);

            if (directive != null)
            {
                if (directive.IsEvery)
                {
                    result.Append("every ");
                    result.Append(directive.PartialDescription);
                    result.Append(string.IsNullOrWhiteSpace(directive.PartialDescription) ? " day " : " days ");
                }
                else
                {
                    result.Append(this.SingularQualifierName + " ");
                    var dayParts = SplitValues(directive.PartialDescription);

                    for (int i = 0; i < dayParts.Count; i++)
                    {
                        var dayPart = dayParts[i];
                        result.Append(this.MakethTheNumber(dayPart.Item1));
                        if (dayPart.Item2.HasValue)
                        {
                            result.Append("-");
                            result.Append(this.MakethTheNumber(dayPart.Item2.Value));
                        }

                        if (i < dayParts.Count - 1)
                        {
                            result.Append(",");
                        }
                    }

                    result.Append(dayParts.Count == 1 ? " day " : " days ");
                }
            }

            return(false);
        }
Пример #6
0
        /// <summary>
        /// Gets the description directive.
        /// </summary>
        /// <param name="schedulePart">The schedule part.</param>
        /// <returns></returns>
        public virtual DescriptionDirective GetDescriptionDirective(string schedulePart)
        {
            DescriptionDirective directive = new DescriptionDirective();
            string compactSchedulePart     = this.Compact(schedulePart);

            directive.Field = this.FieldKind;
            if (compactSchedulePart.Contains("*"))
            {
                directive.IsEvery = true;
                var splitValues = compactSchedulePart.Split('/');
                if (splitValues.Length > 1)
                {
                    directive.PartialDescription = splitValues[1];
                }
            }
            else
            {
                directive.IsEvery            = false;
                directive.PartialDescription = compactSchedulePart;
            }

            return(directive);
        }
Пример #7
0
        /// <summary>
        /// Builds the description for the specified type from the list of directives into the result StringBuilder
        /// </summary>
        /// <param name="directives">The directives.</param>
        /// <param name="result">The result StringBuilder.</param>
        /// <returns><c>true</c> if there should be a "skip" after building this description, otherwise <c>false</c>.</returns>
        public override bool BuildDescription(List <DescriptionDirective> directives, StringBuilder result)
        {
            DescriptionDirective directive = directives.FirstOrDefault(d => d.Field == this.FieldKind);

            if (directive != null)
            {
                // cron should not be compacted here. so * should not have any number with it
                if (directive.IsEvery)
                {
                    result.Append("any day of the week ");
                }
                else
                {
                    result.Append(this.SingularQualifierName + " ");
                    var dayParts = SplitValues(directive.PartialDescription);

                    for (int i = 0; i < dayParts.Count; i++)
                    {
                        var dayPart = dayParts[i];
                        result.Append(DayOfWeek[dayPart.Item1]);
                        if (dayPart.Item2.HasValue)
                        {
                            result.Append("-");
                            result.Append(DayOfWeek[dayPart.Item2.Value]);
                        }

                        if (i < dayParts.Count - 1)
                        {
                            result.Append(",");
                        }
                    }
                }
            }

            return(false);
        }