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
            {
                // 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);
            }
        }
Exemplo n.º 2
0
        public Schedule CreateSchedule(string automationAccountName, OneTimeSchedule 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,
                ScheduleType =
                    AutomationManagement.Models.ScheduleType
                                        .OneTimeSchedule
            };

            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));
        }