@@ -57,18 +57,8 @@ public Schedule(string resourceGroupName, string automationAccountName, Azure.Ma
5757 this . NextRun = AdjustOffset ( schedule . Properties . NextRun , schedule . Properties . NextRunOffsetMinutes ) ;
5858 this . Interval = schedule . Properties . Interval ?? this . Interval ;
5959 this . Frequency = ( ScheduleFrequency ) Enum . Parse ( typeof ( ScheduleFrequency ) , schedule . Properties . Frequency , true ) ;
60- this . DaysOfWeekWeeklySchedule = schedule . Properties . AdvancedSchedule == null
61- ? null
62- : schedule . Properties . AdvancedSchedule . WeekDays ;
63- this . DaysOfMonth = schedule . Properties . AdvancedSchedule == null
64- ? null
65- : this . GetDaysOfMonth ( schedule . Properties . AdvancedSchedule . MonthDays ) ;
66- this . DayOfWeekMonthlySchedule = this . IsMonthlyOccurrenceNull ( schedule . Properties . AdvancedSchedule )
67- ? null
68- : schedule . Properties . AdvancedSchedule . MonthlyOccurrences . First ( ) . Day ;
69- this . DayOfWeekOccurrence = this . IsMonthlyOccurrenceNull ( schedule . Properties . AdvancedSchedule )
70- ? null
71- : this . GetDayOfWeekOccurrence ( schedule . Properties . AdvancedSchedule . MonthlyOccurrences . First ( ) . Occurrence ) ;
60+ this . WeeklyScheduleOptions = this . CreateWeeklyScheduleOptions ( schedule ) ;
61+ this . MonthlyScheduleOptions = this . CreateMonthlyScheduleOptions ( schedule ) ;
7262 this . TimeZone = schedule . Properties . TimeZone ;
7363 }
7464
@@ -112,24 +102,14 @@ public Schedule()
112102 public ScheduleFrequency Frequency { get ; set ; }
113103
114104 /// <summary>
115- /// Gets or sets the schedule days of the week.
116- /// </summary>
117- public IList < string > DaysOfWeekWeeklySchedule { get ; set ; }
118-
119- /// <summary>
120- /// Gets or sets the schedule days of the month.
105+ /// Gets or sets the monthly schedule options.
121106 /// </summary>
122- public IList < DaysOfMonth > DaysOfMonth { get ; set ; }
107+ public MonthlyScheduleOptions MonthlyScheduleOptions { get ; set ; }
123108
124109 /// <summary>
125- /// Gets or sets the schedule day of the week .
110+ /// Gets or sets the weekly schedule options .
126111 /// </summary>
127- public string DayOfWeekMonthlySchedule { get ; set ; }
128-
129- /// <summary>
130- /// Gets or sets the schedule day of the week occurrence.
131- /// </summary>
132- public string DayOfWeekOccurrence { get ; set ; }
112+ public WeeklyScheduleOptions WeeklyScheduleOptions { get ; set ; }
133113
134114 /// <summary>
135115 /// The create advanced schedule.
@@ -146,23 +126,32 @@ public AdvancedSchedule GetAdvancedSchedule()
146126
147127 var advancedSchedule = new AdvancedSchedule ( )
148128 {
149- WeekDays = this . DaysOfWeekWeeklySchedule ,
150- MonthDays = this . DaysOfMonth == null ? null : this . DaysOfMonth . Select ( v => Convert . ToInt32 ( v ) ) . ToList ( ) ,
151- MonthlyOccurrences = string . IsNullOrWhiteSpace ( this . DayOfWeekMonthlySchedule ) && this . DayOfWeekOccurrence == null
129+ WeekDays = this . WeeklyScheduleOptions == null ? null : this . WeeklyScheduleOptions . DaysOfWeek ,
130+ MonthDays = ( this . MonthlyScheduleOptions == null || this . MonthlyScheduleOptions . DaysOfMonth == null ) ? null : this . MonthlyScheduleOptions . DaysOfMonth . Select ( v => Convert . ToInt32 ( v ) ) . ToList ( ) ,
131+ MonthlyOccurrences = ( this . MonthlyScheduleOptions == null || this . MonthlyScheduleOptions . DayOfWeek == null )
152132 ? null
153133 : new AdvancedScheduleMonthlyOccurrence [ ]
154134 {
155135 new AdvancedScheduleMonthlyOccurrence ( )
156136 {
157- Day = this . DayOfWeekMonthlySchedule ,
158- Occurrence = this . GetDayOfWeekOccurrence ( this . DayOfWeekOccurrence )
137+ Day = this . MonthlyScheduleOptions . DayOfWeek . Day ,
138+ Occurrence = this . GetDayOfWeekOccurrence ( this . MonthlyScheduleOptions . DayOfWeek . Occurrence )
159139 }
160140 }
161141 } ;
162142
163143 return advancedSchedule ;
164144 }
165145
146+ /// <summary>
147+ /// Gets or sets the schedule time zone.
148+ /// </summary>
149+ public string TimeZone { get ; set ; }
150+
151+ #endregion Public Properties
152+
153+ #region Private Methods
154+
166155 /// <summary>
167156 /// The is null or empty list.
168157 /// </summary>
@@ -204,10 +193,8 @@ private bool IsMonthlyOccurrenceNull(Azure.Management.Automation.Models.Advanced
204193 /// </returns>
205194 private bool AdvancedScheduleIsNull ( Schedule schedule )
206195 {
207- return ( schedule . DaysOfWeekWeeklySchedule == null
208- && schedule . DaysOfMonth == null
209- && string . IsNullOrWhiteSpace ( schedule . DayOfWeekMonthlySchedule )
210- && schedule . DayOfWeekOccurrence == null ) ;
196+ return schedule . WeeklyScheduleOptions == null
197+ && schedule . MonthlyScheduleOptions == null ;
211198 }
212199
213200 /// <summary>
@@ -229,6 +216,53 @@ private bool AdvancedScheduleIsNull(Schedule schedule)
229216 return Convert . ToInt32 ( Enum . Parse ( typeof ( DayOfWeekOccurrence ) , dayOfWeekOccurrence ) ) ;
230217 }
231218
219+ /// <summary>
220+ /// The create weekly schedule options.
221+ /// </summary>
222+ /// <param name="schedule">
223+ /// The schedule.
224+ /// </param>
225+ /// <returns>
226+ /// The <see cref="WeeklyScheduleOptions"/>.
227+ /// </returns>
228+ private WeeklyScheduleOptions CreateWeeklyScheduleOptions ( Microsoft . Azure . Management . Automation . Models . Schedule schedule )
229+ {
230+ return schedule . Properties . AdvancedSchedule == null
231+ ? null
232+ : new WeeklyScheduleOptions ( )
233+ {
234+ DaysOfWeek = schedule . Properties . AdvancedSchedule . WeekDays
235+ } ;
236+ }
237+
238+ /// <summary>
239+ /// The create monthly schedule options.
240+ /// </summary>
241+ /// <param name="schedule">
242+ /// The schedule.
243+ /// </param>
244+ /// <returns>
245+ /// The <see cref="MonthlyScheduleOptions"/>.
246+ /// </returns>
247+ private MonthlyScheduleOptions CreateMonthlyScheduleOptions (
248+ Microsoft . Azure . Management . Automation . Models . Schedule schedule )
249+ {
250+ return schedule . Properties . AdvancedSchedule == null
251+ || ( schedule . Properties . AdvancedSchedule . MonthDays == null && schedule . Properties . AdvancedSchedule . MonthlyOccurrences == null )
252+ ? null
253+ : new MonthlyScheduleOptions ( )
254+ {
255+ DaysOfMonth = this . GetDaysOfMonth ( schedule . Properties . AdvancedSchedule . MonthDays ) ,
256+ DayOfWeek = this . IsMonthlyOccurrenceNull ( schedule . Properties . AdvancedSchedule )
257+ ? null
258+ : new DayOfWeek ( )
259+ {
260+ Day = schedule . Properties . AdvancedSchedule . MonthlyOccurrences . First ( ) . Day ,
261+ Occurrence = this . GetDayOfWeekOccurrence ( schedule . Properties . AdvancedSchedule . MonthlyOccurrences . First ( ) . Occurrence )
262+ }
263+ } ;
264+ }
265+
232266 /// <summary>
233267 /// The get day of week occurrence.
234268 /// </summary>
@@ -258,14 +292,6 @@ private IList<DaysOfMonth> GetDaysOfMonth(IList<int> daysOfMonth)
258292 {
259293 return daysOfMonth . Select ( value => ( DaysOfMonth ) value ) . ToList ( ) ;
260294 }
261- /// <summary>
262- /// Gets or sets the schedule time zone.
263- /// </summary>
264- public string TimeZone { get ; set ; }
265-
266- #endregion Public Properties
267-
268- #region Private Methods
269295
270296 private static DateTimeOffset ? AdjustOffset ( DateTimeOffset ? dateTimeOffset , double offsetMinutes )
271297 {
0 commit comments