private static string zCronDayOfWeekValue(MonthlySchedule schedule, WeekdayPosition?weekdayPosition, DayOfWeek?weekDay) { if (schedule.MonthlyRecurrenceType == MonthlyRecurrenceType.Weekdays) { if (weekdayPosition.HasValue && weekDay.HasValue) { if (weekdayPosition.Value == WeekdayPosition.Last) { return(String.Format("{0}L", (int)weekDay.Value + 1)); } else { return(String.Format("{0}#{1}", (int)weekDay.Value + 1, weekdayPosition.Value + 1)); } } else if (schedule.Weekdays.Count == 7) { return("*"); } else { return(DescriptionUtils.BuildDescriptiveList(schedule.Weekdays, false, false, wd => ((int)wd + 1).ToString())); } } else { return("?"); } }
public override void ExecuteCmdlet() { if (ParameterSetName == ParentObjectParameterSet) { ResourceGroupName = AccountObject.ResourceGroupName; Location = AccountObject.Location; var NameParts = AccountObject.Name.Split('/'); AccountName = NameParts[0]; } var snapshotPolicyBody = new Management.NetApp.Models.SnapshotPolicy() { Location = Location, Enabled = Enabled, HourlySchedule = (HourlySchedule != null) ? HourlySchedule.ConvertFromPs() : null, DailySchedule = (DailySchedule != null) ? DailySchedule.ConvertFromPs() : null, WeeklySchedule = (WeeklySchedule != null) ? WeeklySchedule.ConvertFromPs() : null, MonthlySchedule = (MonthlySchedule != null) ? MonthlySchedule.ConvertFromPs() : null }; if (ShouldProcess(Name, string.Format(PowerShell.Cmdlets.NetAppFiles.Properties.Resources.CreateResourceMessage, ResourceGroupName))) { var anfSnapshotPolicy = AzureNetAppFilesManagementClient.SnapshotPolicies.Create(snapshotPolicyBody, ResourceGroupName, AccountName, snapshotPolicyName: Name); WriteObject(anfSnapshotPolicy.ConvertToPs()); } }
public void TestOccurrence() { //Arrange MonthlySchedule itemFirst = new MonthlySchedule { MonthlyTheNOccurrence = MonthlySchedule.MonthlyTheNOccurrenceEnum.First }; MonthlySchedule itemSecond = new MonthlySchedule { MonthlyTheNOccurrence = MonthlySchedule.MonthlyTheNOccurrenceEnum.Second }; MonthlySchedule itemThird = new MonthlySchedule { MonthlyTheNOccurrence = MonthlySchedule.MonthlyTheNOccurrenceEnum.Third }; MonthlySchedule itemFourth = new MonthlySchedule { MonthlyTheNOccurrence = MonthlySchedule.MonthlyTheNOccurrenceEnum.Fourth }; MonthlySchedule itemLast = new MonthlySchedule { MonthlyTheNOccurrence = MonthlySchedule.MonthlyTheNOccurrenceEnum.Last }; //Act //Assert Assert.AreEqual(itemFirst.GetMonthlyTheNOccurrenceText(), "first"); Assert.AreEqual(itemSecond.GetMonthlyTheNOccurrenceText(), "second"); Assert.AreEqual(itemThird.GetMonthlyTheNOccurrenceText(), "third"); Assert.AreEqual(itemFourth.GetMonthlyTheNOccurrenceText(), "fourth"); Assert.AreEqual(itemLast.GetMonthlyTheNOccurrenceText(), "last"); }
private static string zCronMinuteValue(MonthlySchedule schedule) { if (schedule.RepeatsDailyOnInterval) { if (schedule.DailyRepetitionInterval.Minutes != 0) { return(String.Format("0/{0}", schedule.DailyRepetitionInterval.Minutes)); } else if (schedule.DailyRepetitionInterval.Seconds != 0) { return("0/1"); } else { return(schedule.DailyRepetitionStartTimeUtc .ToLocalTime() .Minute .ToString()); } } else { return(schedule.StartTimeUtc .ToLocalTime() .Minute .ToString()); } }
private void Test(object sender, System.EventArgs e) { MessageBox.Show("Test will now create all types of schedules and opens Schedules View"); // create and add different types of schedules Schedule s = new IntervalSchedule("Test_Interval", DateTime.Now.AddMinutes(1), 45, TimeSpan.Zero, new TimeSpan(TimeSpan.TicksPerDay)); s.OnTrigger += new EventScheduler.Invoke(ScheduleCallBack); Scheduler.AddSchedule(s); s = new OneTimeSchedule("Test_Onetime", DateTime.Now.AddMinutes(1.5)); s.OnTrigger += new EventScheduler.Invoke(ScheduleCallBack); Scheduler.AddSchedule(s); s = new DailySchedule("Test_daily", DateTime.Now.AddMinutes(2)); s.OnTrigger += new EventScheduler.Invoke(ScheduleCallBack); Scheduler.AddSchedule(s); s = new WeeklySchedule("Test_weekly", DateTime.Now.AddMinutes(2.5)); s.OnTrigger += new EventScheduler.Invoke(ScheduleCallBack); Scheduler.AddSchedule(s); s = new MonthlySchedule("Test_monthly", DateTime.Now.AddMinutes(3)); s.OnTrigger += new EventScheduler.Invoke(ScheduleCallBack); Scheduler.AddSchedule(s); // kick off the Schedules View SchedulerUI.ShowSchedules(); }
public void TestControllerJSONGenerationForMonth() { //Arrange MonthlySchedule item = new MonthlySchedule { RecurrenceType = MonthlySchedule.RecurrenceTypeEnum.Monthly, MonthlyTheNDaySelected = true, MonthlyTheNOccurrence = MonthlySchedule.MonthlyTheNOccurrenceEnum.Last, MonthlyTheNDayOfWeek = DayOfWeek.Friday, MonthlyTheNDayDayMonth = 1, RecurrenceStartDate = new System.DateTime(2019, 1, 25), RecurrenceEndAfterNSelected = true, RecurrenceEndAfterNOccurences = 100 }; ScheduleItem scheduleItem = new ScheduleItem { MonthlySchedule = item }; ScheduleItemController controller = new ScheduleItemController(); //Act item.ProcessFutureDates(); string json = controller.CreateJSON(scheduleItem); ScheduleItem processedItem = controller.ProcessJSON(json); //Assert Assert.IsTrue(json != null); Assert.AreEqual(processedItem.ScheduleItemType, "Monthly"); Assert.IsTrue(processedItem.DailySchedule == null); Assert.IsTrue(processedItem.WeeklySchedule == null); Assert.IsTrue(processedItem.MonthlySchedule != null); Assert.IsTrue(processedItem.YearlySchedule == null); }
/// <summary> /// Allow 3 months to show up as "Quarterly", otherwise return the base implementation of a month description. /// </summary> public override string Format(MonthlySchedule s) { if (s.Frequency == 3) { return(String.Format(String.Concat("Quarterly", (Start.HasValue ? " on day {0}" : "")), Start.Value.Day)); } return(base.Format(s)); }
public void Occurrences_before_start() { // 21/2/2009, 21/8/2010, 21/2/2012, 21/8/2013, 21/2/2015 MonthlySchedule month = new MonthlySchedule { Frequency = 18 }; IList<DateTime> occurrences = Convert(month.GetOccurrences(_start, new DateTime(2009, 1, 1), new DateTime(2009, 2, 1))); Assert.AreEqual(0, occurrences.Count); }
/// <summary> /// Validates null values and other possible combinations /// </summary> public override void Validate() { base.Validate(); if (IsDailyScheduleEnabled == false && IsWeeklyScheduleEnabled == false && IsMonthlyScheduleEnabled == false && IsYearlyScheduleEnabled == false) { throw new ArgumentException(Resources.AllRetentionSchedulesEmptyException); } if (IsDailyScheduleEnabled) { if (DailySchedule == null) { throw new ArgumentException(Resources.DailyScheduleEnabledButScheduleIsNullException); } else { DailySchedule.Validate(); } } if (IsWeeklyScheduleEnabled) { if (WeeklySchedule == null) { throw new ArgumentException(Resources.WeeklyScheduleEnabledButScheduleIsNullException); } else { WeeklySchedule.Validate(); } } if (IsMonthlyScheduleEnabled) { if (MonthlySchedule == null) { throw new ArgumentException(Resources.MonthlyScheduleEnabledButScheduleIsNullException); } else { MonthlySchedule.Validate(); } } if (IsYearlyScheduleEnabled) { if (YearlySchedule == null) { throw new ArgumentException(Resources.YearlyScheduleEnabledButScheduleIsNullException); } else { YearlySchedule.Validate(); } } }
public void Next_occurrence_before_start() { // 21/2/2009, 21/8/2010, 21/2/2012, 21/8/2013, 21/2/2015 MonthlySchedule month = new MonthlySchedule { Frequency = 18 }; DateTime? next = month.NextOccurrence(_start, new DateTime(2000, 1, 1)); Assert.IsTrue(next.HasValue); Assert.AreEqual(new DateTime(2009, 2, 21), next.Value); }
public void Occurrences_stress_test() { var d = new DateTime(1400, 1, 1); MonthlySchedule month = new MonthlySchedule { Frequency = 1 }; // 1/1/1900 (Monday) -> 31/12/1999 (Friday) = 36524 total days; 7 days in every 21 for 100 years; 36524 - 14 days = 36510 / 3 = 12170 IList<DateTime> occurrences = Convert(month.GetOccurrences(d, d, new DateTime(2399, 12, 31))); Assert.AreEqual(12000, occurrences.Count); }
public void Occurrences_before_start() { // 21/2/2009, 21/8/2010, 21/2/2012, 21/8/2013, 21/2/2015 MonthlySchedule month = new MonthlySchedule { Frequency = 18 }; IList <DateTime> occurrences = Convert(month.GetOccurrences(_start, new DateTime(2009, 1, 1), new DateTime(2009, 2, 1))); Assert.AreEqual(0, occurrences.Count); }
public void Occurrences_crossing_start() { // 21/2/2009, 21/8/2010, 21/2/2012, 21/8/2013, 21/2/2015 MonthlySchedule month = new MonthlySchedule { Frequency = 18 }; IList<DateTime> occurrences = Convert(month.GetOccurrences(_start, new DateTime(2008, 1, 1), new DateTime(2010, 12, 31))); Assert.AreEqual(2, occurrences.Count); Assert.AreEqual(new DateTime(2009, 2, 21), occurrences[0]); Assert.AreEqual(new DateTime(2010, 8, 21), occurrences[1]); }
public ActionResult EditMonthly(MonthlySchedule schedule, string selectedToolID, string selectedContactID, List <string> selectedDevices) { if (ModelState.IsValid) { unitOfWork.ScheduleRepository.Update(schedule); UpdateScheduleGraph(schedule, selectedToolID, selectedContactID, selectedDevices); unitOfWork.Save(); return(RedirectToAction("Index")); } return(View(schedule)); }
public ActionResult CreateMonthly(MonthlySchedule schedule) { if (ModelState.IsValid) { unitOfWork.ScheduleRepository.Insert(schedule); unitOfWork.ScheduleRepository.Save(); return(RedirectToAction("Index")); } return(View(schedule)); }
private static string zCronMonthValue(MonthlySchedule schedule) { if (schedule.MonthlyRecurrence.Count == 12) { return("*"); } else { return(DescriptionUtils.BuildDescriptiveList(schedule.MonthlyRecurrence, false, false, m => ((int)m + 1).ToString())); } }
public void Next_occurrence_before_start() { // 21/2/2009, 21/8/2010, 21/2/2012, 21/8/2013, 21/2/2015 MonthlySchedule month = new MonthlySchedule { Frequency = 18 }; DateTime?next = month.NextOccurrence(_start, new DateTime(2000, 1, 1)); Assert.IsTrue(next.HasValue); Assert.AreEqual(new DateTime(2009, 2, 21), next.Value); }
public void Once_Outside_Active_Day() { var input = new DateTime(2020, 8, 16, 19, 50, 30); var expected = new DateTime(2020, 8, 21, 19, 40, 15); var sch = new MonthlySchedule(new int[] { 21 }, new Time("19:40:15")); var actual = sch.GetNext(input); Assert.Equal(expected, actual); }
public void Once_Inside_Active_Day_After_Trigger() { var input = new DateTime(2020, 8, 16, 19, 50, 30); var expected = new DateTime(2020, 9, 3, 19, 40, 15); var sch = new MonthlySchedule(new int[] { 16, 3, 8 }, new Time("19:40:15")); var actual = sch.GetNext(input); Assert.Equal(expected, actual); }
public void Recurring_Inside_Active_Day_Default_Active_Period() { var input = new DateTime(2020, 8, 16, 9, 50, 30); var expected = new DateTime(2020, 8, 16, 10, 0, 0); var sch = new MonthlySchedule(new int[] { 16, 21 }, DailyIntervalUnit.Hour, 2, null, null); var actual = sch.GetNext(input); Assert.Equal(expected, actual); }
public void Occurrences_stress_test() { var d = new DateTime(1400, 1, 1); MonthlySchedule month = new MonthlySchedule { Frequency = 1 }; // 1/1/1900 (Monday) -> 31/12/1999 (Friday) = 36524 total days; 7 days in every 21 for 100 years; 36524 - 14 days = 36510 / 3 = 12170 IList <DateTime> occurrences = Convert(month.GetOccurrences(d, d, new DateTime(2399, 12, 31))); Assert.AreEqual(12000, occurrences.Count); }
public override string ToString() { return(string.Format("IsDailyScheduleEnabled:{0}, IsWeeklyScheduleEnabled:{1}, " + "IsMonthlyScheduleEnabled:{2}, IsYearlyScheduleEnabled:{3}" + "DailySchedule: {4}, WeeklySchedule: {5}, MonthlySchedule:{6}, YearlySchedule:{7}", IsDailyScheduleEnabled, IsWeeklyScheduleEnabled, IsMonthlyScheduleEnabled, IsYearlyScheduleEnabled, DailySchedule == null ? "NULL" : DailySchedule.ToString(), WeeklySchedule == null ? "NULL" : WeeklySchedule.ToString(), MonthlySchedule == null ? "NULL" : MonthlySchedule.ToString(), YearlySchedule == null ? "NULL" : YearlySchedule.ToString())); }
public void Occurrences_crossing_start() { // 21/2/2009, 21/8/2010, 21/2/2012, 21/8/2013, 21/2/2015 MonthlySchedule month = new MonthlySchedule { Frequency = 18 }; IList <DateTime> occurrences = Convert(month.GetOccurrences(_start, new DateTime(2008, 1, 1), new DateTime(2010, 12, 31))); Assert.AreEqual(2, occurrences.Count); Assert.AreEqual(new DateTime(2009, 2, 21), occurrences[0]); Assert.AreEqual(new DateTime(2010, 8, 21), occurrences[1]); }
public void Recurring_Outside_Active_Day_Custom_Active_Period() { var input = new DateTime(2020, 8, 16, 19, 50, 30); var expected = new DateTime(2020, 8, 21, 2, 30, 15); var sch = new MonthlySchedule(new int[] { 21 }, DailyIntervalUnit.Hour, 2, new Time(2, 30, 15), new Time(12, 30, 15)); var actual = sch.GetNext(input); Assert.Equal(expected, actual); }
public void Occurrences_day_of_month_first_with_time_component() { var month = new MonthlySchedule { Frequency = 1 }; IList <DateTime> occurrences = Convert(month.GetOccurrences( new DateTime(2011, 8, 1, 14, 30, 0), new DateTime(2011, 8, 17), new DateTime(2011, 10, 1, 11, 0, 0))); Assert.AreEqual(1, occurrences.Count); Assert.AreEqual(new DateTime(2011, 9, 1, 14, 30, 0), occurrences[0]); }
public static MonthlySchedule ConvertFromPs(this PSNetAppFilesMonthlySchedule psMonthlySchedule) { var monthlySchedule = new MonthlySchedule { Minute = psMonthlySchedule.Minute, Hour = psMonthlySchedule.Hour, DaysOfMonth = psMonthlySchedule.DaysOfMonth, SnapshotsToKeep = psMonthlySchedule.SnapshotsToKeep, UsedBytes = psMonthlySchedule.UsedBytes }; return(monthlySchedule); }
public static PSNetAppFilesMonthlySchedule ConvertToPs(this MonthlySchedule monthlySchedule) { PSNetAppFilesMonthlySchedule psNetAppFilesWeeklySchedule = new PSNetAppFilesMonthlySchedule { Minute = monthlySchedule.Minute, Hour = monthlySchedule.Hour, DaysOfMonth = monthlySchedule.DaysOfMonth, SnapshotsToKeep = monthlySchedule.SnapshotsToKeep, UsedBytes = monthlySchedule.UsedBytes }; return(psNetAppFilesWeeklySchedule); }
public void Once_Unreachable_Day() { // February 2020 has only 29 days var input = new DateTime(2020, 2, 16, 18, 30, 30); var expected = new DateTime(2020, 3, 7, 19, 40, 15); var sch = new MonthlySchedule(new int[] { 7, 31 }, new Time("19:40:15")); var actual = sch.GetNext(input); Assert.Equal(expected, actual); }
private static TriggerBuilder zCreateMonthlyTriggerBuilder(MonthlySchedule schedule, WeekdayPosition?weekdayPosition, DayOfWeek?weekDay) { string cronExpression = String.Format("{0} {1} {2} {3} {4} {5}", zCronSecondValue(schedule), zCronMinuteValue(schedule), zCronHourValue(schedule), zCronDayOfMonthValue(schedule), zCronMonthValue(schedule), zCronDayOfWeekValue(schedule, weekdayPosition, weekDay)); return(TriggerBuilder.Create() .WithCronSchedule(cronExpression, sb => sb.WithMisfireHandlingInstructionDoNothing())); }
public void Recurring_Unreachable_Day() { // February 2020 has only 29 days var input = new DateTime(2020, 2, 16, 18, 30, 30); var expected = new DateTime(2020, 3, 7, 2, 30, 15); var sch = new MonthlySchedule(new int[] { 7, 31 }, DailyIntervalUnit.Hour, 2, new Time(2, 30, 15), new Time(12, 30, 15)); var actual = sch.GetNext(input); Assert.Equal(expected, actual); }
public override void ExecuteCmdlet() { if (ParameterSetName == ResourceIdParameterSet) { var resourceIdentifier = new ResourceIdentifier(ResourceId); ResourceGroupName = resourceIdentifier.ResourceGroupName; Name = resourceIdentifier.ResourceName; } if (ParameterSetName == ParentObjectParameterSet) { ResourceGroupName = AccountObject.ResourceGroupName; Location = AccountObject.Location; var NameParts = AccountObject.Name.Split('/'); AccountName = NameParts[0]; } Management.NetApp.Models.SnapshotPolicy existingSnapshotPolicy = null; try { existingSnapshotPolicy = AzureNetAppFilesManagementClient.SnapshotPolicies.Get(ResourceGroupName, AccountName, Name); } catch { existingSnapshotPolicy = null; } if (existingSnapshotPolicy == null) { throw new AzPSResourceNotFoundCloudException($"A Snapshot Policy with name '{this.Name}' in resource group '{this.ResourceGroupName}' does not exists. Please use New-AzNetAppFilesSnapshotPolicy to create a Snapshot Policy."); } var snapshotPolicyBody = new Management.NetApp.Models.SnapshotPolicy() { Location = Location, Enabled = Enabled, HourlySchedule = (HourlySchedule != null) ? HourlySchedule.ConvertFromPs() : null, DailySchedule = (DailySchedule != null) ? DailySchedule.ConvertFromPs() : null, WeeklySchedule = (WeeklySchedule != null) ? WeeklySchedule.ConvertFromPs() : null, MonthlySchedule = (MonthlySchedule != null) ? MonthlySchedule.ConvertFromPs() : null }; if (ShouldProcess(Name, string.Format(PowerShell.Cmdlets.NetAppFiles.Properties.Resources.UpdateResourceMessage, ResourceGroupName))) { var anfSnapshotPolicy = AzureNetAppFilesManagementClient.SnapshotPolicies.Create(snapshotPolicyBody, ResourceGroupName, AccountName, snapshotPolicyName: Name); WriteObject(anfSnapshotPolicy.ConvertToPs()); } }
private static string zCronDayOfMonthValue(MonthlySchedule schedule) { if (schedule.MonthlyRecurrenceType == MonthlyRecurrenceType.OrdinalDays) { if ((schedule.OrdinalDays.Count == 31 && !schedule.OrdinalDays.Contains(-1)) || schedule.OrdinalDays.Count == 32) { return("*"); } else { //The documentation says that using L with a list could cause unexpected results. If this doesn't work, find other way to do this. return(DescriptionUtils.BuildDescriptiveList(schedule.OrdinalDays, false, false, od => od > -1 ? ((int)od + 1).ToString() : "L")); } } else { return("?"); } }
public void TestDayOfWeek() { //Arrange MonthlySchedule itemMon = new MonthlySchedule { MonthlyTheNDayOfWeek = DayOfWeek.Monday }; MonthlySchedule itemTue = new MonthlySchedule { MonthlyTheNDayOfWeek = DayOfWeek.Tuesday }; MonthlySchedule itemWed = new MonthlySchedule { MonthlyTheNDayOfWeek = DayOfWeek.Wednesday }; MonthlySchedule itemThu = new MonthlySchedule { MonthlyTheNDayOfWeek = DayOfWeek.Thursday }; MonthlySchedule itemFri = new MonthlySchedule { MonthlyTheNDayOfWeek = DayOfWeek.Friday }; MonthlySchedule itemSat = new MonthlySchedule { MonthlyTheNDayOfWeek = DayOfWeek.Saturday }; MonthlySchedule itemSun = new MonthlySchedule { MonthlyTheNDayOfWeek = DayOfWeek.Sunday }; //Act //Assert Assert.AreEqual(itemMon.GetMonthlyTheNDayOfWeekText(), "Monday"); Assert.AreEqual(itemTue.GetMonthlyTheNDayOfWeekText(), "Tuesday"); Assert.AreEqual(itemWed.GetMonthlyTheNDayOfWeekText(), "Wednesday"); Assert.AreEqual(itemThu.GetMonthlyTheNDayOfWeekText(), "Thursday"); Assert.AreEqual(itemFri.GetMonthlyTheNDayOfWeekText(), "Friday"); Assert.AreEqual(itemSat.GetMonthlyTheNDayOfWeekText(), "Saturday"); Assert.AreEqual(itemSun.GetMonthlyTheNDayOfWeekText(), "Sunday"); }
private static SnapshotPolicy CreatePolicy(string location, string name = "") { // Create basic policy records with a selection of data HourlySchedule HourlySchedule = new HourlySchedule { SnapshotsToKeep = 2, Minute = 50 }; DailySchedule DailySchedule = new DailySchedule { SnapshotsToKeep = 4, Hour = 14, Minute = 30 }; WeeklySchedule WeeklySchedule = new WeeklySchedule { SnapshotsToKeep = 3, Day = "Wednesday", Hour = 14, Minute = 45 }; MonthlySchedule MonthlySchedule = new MonthlySchedule { SnapshotsToKeep = 5, DaysOfMonth = "10,11,12", Hour = 14, Minute = 15 }; SnapshotPolicy testSnapshotPolicy = new SnapshotPolicy(location: location, name: name) { Enabled = true, HourlySchedule = HourlySchedule, DailySchedule = DailySchedule, WeeklySchedule = WeeklySchedule, MonthlySchedule = MonthlySchedule }; return(testSnapshotPolicy); }
/// <summary> /// Gets the generated description for the schedule. Will not update Description or fire events. /// </summary> public virtual string Format(MonthlySchedule s) { // Monthly on day 21 // Every 6 months on day 21 var sb = new StringBuilder(); if (s.Frequency == 1) sb.Append("Monthly"); else sb.AppendFormat("Every {0} months", s.Frequency); if (Start.HasValue) sb.AppendFormat(" on day {0}", Start.Value.Day); return sb.ToString(); //(EndDate.HasValue ? String.Format(", ending {0}", EndDate.Value.ToString("d MMMM yyyy")) : "")); }
/// <summary> /// Visitor pattern for generating description for this schedule. Will update Description and fire events. /// </summary> public virtual void Visit(MonthlySchedule s) { OnDescriptionChanged(s, Format(s)); }
public void Occurrences_day_of_month_first_with_time_component() { var month = new MonthlySchedule { Frequency = 1 }; IList<DateTime> occurrences = Convert(month.GetOccurrences( new DateTime(2011, 8, 1, 14, 30, 0), new DateTime(2011, 8, 17), new DateTime(2011, 10, 1, 11, 0, 0))); Assert.AreEqual(1, occurrences.Count); Assert.AreEqual(new DateTime(2011, 9, 1, 14, 30, 0), occurrences[0]); }