Esempio n. 1
0
        private void SetRepeatItems(CronRow row, TimeSpan timeSpan)
        {
            if (timeSpan.Minutes > 0 && timeSpan.Hours == 0 && timeSpan.Days == 0)
            {
                // e.g. every 15 minutes
                row.Minute.Start       = timeSpan.Minutes.ToString();
                row.Minute.IsRepeating = true;
            }
            else if (timeSpan.Minutes > 0 && timeSpan.Hours > 0 && timeSpan.Days == 0)
            {
                // e.g. every 15 minutes, 3 hours
                row.Minute.Start       = timeSpan.Minutes.ToString();
                row.Minute.IsRepeating = true;

                row.Hours.Start       = timeSpan.Hours.ToString();
                row.Hours.IsRepeating = true;
            }
            else if (timeSpan.Minutes > 0 && timeSpan.Hours > 0 && timeSpan.Days > 0)
            {
                // e.g. every 15 minutes, 3 hours, 2nd day
                row.Minute.Start       = timeSpan.Minutes.ToString();
                row.Minute.IsRepeating = true;

                row.Hours.Start       = timeSpan.Hours.ToString();
                row.Hours.IsRepeating = true;

                row.DayOfMonth.Start       = timeSpan.Days.ToString();
                row.DayOfMonth.IsRepeating = true;
            }
            else if (timeSpan.Minutes == 0 && timeSpan.Hours > 0 && timeSpan.Days == 0)
            {
                // e.g. every 5 hours
                row.Hours.Start       = timeSpan.Hours.ToString();
                row.Hours.IsRepeating = true;
            }
            else if (timeSpan.Minutes == 0 && timeSpan.Hours > 0 && timeSpan.Days > 0)
            {
                // e.g. every 5 hours, 2 Days
                row.Hours.Start       = timeSpan.Hours.ToString();
                row.Hours.IsRepeating = true;

                row.DayOfMonth.Start       = timeSpan.Days.ToString();
                row.DayOfMonth.IsRepeating = true;
            }
            else if (timeSpan.Minutes == 0 && timeSpan.Hours == 0 && timeSpan.Days > 0)
            {
                // e.g. every 2nd Day
                row.DayOfMonth.Start       = timeSpan.Days.ToString();
                row.DayOfMonth.IsRepeating = true;
            }
        }
		public string ToCronExpression(Task task)
		{
			TaskDefinition definition = task.Definition;

			if (definition.Triggers.Any())
			{
				var lines = new List<string>();

				foreach (Trigger trigger in definition.Triggers)
				{
					// Windows has many-to-many for actions and triggers, cron doesn't.
					// So map them all into rows - 2 triggers and 2 actions are 4 rows.
					foreach (Action action in definition.Actions)
					{
						var cronRow = new CronRow()
						{
							Name = task.Name
						};
						cronRow.Command = GetCommandText(action);

						DateTime startDate = trigger.StartBoundary;

						cronRow.SetStartFromDate(startDate);

						if (trigger.Repetition.IsSet())
						{
							TimeSpan interval = trigger.Repetition.Interval;
							SetRepeatItems(cronRow, interval);
						}

						Helper.WriteConsoleColor($"[{cronRow.Name}] ", ConsoleColor.Green);

						if (_listOptions.Explain)
						{
							_writer.WriteLine();
							_writer.WriteLine("{0}", cronRow.Explain());
						}
						else
						{
							_writer.WriteLine("{0}", cronRow.CronString());
						}

						Helper.WriteConsoleColor(cronRow.ShortnedCommand, ConsoleColor.DarkGray);
						_writer.WriteLine();
					}
				}
			}

			return "";
		}
Esempio n. 3
0
        public string ToCronExpression(Task task)
        {
            TaskDefinition definition = task.Definition;

            if (definition.Triggers.Any())
            {
                var lines = new List <string>();

                foreach (Trigger trigger in definition.Triggers)
                {
                    // Windows has many-to-many for actions and triggers, cron doesn't.
                    // So map them all into rows - 2 triggers and 2 actions are 4 rows.
                    foreach (Action action in definition.Actions)
                    {
                        var cronRow = new CronRow()
                        {
                            Name = task.Name
                        };
                        cronRow.Command = GetCommandText(action);

                        DateTime startDate = trigger.StartBoundary;

                        cronRow.SetStartFromDate(startDate);

                        if (trigger.Repetition.IsSet())
                        {
                            TimeSpan interval = trigger.Repetition.Interval;
                            SetRepeatItems(cronRow, interval);
                        }

                        Helper.WriteConsoleColor($"[{cronRow.Name}] ", ConsoleColor.Green);

                        if (_listOptions.Explain)
                        {
                            _writer.WriteLine();
                            _writer.WriteLine("{0}", cronRow.Explain());
                        }
                        else
                        {
                            _writer.WriteLine("{0}", cronRow.CronString());
                        }

                        Helper.WriteConsoleColor(cronRow.ShortnedCommand, ConsoleColor.DarkGray);
                        _writer.WriteLine();
                    }
                }
            }

            return("");
        }
		private void SetRepeatItems(CronRow row, TimeSpan timeSpan)
		{
			if (timeSpan.Minutes > 0 && timeSpan.Hours == 0 && timeSpan.Days == 0)
			{
				// e.g. every 15 minutes
				row.Minute.Start = timeSpan.Minutes.ToString();
				row.Minute.IsRepeating = true;
			}
			else if (timeSpan.Minutes > 0 && timeSpan.Hours > 0 && timeSpan.Days == 0)
			{
				// e.g. every 15 minutes, 3 hours
				row.Minute.Start = timeSpan.Minutes.ToString();
				row.Minute.IsRepeating = true;

				row.Hours.Start = timeSpan.Hours.ToString();
				row.Hours.IsRepeating = true;
			}
			else if (timeSpan.Minutes > 0 && timeSpan.Hours > 0 && timeSpan.Days > 0)
			{
				// e.g. every 15 minutes, 3 hours, 2nd day
				row.Minute.Start = timeSpan.Minutes.ToString();
				row.Minute.IsRepeating = true;

				row.Hours.Start = timeSpan.Hours.ToString();
				row.Hours.IsRepeating = true;

				row.DayOfMonth.Start = timeSpan.Days.ToString();
				row.DayOfMonth.IsRepeating = true;
			}
			else if (timeSpan.Minutes == 0 && timeSpan.Hours > 0 && timeSpan.Days == 0)
			{
				// e.g. every 5 hours
				row.Hours.Start = timeSpan.Hours.ToString();
				row.Hours.IsRepeating = true;
			}
			else if (timeSpan.Minutes == 0 && timeSpan.Hours > 0 && timeSpan.Days > 0)
			{
				// e.g. every 5 hours, 2 Days
				row.Hours.Start = timeSpan.Hours.ToString();
				row.Hours.IsRepeating = true;

				row.DayOfMonth.Start = timeSpan.Days.ToString();
				row.DayOfMonth.IsRepeating = true;
			}
			else if (timeSpan.Minutes == 0 && timeSpan.Hours == 0 && timeSpan.Days > 0)
			{
				// e.g. every 2nd Day
				row.DayOfMonth.Start = timeSpan.Days.ToString();
				row.DayOfMonth.IsRepeating = true;
			}
		}