Skip to content

Commit 2552673

Browse files
committed
Corrected error messages for policy objects
1 parent 67ed99c commit 2552673

File tree

4 files changed

+121
-40
lines changed

4 files changed

+121
-40
lines changed

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CommonModels/PolicyRetentionObjects.cs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public override void Validate()
207207
{
208208
if (RetentionScheduleDaily == null)
209209
{
210-
throw new ArgumentException("RetentionScheduleDaily is set to NULL");
210+
throw new ArgumentException(Resources.MonthlyYearlyRetentionDailySchedulePolicyNULLException);
211211
}
212212

213213
RetentionScheduleDaily.Validate();
@@ -217,7 +217,7 @@ public override void Validate()
217217
{
218218
if (RetentionScheduleWeekly == null)
219219
{
220-
throw new ArgumentException("RetentionScheduleWeekly is set to NULL");
220+
throw new ArgumentException(Resources.MonthlyYearlyRetentionWeeklySchedulePolicyNULLException);
221221
}
222222

223223
RetentionScheduleWeekly.Validate();
@@ -268,7 +268,7 @@ public override void Validate()
268268
{
269269
if (RetentionScheduleDaily == null)
270270
{
271-
throw new ArgumentException("RetentionScheduleDaily is set to NULL");
271+
throw new ArgumentException(Resources.MonthlyYearlyRetentionDailySchedulePolicyNULLException);
272272
}
273273

274274
RetentionScheduleDaily.Validate();
@@ -278,7 +278,7 @@ public override void Validate()
278278
{
279279
if (RetentionScheduleWeekly == null)
280280
{
281-
throw new ArgumentException("RetentionScheduleWeekly is set to NULL");
281+
throw new ArgumentException(Resources.MonthlyYearlyRetentionWeeklySchedulePolicyNULLException);
282282
}
283283

284284
RetentionScheduleWeekly.Validate();
@@ -305,14 +305,14 @@ public void Validate()
305305
{
306306
if (DaysOfTheMonth == null || DaysOfTheMonth.Count == 0)
307307
{
308-
throw new ArgumentException("DaysOfTheMonth is set to NULL/Empty");
308+
throw new ArgumentException(Resources.InvalidDaysOfMonthInMonthlyYearlyRetentionPolicyException);
309309
}
310310

311311
// check if all the days are unique or not
312312
List<Day> distinctDays = DaysOfTheMonth.GroupBy(x => new { x.Date, x.IsLast }).Select(g => g.First()).ToList();
313313
if (DaysOfTheMonth.Count != distinctDays.Count)
314314
{
315-
throw new ArgumentException("DaysOfTheMonth list in DailyRetentionFormat contains duplicate entries");
315+
throw new ArgumentException(Resources.InvalidDaysOfMonthInMonthlyYearlyRetentionPolicyException);
316316
}
317317

318318
// also check if there exists more than one 'IsLast=true'
@@ -328,7 +328,7 @@ public void Validate()
328328

329329
if(countOfIsLast > 1)
330330
{
331-
throw new ArgumentException("Only ONE day can have IsLast=true in DaysOfTheMonth list");
331+
throw new ArgumentException(Resources.InvalidDayInDaysOfMonthOfMonthlyYearlyRetentionPolicyException);
332332
}
333333
}
334334

@@ -346,25 +346,17 @@ public class WeeklyRetentionFormat
346346

347347
public void Validate()
348348
{
349-
if (DaysOfTheWeek == null || DaysOfTheWeek.Count == 0)
349+
if (DaysOfTheWeek == null || DaysOfTheWeek.Count == 0 ||
350+
DaysOfTheWeek.Count != DaysOfTheWeek.Distinct().Count())
350351
{
351-
throw new ArgumentException("DaysOfTheWeek is set to NULL/Empty");
352+
throw new ArgumentException(Resources.InvalidDaysOfWeekInMonthlyYearlyRetentionPolicyException);
352353
}
353354

354-
if (WeeksOfTheMonth == null || WeeksOfTheMonth.Count == 0)
355+
if (WeeksOfTheMonth == null || WeeksOfTheMonth.Count == 0 ||
356+
WeeksOfTheMonth.Count != WeeksOfTheMonth.Distinct().Count())
355357
{
356-
throw new ArgumentException("WeeksOfTheMonth is set to NULL/Empty");
357-
}
358-
359-
if (DaysOfTheWeek.Count != DaysOfTheWeek.Distinct().Count())
360-
{
361-
throw new ArgumentException("DaysOfTheWeek list in WeeklyRetentionFormat contains duplicate entries");
362-
}
363-
364-
if (WeeksOfTheMonth.Count != WeeksOfTheMonth.Distinct().Count())
365-
{
366-
throw new ArgumentException("WeeksOfTheMonth list in WeeklyRetentionFormat contains duplicate entries");
367-
}
358+
throw new ArgumentException(Resources.InvalidWeeksOfMonthInMonthlyYearlyRetentionPolicyException);
359+
}
368360
}
369361

370362
public override string ToString()
@@ -390,8 +382,7 @@ public void Validate()
390382
{
391383
if (IsLast == false && (Date <= 0 || Date > PolicyConstants.MaxAllowedDateInMonth))
392384
{
393-
throw new ArgumentException("Days in DaysOfTheMonth should have IsLast = true or date should be 1-" +
394-
PolicyConstants.MaxAllowedDateInMonth);
385+
throw new ArgumentException(Resources.InvalidDayInDaysOfMonthOfMonthlyYearlyRetentionPolicyException);
395386
}
396387
}
397388

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CommonModels/PolicyScheduleObjects.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Text;
1818
using System.Threading.Tasks;
1919
using System.Collections.Generic;
20+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
2021

2122
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
2223
{
@@ -31,29 +32,22 @@ public class AzureRmRecoveryServicesSimpleSchedulePolicy : AzureRmRecoveryServic
3132
public override void Validate()
3233
{
3334
//Currently only one scheduled run time is allowed
34-
if (ScheduleRunTimes == null || ScheduleRunTimes.Count != 1)
35-
{
36-
throw new ArgumentException("", "ScheduleRunTimes");
37-
}
38-
3935
//Validate that the schedule runtime is in multiples of 30 Mins
40-
if (ScheduleRunTimes[0].Minute % 30 != 0 || ScheduleRunTimes[0].Second != 0 || ScheduleRunTimes[0].Millisecond != 0)
36+
if (ScheduleRunTimes == null || ScheduleRunTimes.Count != 1 ||
37+
ScheduleRunTimes[0].Minute % 30 != 0 ||
38+
ScheduleRunTimes[0].Second != 0 ||
39+
ScheduleRunTimes[0].Millisecond != 0)
4140
{
42-
throw new ArgumentException("ScheduleTimes must be of multiples of 30 Mins with Seconds " +
43-
"and milliseconds set to 0");
41+
throw new ArgumentException(Resources.InvalidScheduleTimeInScheduleException);
4442
}
4543

4644
if (ScheduleRunFrequency == ScheduleRunType.Weekly)
4745
{
48-
if (ScheduleRunDays == null || ScheduleRunDays.Count == 0)
49-
{
50-
throw new ArgumentException("", "scheduleRunDays");
51-
}
52-
53-
if (ScheduleRunDays.Count != ScheduleRunDays.Distinct().Count())
46+
if (ScheduleRunDays == null || ScheduleRunDays.Count == 0 ||
47+
ScheduleRunDays.Count != ScheduleRunDays.Distinct().Count())
5448
{
55-
throw new ArgumentException("ScheduleRunDays list in BackupSchedule contains duplicate entries");
56-
}
49+
throw new ArgumentException(Resources.InvalidScheduleRunDaysInScheduleException);
50+
}
5751
}
5852
}
5953

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.Designer.cs

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.resx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,28 @@
237237
<data name="YearlyScheduleMonthsOfYearException" xml:space="preserve">
238238
<value>MonthsOfYear list in YearlyRetentionSchedule should not be NULL and not contain duplicate entires</value>
239239
</data>
240+
<data name="InvalidDayInDaysOfMonthOfMonthlyYearlyRetentionPolicyException" xml:space="preserve">
241+
<value>In Monthly/Yearly retention schedule, Day in DaysOfMonth should be 1-28 (or) IsLast=true set for one day only</value>
242+
</data>
243+
<data name="InvalidDaysOfMonthInMonthlyYearlyRetentionPolicyException" xml:space="preserve">
244+
<value>In Monthly/Yearly retention schedule, DaysOfMonth is NULL or empty or contains duplicate entires</value>
245+
</data>
246+
<data name="InvalidDaysOfWeekInMonthlyYearlyRetentionPolicyException" xml:space="preserve">
247+
<value>In Monthly/Yearly retention schedule, DaysOfWeek is NULL or empty or contains duplicate entires</value>
248+
</data>
249+
<data name="InvalidScheduleRunDaysInScheduleException" xml:space="preserve">
250+
<value>In Schedule, if ScheduleRunFrequency is Weekly then ScheduleRunDays should not be empty and not contain duplicate entries</value>
251+
</data>
252+
<data name="InvalidScheduleTimeInScheduleException" xml:space="preserve">
253+
<value>ScheduleTimes in Schedule should have ONE time and must be of multiples of 30 Mins with seconds and milliseconds set to 0</value>
254+
</data>
255+
<data name="InvalidWeeksOfMonthInMonthlyYearlyRetentionPolicyException" xml:space="preserve">
256+
<value>In Monthly/Yearly retention schedule, WeeksOfMonth is NULL or empty or contains duplicate entires</value>
257+
</data>
258+
<data name="MonthlyYearlyRetentionDailySchedulePolicyNULLException" xml:space="preserve">
259+
<value>In Monthly/Yearly retention schedule, if RetentionScheduleFormatType=Daily then RetentionScheduleDaily should NOT be null</value>
260+
</data>
261+
<data name="MonthlyYearlyRetentionWeeklySchedulePolicyNULLException" xml:space="preserve">
262+
<value>In Monthly/Yearly retention schedule, if RetentionScheduleFormatType=Weekly then RetentionScheduleWeekly should NOT be null</value>
263+
</data>
240264
</root>

0 commit comments

Comments
 (0)