Skip to content

Commit 62d9a8b

Browse files
committed
Merge pull request #55 from MabOneSdk/pragrawa
Policy changes
2 parents 0f5eae4 + 4b95e06 commit 62d9a8b

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class NewAzureBackupProtectionPolicy : AzureBackupVaultCmdletBase
5555
public DateTime ScheduleRunTimes { get; set; }
5656

5757
[Parameter(Position = 9, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RetentionType, ValueFromPipelineByPropertyName = true)]
58-
[ValidateSet("Days", IgnoreCase = true)]
58+
[ValidateSet("Days", "Weeks", IgnoreCase = true)]
5959
public string RetentionType { get; set; }
6060

6161
[Parameter(Position = 10, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RententionDuration, ValueFromPipelineByPropertyName = true)]

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class SetAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase
5252
public DateTime ScheduleRunTimes { get; set; }
5353

5454
[Parameter(Position = 6, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RetentionType)]
55-
[ValidateSet("Days", IgnoreCase = true)]
55+
[ValidateSet("Days", "Weeks", IgnoreCase = true)]
5656
public string RetentionType { get; set; }
5757

5858
[Parameter(Position = 7, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RententionDuration)]

src/ResourceManager/AzureBackup/Commands.AzureBackup/Helpers/ProtectionPolicyHelpers.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,14 @@ private static void ValidateRetentionRange(string retentionType, int retentionDu
107107
if(retentionType == RetentionDurationType.Days.ToString() && (retentionDuration < MinRetentionInDays
108108
|| retentionDuration > MaxRetentionInDays))
109109
{
110-
var exception = new Exception("For Retention in days , valid values of retention duration are 7 to 30.");
111-
//var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null);
112-
//azureBackupCmdletBase.WriteError(errorRecord);
110+
var exception = new ArgumentException("For Retention in days , valid values of retention duration are 7 to 30.");
113111
throw exception;
114112
}
115113

116114
if (retentionType == RetentionDurationType.Weeks.ToString() && (retentionDuration < MinRetentionInWeeks
117115
|| retentionDuration > MaxRetentionInWeeks))
118116
{
119-
var exception = new Exception("For Retention in weeks , valid values of retention duration are 1 to 4.");
120-
//var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null);
121-
//azureBackupCmdletBase.WriteError(errorRecord);
117+
var exception = new ArgumentException("For Retention in weeks , valid values of retention duration are 1 to 4.");
122118
throw exception;
123119
}
124120

@@ -141,19 +137,15 @@ private static IList<DayOfWeek> ParseScheduleRunDays(string[] scheduleRunDays)
141137
{
142138
if (scheduleRunDays == null || scheduleRunDays.Length <= 0)
143139
{
144-
var exception = new Exception("For weekly scheduletype , ScheduleRunDays should not be empty.");
145-
//var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null);
146-
//azureBackupCmdletBase.WriteError(errorRecord);
140+
var exception = new ArgumentException("For weekly scheduletype , ScheduleRunDays should not be empty.");
147141
throw exception;
148142
}
149143

150144
IList<DayOfWeek> ListofWeekDays = new List<DayOfWeek>();
151145

152146
foreach (var dayOfWeek in scheduleRunDays)
153147
{
154-
//azureBackupCmdletBase.WriteDebug("dayOfWeek" + dayOfWeek.ToString());
155148
DayOfWeek item = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), dayOfWeek, true);
156-
//azureBackupCmdletBase.WriteDebug("Item" + item.ToString());
157149
if (!ListofWeekDays.Contains(item))
158150
{
159151
ListofWeekDays.Add(item);
@@ -165,7 +157,10 @@ private static IList<DayOfWeek> ParseScheduleRunDays(string[] scheduleRunDays)
165157

166158
private static DateTime ParseScheduleRunTime(DateTime scheduleStartTime)
167159
{
168-
scheduleStartTime = scheduleStartTime.ToUniversalTime();
160+
if (scheduleStartTime.Kind == DateTimeKind.Local)
161+
{
162+
scheduleStartTime = scheduleStartTime.ToUniversalTime();
163+
}
169164
DateTime scheduleRunTime = new DateTime(scheduleStartTime.Year, scheduleStartTime.Month,
170165
scheduleStartTime.Day, scheduleStartTime.Hour, scheduleStartTime.Minute - (scheduleStartTime.Minute % 30), 0);
171166
return scheduleRunTime;

0 commit comments

Comments
 (0)