Skip to content

Commit bbc9e13

Browse files
committed
Merge pull request #21 from jemex/dev
CalendarSchedule-Adding Property bag for Monthly and WeeklySchedule Option Response
2 parents 8278025 + b6232b7 commit bbc9e13

File tree

6 files changed

+164
-50
lines changed

6 files changed

+164
-50
lines changed

src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationSchedule.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Security.Permissions;
2020
using Microsoft.Azure.Commands.Automation.Common;
2121
using Microsoft.Azure.Commands.Automation.Model;
22+
using DayOfWeek = Microsoft.Azure.Commands.Automation.Model.DayOfWeek;
2223

2324
namespace Microsoft.Azure.Commands.Automation.Cmdlet
2425
{
@@ -63,7 +64,7 @@ public NewAzureAutomationSchedule()
6364
/// Gets or sets the schedule days of the week.
6465
/// </summary>
6566
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByWeekly, Mandatory = false, HelpMessage = "The list of days of week for the weekly schedule.")]
66-
public DayOfWeek[] DaysOfWeek { get; set; }
67+
public System.DayOfWeek[] DaysOfWeek { get; set; }
6768

6869
/// <summary>
6970
/// Gets or sets the schedule days of the month.
@@ -75,7 +76,7 @@ public NewAzureAutomationSchedule()
7576
/// Gets or sets the schedule day of the week.
7677
/// </summary>
7778
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByMonthlyDayOfWeek, Mandatory = false, HelpMessage = "The day of week for the monthly occurrence.")]
78-
public DayOfWeek? DayOfWeek { get; set; }
79+
public System.DayOfWeek? DayOfWeek { get; set; }
7980

8081
/// <summary>
8182
/// Gets or sets the schedule day of the week.
@@ -202,14 +203,35 @@ private Schedule CreateMonthlyScheduleModel()
202203
ExpiryTime = this.ExpiryTime,
203204
Frequency = ScheduleFrequency.Month,
204205
Interval = this.MonthInterval,
205-
DaysOfMonth = this.DaysOfMonth,
206-
DayOfWeekMonthlySchedule = dayOfWeek,
207-
DayOfWeekOccurrence = this.DayOfWeekOccurrence == 0 ? null : this.DayOfWeekOccurrence.ToString()
206+
MonthlyScheduleOptions = this.IsMonthlyScheduleNull()
207+
? null
208+
: new MonthlyScheduleOptions()
209+
{
210+
DaysOfMonth = this.DaysOfMonth,
211+
DayOfWeek = this.DayOfWeek == null && this.DayOfWeekOccurrence == 0
212+
? null
213+
: new DayOfWeek()
214+
{
215+
Day = dayOfWeek,
216+
Occurrence = this.DayOfWeekOccurrence == 0 ? null : this.DayOfWeekOccurrence.ToString()
217+
}
218+
}
208219
};
209220

210221
return newSchedule;
211222
}
212223

224+
/// <summary>
225+
/// The is monthly schedule null.
226+
/// </summary>
227+
/// <returns>
228+
/// The <see cref="bool"/>.
229+
/// </returns>
230+
private bool IsMonthlyScheduleNull()
231+
{
232+
return this.DaysOfMonth == null && this.DayOfWeek == null && this.DayOfWeekOccurrence == 0;
233+
}
234+
213235
/// <summary>
214236
/// The create weekly schedule model.
215237
/// </summary>
@@ -226,9 +248,12 @@ private Schedule CreateWeeklyScheduleModel()
226248
ExpiryTime = this.ExpiryTime,
227249
Frequency = ScheduleFrequency.Week,
228250
Interval = this.WeekInterval,
229-
DaysOfWeekWeeklySchedule = this.DaysOfWeek == null
251+
WeeklyScheduleOptions = this.DaysOfWeek == null
230252
? null
231-
: this.DaysOfWeek.Select(day => day.ToString()).ToList()
253+
: new WeeklyScheduleOptions()
254+
{
255+
DaysOfWeek = this.DaysOfWeek.Select(day => day.ToString()).ToList()
256+
}
232257
};
233258

234259
return newSchedule;

src/ResourceManager/Automation/Commands.Automation/Commands.Automation.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@
225225
<Compile Include="Model\ConfigurationContent.cs" />
226226
<Compile Include="Model\Connection.cs" />
227227
<Compile Include="Model\CredentialInfo.cs" />
228+
<Compile Include="Model\DayOfWeek.cs" />
228229
<Compile Include="Model\DscNode.cs" />
229230
<Compile Include="Model\DscNodeReport.cs" />
230231
<Compile Include="Model\DscOnboardingMetaconfig.cs" />
@@ -233,13 +234,15 @@
233234
<Compile Include="Model\JobStreamRecord.cs" />
234235
<Compile Include="Model\JobStream.cs" />
235236
<Compile Include="Model\Module.cs" />
237+
<Compile Include="Model\MonthlyScheduleOptions.cs" />
236238
<Compile Include="Model\NodeConfiguration.cs" />
237239
<Compile Include="Model\BaseProperties.cs" />
238240
<Compile Include="Model\Runbook.cs" />
239241
<Compile Include="Model\Schedule.cs" />
240242
<Compile Include="Model\ScheduleFrequency.cs" />
241243
<Compile Include="Model\Variable.cs" />
242244
<Compile Include="Model\Webhook.cs" />
245+
<Compile Include="Model\WeeklyScheduleOptions.cs" />
243246
<Compile Include="Properties\AssemblyInfo.cs" />
244247
<Compile Include="Properties\Resources.Designer.cs">
245248
<AutoGen>True</AutoGen>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.Azure.Commands.Automation.Model
8+
{
9+
public class DayOfWeek
10+
{
11+
/// <summary>
12+
/// Gets or sets the schedule day of the week occurrence.
13+
/// </summary>
14+
public string Occurrence { get; set; }
15+
16+
/// <summary>
17+
/// Gets or sets the schedule day of the week.
18+
/// </summary>
19+
public string Day { get; set; }
20+
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.Commands.Automation.Cmdlet;
7+
8+
namespace Microsoft.Azure.Commands.Automation.Model
9+
{
10+
public class MonthlyScheduleOptions
11+
{
12+
/// <summary>
13+
/// Gets or sets the schedule days of the month.
14+
/// </summary>
15+
public IList<DaysOfMonth> DaysOfMonth { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the day of week.
19+
/// </summary>
20+
public DayOfWeek DayOfWeek { get; set; }
21+
}
22+
}

src/ResourceManager/Automation/Commands.Automation/Model/Schedule.cs

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.Azure.Commands.Automation.Model
8+
{
9+
public class WeeklyScheduleOptions
10+
{
11+
/// <summary>
12+
/// Gets or sets the schedule days of the week.
13+
/// </summary>
14+
public IList<string> DaysOfWeek { get; set; }
15+
}
16+
}

0 commit comments

Comments
 (0)