@@ -245,7 +245,7 @@ public List<AzureRmRecoveryServicesJobBase> ModifyPolicy()
245
245
{
246
246
// poll for AsyncHeader and get the jobsList
247
247
// TBD
248
- }
248
+ }
249
249
else
250
250
{
251
251
// no datasources attached to policy
@@ -297,6 +297,103 @@ public void DeletePolicy()
297
297
throw new NotImplementedException ( ) ;
298
298
}
299
299
300
+
301
+ public AzureRmRecoveryServicesSchedulePolicyBase GetDefaultSchedulePolicyObject ( )
302
+ {
303
+ AzureRmRecoveryServicesSimpleSchedulePolicy defaultSchedule = new AzureRmRecoveryServicesSimpleSchedulePolicy ( ) ;
304
+ //Default is daily scedule at 10:30 AM local time
305
+ defaultSchedule . ScheduleRunFrequency = ScheduleRunType . Daily ;
306
+
307
+ DateTime scheduleTime = GenerateRandomTime ( ) ;
308
+ defaultSchedule . ScheduleRunTimes = new List < DateTime > ( ) ;
309
+ defaultSchedule . ScheduleRunTimes . Add ( scheduleTime ) ;
310
+
311
+ defaultSchedule . ScheduleRunDays = new List < DayOfWeek > ( ) ;
312
+ defaultSchedule . ScheduleRunDays . Add ( DayOfWeek . Sunday ) ;
313
+
314
+ return defaultSchedule ;
315
+ }
316
+
317
+ public AzureRmRecoveryServicesRetentionPolicyBase GetDefaultRetentionPolicyObject ( )
318
+ {
319
+ AzureRmRecoveryServicesLongTermRetentionPolicy defaultRetention = new AzureRmRecoveryServicesLongTermRetentionPolicy ( ) ;
320
+
321
+ //Default time is 10:30 local time
322
+ DateTime retentionTime = GenerateRandomTime ( ) ;
323
+
324
+ //Daily Retention policy
325
+ defaultRetention . IsDailyScheduleEnabled = true ;
326
+ defaultRetention . DailySchedule = new Models . DailyRetentionSchedule ( ) ;
327
+ defaultRetention . DailySchedule . RetentionTimes = new List < DateTime > ( ) ;
328
+ defaultRetention . DailySchedule . RetentionTimes . Add ( retentionTime ) ;
329
+ defaultRetention . DailySchedule . DurationCountInDays = 180 ; //TBD make it const
330
+
331
+ //Weekly Retention policy
332
+ defaultRetention . IsWeeklyScheduleEnabled = true ;
333
+ defaultRetention . WeeklySchedule = new Models . WeeklyRetentionSchedule ( ) ;
334
+ defaultRetention . WeeklySchedule . DaysOfTheWeek = new List < DayOfWeek > ( ) ;
335
+ defaultRetention . WeeklySchedule . DaysOfTheWeek . Add ( DayOfWeek . Sunday ) ;
336
+ defaultRetention . WeeklySchedule . DurationCountInWeeks = 104 ; //TBD make it const
337
+ defaultRetention . WeeklySchedule . RetentionTimes = new List < DateTime > ( ) ;
338
+ defaultRetention . WeeklySchedule . RetentionTimes . Add ( retentionTime ) ;
339
+
340
+ //Monthly retention policy
341
+ defaultRetention . IsMonthlyScheduleEnabled = true ;
342
+ defaultRetention . MonthlySchedule = new Models . MonthlyRetentionSchedule ( ) ;
343
+ defaultRetention . MonthlySchedule . DurationCountInMonths = 60 ; //tbd: make it const
344
+ defaultRetention . MonthlySchedule . RetentionScheduleFormatType = Models . RetentionScheduleFormat . Weekly ;
345
+
346
+ //Initialize day based schedule
347
+ defaultRetention . MonthlySchedule . RetentionScheduleDaily = GetDailyRetentionFormat ( ) ;
348
+
349
+ //Initialize Week based schedule
350
+ defaultRetention . MonthlySchedule . RetentionScheduleWeekly = GetWeeklyRetentionFormat ( ) ;
351
+
352
+ //Yearly retention policy
353
+ defaultRetention . IsYearlyScheduleEnabled = true ;
354
+ defaultRetention . YearlySchedule = new Models . YearlyRetentionSchedule ( ) ;
355
+ defaultRetention . YearlySchedule . DurationCountInYears = 10 ;
356
+ defaultRetention . YearlySchedule . RetentionScheduleFormatType = Models . RetentionScheduleFormat . Weekly ;
357
+ defaultRetention . YearlySchedule . MonthsOfYear = new List < Models . Month > ( ) ;
358
+ defaultRetention . YearlySchedule . MonthsOfYear . Add ( Models . Month . January ) ;
359
+ defaultRetention . YearlySchedule . RetentionScheduleDaily = GetDailyRetentionFormat ( ) ;
360
+ defaultRetention . YearlySchedule . RetentionScheduleWeekly = GetWeeklyRetentionFormat ( ) ;
361
+ return defaultRetention ;
362
+
363
+ }
364
+
365
+ private static Models . DailyRetentionFormat GetDailyRetentionFormat ( )
366
+ {
367
+ Models . DailyRetentionFormat dailyRetention = new Models . DailyRetentionFormat ( ) ;
368
+ dailyRetention . DaysOfTheMonth = new List < Models . Day > ( ) ;
369
+ Models . Day dayBasedRetention = new Models . Day ( ) ;
370
+ dayBasedRetention . IsLast = false ;
371
+ dayBasedRetention . Date = 1 ;
372
+ dailyRetention . DaysOfTheMonth . Add ( dayBasedRetention ) ;
373
+ return dailyRetention ;
374
+ }
375
+
376
+ private static Models . WeeklyRetentionFormat GetWeeklyRetentionFormat ( )
377
+ {
378
+ Models . WeeklyRetentionFormat weeklyRetention = new Models . WeeklyRetentionFormat ( ) ;
379
+ weeklyRetention . DaysOfTheWeek = new List < DayOfWeek > ( ) ;
380
+ weeklyRetention . DaysOfTheWeek . Add ( DayOfWeek . Sunday ) ;
381
+
382
+ weeklyRetention . WeeksOfTheMonth = new List < WeekOfMonth > ( ) ;
383
+ weeklyRetention . WeeksOfTheMonth . Add ( WeekOfMonth . First ) ;
384
+ return weeklyRetention ;
385
+ }
386
+
387
+ private static DateTime GenerateRandomTime ( )
388
+ {
389
+ //Schedule time will be random to avoid the load in service (same is in portal as well)
390
+ Random rand = new Random ( ) ;
391
+ int hour = rand . Next ( 0 , 24 ) ;
392
+ int minute = ( rand . Next ( 0 , 2 ) == 0 ) ? 0 : 30 ;
393
+ return new DateTime ( DateTime . Now . Year , DateTime . Now . Month , DateTime . Now . Day , hour , minute , 00 ) ;
394
+ }
395
+
396
+
300
397
#region private
301
398
private void ValidateAzureVMWorkloadType ( Microsoft . Azure . Commands . RecoveryServices . Backup . Cmdlets . Models . WorkloadType type )
302
399
{
0 commit comments