protected override void AutomationExecuteCmdlet()
        {
            // Assume local time if DateTimeKind.Unspecified
            if (this.StartTime.Kind == DateTimeKind.Unspecified)
            {
                this.StartTime = DateTime.SpecifyKind(this.StartTime, DateTimeKind.Local);
            }

            if (this.ExpiryTime.Kind == DateTimeKind.Unspecified)
            {
                this.ExpiryTime = DateTime.SpecifyKind(this.ExpiryTime, DateTimeKind.Local);
            }

            if (this.OneTime.IsPresent)
            {
                // ByOneTime
                var oneTimeSchedule = new OneTimeSchedule
                {
                    Name = this.Name,
                    StartTime = this.StartTime,
                    Description = this.Description,
                    ExpiryTime = this.ExpiryTime
                };

                Schedule schedule = this.AutomationClient.CreateSchedule(this.AutomationAccountName, oneTimeSchedule);
                this.WriteObject(schedule);
            }
            else if (this.DayInterval >= 1)
            {
                // ByDaily
                var dailySchedule = new DailySchedule
                {
                    Name = this.Name,
                    StartTime = this.StartTime,
                    DayInterval = this.DayInterval,
                    Description = this.Description,
                    ExpiryTime = this.ExpiryTime
                };

                Schedule schedule = this.AutomationClient.CreateSchedule(this.AutomationAccountName, dailySchedule);
                this.WriteObject(schedule);
            }
            else if (this.HourInterval >= 1)
            {
                // ByHourly
                var hourlySchedule = new HourlySchedule
                {
                    Name = this.Name,
                    StartTime = this.StartTime,
                    HourInterval = this.HourInterval,
                    Description = this.Description,
                    ExpiryTime = this.ExpiryTime
                };

                Schedule schedule = this.AutomationClient.CreateSchedule(this.AutomationAccountName, hourlySchedule);
                this.WriteObject(schedule);
            }
        }
Ejemplo n.º 2
0
        public Schedule CreateSchedule(string automationAccountName, HourlySchedule schedule)
        {
            this.ValidateScheduleName(automationAccountName, schedule.Name);

            var scheduleModel = new AutomationManagement.Models.Schedule
            {
                Name = schedule.Name,
                StartTime = schedule.StartTime.ToUniversalTime(),
                ExpiryTime = schedule.ExpiryTime.ToUniversalTime(),
                Description = schedule.Description,
                HourInterval = schedule.HourInterval,
                ScheduleType =
                    AutomationManagement.Models.ScheduleType
                                        .HourlySchedule
            };

            var scheduleCreateParameters = new AutomationManagement.Models.ScheduleCreateParameters
            {
                Schedule = scheduleModel
            };

            var scheduleCreateResponse = this.automationManagementClient.Schedules.Create(
                automationAccountName,
                scheduleCreateParameters);

            return this.GetSchedule(automationAccountName, new Guid(scheduleCreateResponse.Schedule.Id));
        }