diff --git a/src/ResourceManager/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj b/src/ResourceManager/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj index c2796176620b..dbd343473f35 100644 --- a/src/ResourceManager/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj +++ b/src/ResourceManager/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj @@ -59,8 +59,9 @@ ..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll - - ..\..\..\packages\Microsoft.Azure.Management.Automation.2.0.0\lib\net40\Microsoft.Azure.Management.Automation.dll + + ..\..\..\packages\Microsoft.Azure.Management.Automation.2.0.1\lib\net40\Microsoft.Azure.Management.Automation.dll + True False @@ -130,8 +131,10 @@ ..\..\..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll - - ..\..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll True + + + ..\..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll + True ..\..\..\packages\xunit.assert.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.assert.dll diff --git a/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationRunbookTest.cs b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationRunbookTest.cs index 5c475cf0c40b..1afe65240135 100644 --- a/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationRunbookTest.cs +++ b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationRunbookTest.cs @@ -20,6 +20,7 @@ using Microsoft.WindowsAzure.Commands.Utilities.Common; using Moq; using System.Collections.Generic; + namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.UnitTests { [TestClass] @@ -44,7 +45,7 @@ public void SetupTest() } [TestMethod] - public void NewAzureAutomationRunbookByNameSuccessfull() + public void NewAzureAutomationRunbookByNameSuccessful() { // Setup string resourceGroupName = "resourceGroup"; diff --git a/src/ResourceManager/Automation/Commands.Automation.Test/packages.config b/src/ResourceManager/Automation/Commands.Automation.Test/packages.config index 5f5eb3ff65e2..f833738c5d4d 100644 --- a/src/ResourceManager/Automation/Commands.Automation.Test/packages.config +++ b/src/ResourceManager/Automation/Commands.Automation.Test/packages.config @@ -3,6 +3,7 @@ + diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs index c17b4adb075d..2a45403f2257 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs @@ -61,7 +61,12 @@ public class ImportAzureAutomationRunbook : AzureAutomationBaseCmdlet /// Gets or sets the runbook version type /// [Parameter(Mandatory = true, HelpMessage = "Runbook definition type.")] - [ValidateSet(Constants.RunbookType.Graph, Constants.RunbookType.PowerShell, Constants.RunbookType.PowerShellWorkflow, IgnoreCase = true)] + [ValidateSet(Constants.RunbookType.PowerShell, + Constants.RunbookType.GraphicalPowerShell, + Constants.RunbookType.PowerShellWorkflow, + Constants.RunbookType.GraphicalPowerShellWorkflow, + Constants.RunbookType.Graph, + IgnoreCase = true)] [ValidateNotNullOrEmpty] public string Type { get; set; } @@ -101,7 +106,7 @@ protected override void AutomationProcessRecord() this.ResolvePath(this.Path), this.Description, this.Tags, - this.Type, + RunbookTypeSdkValue.Resolve(this.Type), this.LogProgress, this.LogVerbose, this.Published.IsPresent, diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationRunbook.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationRunbook.cs index 87219b2389f3..e806d2af4d5c 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationRunbook.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationRunbook.cs @@ -52,7 +52,12 @@ public class NewAzureAutomationRunbook : AzureAutomationBaseCmdlet /// Gets or sets the runbook version type /// [Parameter(Mandatory = true, HelpMessage = "Runbook definition type.")] - [ValidateSet(Constants.RunbookType.Graph, Constants.RunbookType.PowerShell, Constants.RunbookType.PowerShellWorkflow, IgnoreCase = true)] + [ValidateSet(Constants.RunbookType.PowerShell, + Constants.RunbookType.GraphicalPowerShell, + Constants.RunbookType.PowerShellWorkflow, + Constants.RunbookType.GraphicalPowerShellWorkflow, + Constants.RunbookType.Graph, + IgnoreCase = true)] [ValidateNotNullOrEmpty] public string Type { get; set; } @@ -78,7 +83,15 @@ protected override void AutomationProcessRecord() // ByRunbookName runbook = this.AutomationClient.CreateRunbookByName( - this.ResourceGroupName, this.AutomationAccountName, this.Name, this.Description, this.Tags, this.Type, this.LogProgress, this.LogVerbose, false); + this.ResourceGroupName, + this.AutomationAccountName, + this.Name, + this.Description, + this.Tags, + RunbookTypeSdkValue.Resolve(this.Type), + this.LogProgress, + this.LogVerbose, + false); this.WriteObject(runbook); } diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationSchedule.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationSchedule.cs index a115af3368ab..179d5423b467 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationSchedule.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationSchedule.cs @@ -12,11 +12,15 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Commands.Automation.Common; -using Microsoft.Azure.Commands.Automation.Model; using System; +using System.Collections.Generic; +using System.Linq; using System.Management.Automation; using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Properties; +using DayOfWeek = Microsoft.Azure.Commands.Automation.Model.DayOfWeek; namespace Microsoft.Azure.Commands.Automation.Cmdlet { @@ -57,6 +61,30 @@ public NewAzureAutomationSchedule() [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The schedule description.")] public string Description { get; set; } + /// + /// Gets or sets the schedule days of the week. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByWeekly, Mandatory = false, HelpMessage = "The list of days of week for the weekly schedule.")] + public System.DayOfWeek[] DaysOfWeek { get; set; } + + /// + /// Gets or sets the schedule days of the month. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByMonthlyDaysOfMonth, Mandatory = false, HelpMessage = "The list of days of month for the monthly schedule.")] + public DaysOfMonth[] DaysOfMonth { get; set; } + + /// + /// Gets or sets the schedule day of the week. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByMonthlyDayOfWeek, Mandatory = false, HelpMessage = "The day of week for the monthly occurrence.")] + public System.DayOfWeek? DayOfWeek { get; set; } + + /// + /// Gets or sets the schedule day of the week. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByMonthlyDayOfWeek, Mandatory = false, HelpMessage = "The Occurrence of the week within the month.")] + public DayOfWeekOccurrence DayOfWeekOccurrence { get; set; } + /// /// Gets or sets the switch parameter to create a one time schedule. /// @@ -68,6 +96,9 @@ public NewAzureAutomationSchedule() /// [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByDaily, Mandatory = false, HelpMessage = "The schedule expiry time.")] [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByHourly, Mandatory = false, HelpMessage = "The schedule expiry time.")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByWeekly, Mandatory = false, HelpMessage = "The schedule expiry time.")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByMonthlyDaysOfMonth, Mandatory = false, HelpMessage = "The schedule expiry time.")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByMonthlyDayOfWeek, Mandatory = false, HelpMessage = "The schedule expiry time.")] public DateTimeOffset ExpiryTime { get; set; } /// @@ -84,6 +115,27 @@ public NewAzureAutomationSchedule() [ValidateRange(1, byte.MaxValue)] public byte HourInterval { get; set; } + /// + /// Gets or sets the weekly schedule week interval. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByWeekly, Mandatory = true, HelpMessage = "The weekly schedule week interval.")] + [ValidateRange(1, byte.MaxValue)] + public byte WeekInterval { get; set; } + + /// + /// Gets or sets the weekly schedule week interval. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByMonthlyDaysOfMonth, Mandatory = true, HelpMessage = "The monthly schedule month interval.")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByMonthlyDayOfWeek, Mandatory = true, HelpMessage = "The monthly schedule month interval.")] + [ValidateRange(1, byte.MaxValue)] + public byte MonthInterval { get; set; } + + /// + /// Gets or sets the schedule time zone. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The schedule time zone.")] + public string TimeZone { get; set; } + /// /// Execute this cmdlet. /// @@ -95,26 +147,168 @@ protected override void AutomationProcessRecord() Name = this.Name, StartTime = this.StartTime, Description = this.Description, - ExpiryTime = this.ExpiryTime + ExpiryTime = this.ExpiryTime, + TimeZone = this.TimeZone, }; - if (this.ParameterSetName == AutomationCmdletParameterSets.ByOneTime) + switch (this.ParameterSetName) { - schedule.Frequency = ScheduleFrequency.Onetime; + case AutomationCmdletParameterSets.ByOneTime: + schedule.Frequency = ScheduleFrequency.Onetime; + break; + case AutomationCmdletParameterSets.ByDaily: + schedule.Frequency = ScheduleFrequency.Day; + schedule.Interval = this.DayInterval; + break; + case AutomationCmdletParameterSets.ByHourly: + schedule.Frequency = ScheduleFrequency.Hour; + schedule.Interval = this.HourInterval; + break; + case AutomationCmdletParameterSets.ByWeekly: + schedule = this.CreateWeeklyScheduleModel(); + break; + case AutomationCmdletParameterSets.ByMonthlyDayOfWeek: + schedule = this.CreateMonthlyScheduleModel(); + break; + case AutomationCmdletParameterSets.ByMonthlyDaysOfMonth: + schedule = this.CreateMonthlyScheduleModel(); + break; } - else if (this.ParameterSetName == AutomationCmdletParameterSets.ByDaily) + + Schedule createdSchedule = this.AutomationClient.CreateSchedule(this.ResourceGroupName, this.AutomationAccountName, schedule); + this.WriteObject(createdSchedule); + } + + /// + /// The validate. + /// + /// + /// The . + /// + /// + /// throws exception + /// + private Schedule CreateMonthlyScheduleModel() + { + var dayOfWeek = this.DayOfWeek.HasValue ? this.DayOfWeek.ToString() : null; + if ((!string.IsNullOrWhiteSpace(dayOfWeek) && this.DayOfWeekOccurrence == 0) || (string.IsNullOrWhiteSpace(dayOfWeek) && this.DayOfWeekOccurrence != 0)) { - schedule.Frequency = ScheduleFrequency.Day; - schedule.Interval = this.DayInterval; + throw new ArgumentException(Resources.MonthlyScheduleNeedsDayOfWeekAndOccurrence); } - else if (this.ParameterSetName == AutomationCmdletParameterSets.ByHourly) + + var newSchedule = new Schedule { - schedule.Frequency = ScheduleFrequency.Hour; - schedule.Interval = this.HourInterval; - } + Name = this.Name, + StartTime = this.StartTime, + Description = this.Description, + ExpiryTime = this.ExpiryTime, + Frequency = ScheduleFrequency.Month, + Interval = this.MonthInterval, + MonthlyScheduleOptions = this.IsMonthlyScheduleNull() + ? null + : new MonthlyScheduleOptions() + { + DaysOfMonth = this.DaysOfMonth, + DayOfWeek = this.DayOfWeek == null && this.DayOfWeekOccurrence == 0 + ? null + : new DayOfWeek() + { + Day = dayOfWeek, + Occurrence = this.DayOfWeekOccurrence == 0 ? null : this.DayOfWeekOccurrence.ToString() + } + } + }; - Schedule createdSchedule = this.AutomationClient.CreateSchedule(this.ResourceGroupName, this.AutomationAccountName, schedule); - this.WriteObject(createdSchedule); + return newSchedule; + } + + /// + /// The is monthly schedule null. + /// + /// + /// The . + /// + private bool IsMonthlyScheduleNull() + { + return this.DaysOfMonth == null && this.DayOfWeek == null && this.DayOfWeekOccurrence == 0; + } + + /// + /// The create weekly schedule model. + /// + /// + /// The . + /// + private Schedule CreateWeeklyScheduleModel() + { + var newSchedule = new Schedule + { + Name = this.Name, + StartTime = this.StartTime, + Description = this.Description, + ExpiryTime = this.ExpiryTime, + Frequency = ScheduleFrequency.Week, + Interval = this.WeekInterval, + WeeklyScheduleOptions = this.DaysOfWeek == null + ? null + : new WeeklyScheduleOptions() + { + DaysOfWeek = this.DaysOfWeek.Select(day => day.ToString()).ToList() + } + }; + + return newSchedule; } } + + /// + /// The day of week occurrence. + /// + public enum DayOfWeekOccurrence + { + First = 1, + Second = 2, + Third = 3, + Fourth = 4, + Last = -1 + } + + /// + /// The day of week occurrence. + /// + public enum DaysOfMonth + { + One = 1, + Two = 2, + Three = 3, + Four = 4, + Five = 5, + Six = 6, + Seventh = 7, + Eighth = 8, + Ninth = 9, + Tenth = 10, + Eleventh =11, + Twelfth =12, + Thirteenth = 13, + Fourteenth = 14, + Fifteenth = 15, + Sixteenth = 16, + Seventeenth = 17, + Eighteenth = 18, + Nineteenth = 19, + Twentieth = 20, + TwentyFirst = 21, + TwentySecond = 22, + TwentyThird = 23, + TwentyFourth = 24, + TwentyFifth = 25, + TwentySixth = 26, + TwentySeventh = 27, + TwentyEighth = 28, + TwentyNinth = 29, + Thirtieth = 30, + ThirtyFirst = 31, + LastDay = -1 + } } diff --git a/src/ResourceManager/Automation/Commands.Automation/Commands.Automation.csproj b/src/ResourceManager/Automation/Commands.Automation/Commands.Automation.csproj index f3c8b5d9d8bb..887313e7d263 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Commands.Automation.csproj +++ b/src/ResourceManager/Automation/Commands.Automation/Commands.Automation.csproj @@ -59,9 +59,9 @@ False ..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll - - False - ..\..\..\packages\Microsoft.Azure.Management.Automation.2.0.0\lib\portable-net45+wp8+wpa81+win\Microsoft.Azure.Management.Automation.dll + + ..\..\..\packages\Microsoft.Azure.Management.Automation.2.0.1\lib\net40\Microsoft.Azure.Management.Automation.dll + True False @@ -209,6 +209,7 @@ + @@ -222,6 +223,7 @@ + @@ -230,6 +232,7 @@ + @@ -237,6 +240,7 @@ + True diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs index 47668a0a12e2..2bf24a284d5f 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs @@ -334,7 +334,9 @@ public Schedule CreateSchedule(string resourceGroupName, string automationAccoun ExpiryTime = schedule.ExpiryTime, Description = schedule.Description, Interval = schedule.Interval, - Frequency = schedule.Frequency.ToString() + Frequency = schedule.Frequency.ToString(), + AdvancedSchedule = schedule.GetAdvancedSchedule(), + TimeZone = schedule.TimeZone, } }; @@ -452,8 +454,8 @@ public Runbook CreateRunbookByName(string resourceGroupName, string automationAc var rdcprop = new RunbookCreateOrUpdateDraftProperties() { Description = description, - RunbookType = String.IsNullOrWhiteSpace(type) ? RunbookTypeEnum.Script : (0 == string.Compare(type, Constants.RunbookType.PowerShellWorkflow, StringComparison.OrdinalIgnoreCase)) ? RunbookTypeEnum.Script : type, - LogProgress = logProgress.HasValue && logProgress.Value, + RunbookType = String.IsNullOrWhiteSpace(type) ? RunbookTypeEnum.Script : type, + LogProgress = logProgress.HasValue && logProgress.Value, LogVerbose = logVerbose.HasValue && logVerbose.Value, Draft = new RunbookDraft(), }; @@ -474,7 +476,6 @@ public Runbook CreateRunbookByName(string resourceGroupName, string automationAc public Runbook ImportRunbook(string resourceGroupName, string automationAccountName, string runbookPath, string description, IDictionary tags, string type, bool? logProgress, bool? logVerbose, bool published, bool overwrite, string name) { - var fileExtension = Path.GetExtension(runbookPath); if (0 != @@ -489,15 +490,13 @@ public Runbook ImportRunbook(string resourceGroupName, string automationAccountN } // if graph runbook make sure type is not null and has right value - if (0 == string.Compare(fileExtension, Constants.SupportedFileExtensions.Graph, StringComparison.OrdinalIgnoreCase) - && string.IsNullOrWhiteSpace(type) - && (0 != string.Compare(type, Constants.RunbookType.Graph, StringComparison.OrdinalIgnoreCase))) + if (0 == string.Compare(fileExtension, Constants.SupportedFileExtensions.Graph, StringComparison.OrdinalIgnoreCase) + && (string.IsNullOrWhiteSpace(type) || !IsGraphRunbook(type))) { throw new ResourceCommonException(typeof(Runbook), string.Format(CultureInfo.CurrentCulture, Resources.InvalidRunbookTypeForExtension, fileExtension)); } - var runbookName = Path.GetFileNameWithoutExtension(runbookPath); if (String.IsNullOrWhiteSpace(name) == false) @@ -1784,7 +1783,7 @@ private DirectoryInfo WriteRunbookToFile(string outputFolder, string runbookName outputFolderFullPath = this.ValidateAndGetFullPath(outputFolder); } - var fileExtension = (0 == string.Compare(runbookType, Constants.RunbookType.Graph, StringComparison.OrdinalIgnoreCase)) ? Constants.SupportedFileExtensions.Graph : Constants.SupportedFileExtensions.PowerShellScript; + var fileExtension = IsGraphRunbook(runbookType) ? Constants.SupportedFileExtensions.Graph : Constants.SupportedFileExtensions.PowerShellScript; var outputFilePath = outputFolderFullPath + "\\" + runbookName + fileExtension; @@ -1801,6 +1800,13 @@ private DirectoryInfo WriteRunbookToFile(string outputFolder, string runbookName return new DirectoryInfo(runbookName + fileExtension); } + private static bool IsGraphRunbook(string runbookType) + { + return (string.Equals(runbookType, RunbookTypeEnum.Graph, StringComparison.OrdinalIgnoreCase) || + string.Equals(runbookType, RunbookTypeEnum.GraphPowerShell, StringComparison.OrdinalIgnoreCase) || + string.Equals(runbookType, RunbookTypeEnum.GraphPowerShellWorkflow, StringComparison.OrdinalIgnoreCase)); + } + #endregion } } \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs index ccf9e8ddcefc..387eaeb6012e 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs @@ -52,6 +52,21 @@ internal static class AutomationCmdletParameterSets /// internal const string ByHourly = "ByHourly"; + /// + /// The weekly schedule parameter set. + /// + internal const string ByWeekly = "ByWeekly"; + + /// + /// The monthly schedule parameter set. + /// + internal const string ByMonthlyDaysOfMonth = "ByMonthlyDaysOfMonth"; + + /// + /// The monthly schedule parameter set. + /// + internal const string ByMonthlyDayOfWeek = "ByMonthlyDayOfWeek"; + /// /// The Job Id parameter set. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/Constants.cs b/src/ResourceManager/Automation/Commands.Automation/Common/Constants.cs index b35962ebf345..20fb3c08f651 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/Constants.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/Constants.cs @@ -81,6 +81,10 @@ public static class RunbookType public const string PowerShellWorkflow = "PowerShellWorkflow"; public const string Graph = "Graph"; + + public const string GraphicalPowerShell = "GraphicalPowerShell"; + + public const string GraphicalPowerShellWorkflow = "GraphicalPowerShellWorkflow"; } public static class SupportedFileExtensions diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/RunbookTypeSdkValue.cs b/src/ResourceManager/Automation/Commands.Automation/Common/RunbookTypeSdkValue.cs new file mode 100644 index 000000000000..0757314f2e37 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Common/RunbookTypeSdkValue.cs @@ -0,0 +1,36 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using Microsoft.Azure.Management.Automation.Models; + +namespace Microsoft.Azure.Commands.Automation.Common +{ + public static class RunbookTypeSdkValue + { + public static string Resolve(string commandValue) + { + if (Constants.RunbookType.GraphicalPowerShell.Equals(commandValue, StringComparison.OrdinalIgnoreCase)) + { + return RunbookTypeEnum.GraphPowerShell; + } + else if (Constants.RunbookType.GraphicalPowerShellWorkflow.Equals(commandValue, StringComparison.OrdinalIgnoreCase)) + { + return RunbookTypeEnum.GraphPowerShellWorkflow; + } + + return commandValue; + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Microsoft.Azure.Commands.ResourceManager.Automation.dll-help.xml b/src/ResourceManager/Automation/Commands.Automation/Microsoft.Azure.Commands.ResourceManager.Automation.dll-help.xml index 20a49aa73afc..205c36766a45 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Microsoft.Azure.Commands.ResourceManager.Automation.dll-help.xml +++ b/src/ResourceManager/Automation/Commands.Automation/Microsoft.Azure.Commands.ResourceManager.Automation.dll-help.xml @@ -5761,7 +5761,7 @@ PS C:\> $Value = $Variable.value - The Import-AzureRmAutomationRunbook cmdlet imports an Azure Automation runbook. Specify the path to a Windows PowerShell script (.ps1 ) file to import for Windows PowerShell and Windows PowerShell Workflow runbooks, or to a graphical runbook (.graphrunbook) file for graphical runbooks. The name of the file becomes the name of the runbook. For Windows PowerShell Workflow runbooks, the script must contain a single Windows PowerShell Workflow definition that matches the name of the file. + The Import-AzureRmAutomationRunbook cmdlet imports an Azure Automation runbook. Specify the path to a Windows PowerShell script (.ps1 ) file to import for Windows PowerShell and Windows PowerShell Workflow runbooks, or to a graphical runbook (.graphrunbook) file for graphical runbooks. The name of the file becomes the name of the runbook; however, for PowerShell, GraphicalPowerShell, and GraphicalPowerShellWorkflow runbook types the name can be specified during import by using the Name parameter. For Windows PowerShell Workflow runbooks, the script must contain a single Windows PowerShell Workflow definition that matches the name of the file. @@ -5805,14 +5805,14 @@ PS C:\> $Value = $Variable.value Specifies whether the runbook logs progress information. - Boolean] + Boolean LogVerbose Specifies whether the runbook logs detailed information. - Boolean] + Boolean Name @@ -5839,14 +5839,18 @@ PS C:\> $Value = $Variable.value Specifies the type of runbook that this cmdlet creates. Valid values are: --- Graph -- PowerShell --- PowerShellWorkflow +-- GraphicalPowerShell +-- PowerShellWorkflow +-- GraphicalPowerShellWorkflow +-- Graph (obsolete; equivalent to GraphicalPowerShellWorkflow) - Graph PowerShell + GraphicalPowerShell PowerShellWorkflow + GraphicalPowerShellWorkflow + Graph @@ -5893,9 +5897,9 @@ PS C:\> $Value = $Variable.value Specifies whether the runbook logs progress information. - Boolean] + Boolean - Boolean] + Boolean none @@ -5905,9 +5909,9 @@ PS C:\> $Value = $Variable.value Specifies whether the runbook logs detailed information. - Boolean] + Boolean - Boolean] + Boolean none @@ -5977,9 +5981,11 @@ PS C:\> $Value = $Variable.value Specifies the type of runbook that this cmdlet creates. Valid values are: --- Graph -- PowerShell --- PowerShellWorkflow +-- GraphicalPowerShell +-- PowerShellWorkflow +-- GraphicalPowerShellWorkflow +-- Graph (obsolete; equivalent to GraphicalPowerShellWorkflow) String @@ -6029,7 +6035,7 @@ PS C:\> $Value = $Variable.value PS C:\>$Tags = @{"tag01"='value01"; "tag02"="value02"} -PS C:\> Import-AzureRmAutomationRunbook -Path .\GraphicalRunbook06.graphrunbook -Tags $Tags -ResourceGroup "ResourceGroup01" -AutomationAccountName "AutomationAccount01" -Type Graph +PS C:\> Import-AzureRmAutomationRunbook -Path .\GraphicalRunbook06.graphrunbook -Tags $Tags -ResourceGroup "ResourceGroup01" -AutomationAccountName "AutomationAccount01" -Type GraphicalPowerShell The first command assigns two key/value pairs to the $Tags variable. @@ -7238,7 +7244,7 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N - The New-AzureRmAutomationRunbook cmdlet creates an empty Azure Automation runbook by using Azure PowerShell. Specify a name for the runbook. + The New-AzureRmAutomationRunbook cmdlet creates an empty Azure Automation runbook. @@ -7276,14 +7282,14 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies whether the runbook logs progress. - Boolean] + Boolean LogVerbose Specifies whether logging includes detailed information. - Boolean] + Boolean Tags @@ -7297,14 +7303,18 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies the type of runbook that this cmdlet creates. Valid values are: --- Graph -- PowerShell --- PowerShellWorkflow +-- GraphicalPowerShell +-- PowerShellWorkflow +-- GraphicalPowerShellWorkflow +-- Graph (obsolete; equivalent to GraphicalPowerShellWorkflow) - Graph PowerShell + GraphicalPowerShell PowerShellWorkflow + GraphicalPowerShellWorkflow + Graph @@ -7339,9 +7349,9 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies whether the runbook logs progress. - Boolean] + Boolean - Boolean] + Boolean none @@ -7351,9 +7361,9 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies whether logging includes detailed information. - Boolean] + Boolean - Boolean] + Boolean none @@ -7399,9 +7409,11 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies the type of runbook that this cmdlet creates. Valid values are: --- Graph -- PowerShell --- PowerShellWorkflow +-- GraphicalPowerShell +-- PowerShellWorkflow +-- GraphicalPowerShellWorkflow +-- Graph (obsolete; equivalent to GraphicalPowerShellWorkflow) String @@ -7449,10 +7461,10 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N - PS C:\>New-AzureRmAutomationRunbook -AutomationAccountName "Contoso17" -Name "Runbook02" -ResourceGroupName "ResourceGroup01" + PS C:\>New-AzureRmAutomationRunbook -AutomationAccountName "Contoso17" -Name "Runbook02" -ResourceGroupName "ResourceGroup01" -Type PowerShell - This command creates a runbook named Runbook02 in the Azure Automation account named Contoso17. + This command creates a PowerShell runbook named Runbook02 in the Azure Automation account named Contoso17. @@ -7546,7 +7558,7 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies a description for the schedule. - String + String ExpiryTime @@ -7562,6 +7574,13 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Byte + + TimeZone + + The time zone for the schedule. This string can be the IANNA ID or the Windows Time Zone ID. + + String + New-AzureRMAutomationSchedule @@ -7598,7 +7617,7 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies a description for the schedule. - String + String OneTime @@ -7606,6 +7625,13 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies that the cmdlet creates a one-time schedule. + + TimeZone + + The time zone for the schedule. This string can be the IANNA ID or the Windows Time Zone ID. + + String + New-AzureRMAutomationSchedule @@ -7642,7 +7668,7 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies a description for the schedule. - String + String ExpiryTime @@ -7658,6 +7684,218 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Byte + + TimeZone + + The time zone for the schedule. This string can be the IANNA ID or the Windows Time Zone ID. + + String + + + + New-AzureRMAutomationSchedule + + ResourceGroupName + + Specifies the name of a resource group for which this cmdlet creates a schedule. + + String + + + AutomationAccountName + + Specifies the name of an Automation account for which this cmdlet creates a schedule. + + String + + + Name + + Specifies a name for the schedule. + + String + + + StartTime + + Specifies the start time of a schedule as a DateTimeOffset object. You can specify a string that can be converted to a valid DateTimeOffset. + + DateTimeOffset + + + Description + + Specifies a description for the schedule. + + String + + + ExpiryTime + + Specifies the expiry time of a schedule as a DateTimeOffest object. You can specify a string that can be converted to a valid DateTimeOffset. + + DateTimeOffset + + + DaysOfWeek + + The list of days of week for the weekly schedule. + + System.DayOfWeek[] + + + WeekInterval + + Specifies an interval, in weeks, for the schedule. + + Byte + + + TimeZone + + The time zone for the schedule. This string can be the IANNA ID or the Windows Time Zone ID. + + String + + + + New-AzureRMAutomationSchedule + + ResourceGroupName + + Specifies the name of a resource group for which this cmdlet creates a schedule. + + String + + + AutomationAccountName + + Specifies the name of an Automation account for which this cmdlet creates a schedule. + + String + + + Name + + Specifies a name for the schedule. + + String + + + StartTime + + Specifies the start time of a schedule as a DateTimeOffset object. You can specify a string that can be converted to a valid DateTimeOffset. + + DateTimeOffset + + + Description + + Specifies a description for the schedule. + + String + + + ExpiryTime + + Specifies the expiry time of a schedule as a DateTimeOffest object. You can specify a string that can be converted to a valid DateTimeOffset. + + DateTimeOffset + + + DaysOfMonth + + The list of days of month for the monthly schedule. + + System.Int32[] + + + MonthInterval + + Specifies an interval, in Month, for the schedule. + + Byte + + + TimeZone + + The time zone for the schedule. This string can be the IANNA ID or the Windows Time Zone ID. + + String + + + + New-AzureRMAutomationSchedule + + ResourceGroupName + + Specifies the name of a resource group for which this cmdlet creates a schedule. + + String + + + AutomationAccountName + + Specifies the name of an Automation account for which this cmdlet creates a schedule. + + String + + + Name + + Specifies a name for the schedule. + + String + + + StartTime + + Specifies the start time of a schedule as a DateTimeOffset object. You can specify a string that can be converted to a valid DateTimeOffset. + + DateTimeOffset + + + Description + + Specifies a description for the schedule. + + String + + + ExpiryTime + + Specifies the expiry time of a schedule as a DateTimeOffest object. You can specify a string that can be converted to a valid DateTimeOffset. + + DateTimeOffset + + + DayOfWeek + + The day of week for the monthly occurrence. + + System.DayOfWeek + + + DayOfWeekOccurrence + + The Occurrence of the week within the month.The acceptable values either are 1, 2, 3, 4, -1 or First, Second, Third, Fourth and LastDay + + System.Int32 + + + MonthInterval + + Specifies an interval, in Month, for the schedule. + + Byte + + + TimeZone + + The time zone for the schedule. This string can be the IANNA ID or the Windows Time Zone ID. + + String + @@ -7690,7 +7928,7 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies a description for the schedule. - String + String String @@ -7769,6 +8007,77 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N none + + WeekInterval + + Specifies an interval, in weeks, for the schedule. + + Byte + + Byte + + + none + + + MonthInterval + + Specifies an interval, in moonths, for the schedule. + + Byte + + Byte + + + none + + + DaysOfWeek + + The list of days of week for the weekly schedule. + + System.DayOfWeek[] + + System.DayOfWeek[] + + + + + DayOfWeek + + The day of week for the monthly occurrence. + + System.DayOfWeek + + System.DayOfWeek + + + none + + + DayOfWeekOccurrence + + The Occurrence of the week within the month.The acceptable values either are 1, 2, 3, 4, -1 or First, Second, Third, Fourth and LastDay + + System.Int32 + + System.Int32 + + + none + + + TimeZone + + The time zone for the schedule. This string can be the IANA ID or the Windows Time Zone ID. + + String + + String + + + none + @@ -7803,15 +8112,18 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N - Example 1: Create a one-time schedule + Example 1: Create a one-time schedule in your machine's local time. - PS C:\>New-AzureRmAutomationSchedule -AutomationAccountName "Contoso17" -Name "Schedule01" -StartTime "23:00" -OneTime -ResourceGroupName "ResourceGroup01" - + +PS C:\> $TimeZone = ([System.TimeZoneInfo]::Local).Id +PS C:\> New-AzureRmAutomationSchedule -AutomationAccountName "Contoso17" -Name "Schedule01" -StartTime "23:00" -TimeZone $TimeZone -OneTime -ResourceGroupName "ResourceGroup01" + - The following command creates a schedule that runs one time on the current date at 11:00 PM. + The first command gets the time zone ID from the system. + The second command creates a schedule that runs one time on the current date at 11:00 PM in your local time zone. @@ -7827,7 +8139,8 @@ PS C:\> New-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N - PS C:\>$StartTime = Get-Date "13:00:00" + +PS C:\> $StartTime = Get-Date "13:00:00" PS C:\> $EndTime = $StartTime.AddYears(1) PS C:\> New-AzureRmAutomationSchedule -AutomationAccountName "Contoso17" -Name "Schedule02" -StartTime $StartTime -ExpiryTime $EndTime -DailyInterval 1 -ResourceGroupName "ResourceGroup01" @@ -7844,6 +8157,58 @@ PS C:\> New-AzureRmAutomationSchedule -AutomationAccountName "Contoso17" -Nam + + Example 3: Create a recurring Weekly schedule + + + + + +PS C:\> $StartTime = Get-Date "13:00:00" +PS C:\> $EndTime = $StartTime.AddYears(1) +PS C:\> $days = @([System.DayOfWeek]::Monday, [System.DayOfWeek]::Saturday, [System.DayOfWeek]::Sunday) +PS C:\> New-AzureRmAutomationSchedule -AutomationAccountName "Contoso17" -Name "Schedule03" -StartTime $StartTime -ExpiryTime $EndTime -WeeklyInterval 1 -DaysOfWeek $days -ResourceGroupName "ResourceGroup01" + + + The first command creates a date object by using the Get-Date cmdlet, and then stores the object in the $StartDate variable. Specify a time that is at least five minutes in the future. + The second command creates a date object by using the Get-Date cmdlet, and then stores the object in the $EndDate variable. The command specifies a future time. + The third command creates an array of selected System.DayOfWeek in which the schedule is set to be run, and then stores the object in the $days variable. + The final command creates a weekly schedule named Schedule03 to begin at the time stored in $StartDate, expire at the time stored in $EndDate and run in the days of the week stored in $days. + + + + + + + + + + + Example 4: Create a recurring Monthly schedule + + + + + +PS C:\> $StartTime = Get-Date "13:00:00" +PS C:\> $EndTime = $StartTime.AddYears(1) +PS C:\> $days = @($days = @(17,19,25, "LastDay")) +PS C:\> New-AzureRmAutomationSchedule -AutomationAccountName "Contoso17" -Name "Schedule04" -StartTime $StartTime -ExpiryTime $EndTime -MonthlyInterval 1 -DaysOfMonth $days -ResourceGroupName "ResourceGroup01" + + + The first command creates a date object by using the Get-Date cmdlet, and then stores the object in the $StartDate variable. Specify a time that is at least five minutes in the future. + The second command creates a date object by using the Get-Date cmdlet, and then stores the object in the $EndDate variable. The command specifies a future time. + The third command creates an array of selected System.Int in which the schedule is set to be run, and then stores the object in the $days variable. + The final command creates a monthlySchedule schedule named Schedule04 to begin at the time stored in $StartDate, expire at the time stored in $EndDate and run on the days of the month stored in $days. + + + + + + + + + @@ -11201,7 +11566,7 @@ PS C:\> Set-AzureRmAutomationAccount -Name "AutomationAccount01" -ResourceGro Specifies whether the certificate can be exported. - Boolean] + Boolean Password @@ -11249,9 +11614,9 @@ PS C:\> Set-AzureRmAutomationAccount -Name "AutomationAccount01" -ResourceGro Specifies whether the certificate can be exported. - Boolean] + Boolean - Boolean] + Boolean none @@ -12182,14 +12547,14 @@ PS C:\> Set-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies whether the runbook logs progress. - Boolean] + Boolean LogVerbose Specifies whether logging includes detailed information. - Boolean] + Boolean Tags @@ -12230,9 +12595,9 @@ PS C:\> Set-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies whether the runbook logs progress. - Boolean] + Boolean - Boolean] + Boolean none @@ -12242,9 +12607,9 @@ PS C:\> Set-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies whether logging includes detailed information. - Boolean] + Boolean - Boolean] + Boolean none @@ -12425,7 +12790,7 @@ PS C:\> Set-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies whether this cmdlet enables the schedule. - Boolean] + Boolean @@ -12459,9 +12824,9 @@ PS C:\> Set-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies whether this cmdlet enables the schedule. - Boolean] + Boolean - Boolean] + Boolean none @@ -12831,7 +13196,7 @@ PS C:\> Set-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies whether the webhook is enabled. - Boolean] + Boolean Parameters @@ -12860,9 +13225,9 @@ PS C:\> Set-AzureRmAutomationCredential -AutomationAccountName "Contoso17" -N Specifies whether the webhook is enabled. - Boolean] + Boolean - Boolean] + Boolean none @@ -13182,7 +13547,45 @@ PS C:\> Start-AzureRmAutomationDscCompilationJob -ConfigurationName "Config01 ResourceGroupName - Specifies the name of the resource group for which this cmdlet starts a runbook. + Specifies the name of the resource group in which this cmdlet starts a runbook. + + String + + + AutomationAccountName + + Specifies the name of the Automation account in which this cmdlet starts a runbook. + + String + + + Name + + Specifies the name of the runbook that this cmdlet starts. + + String + + + Parameters + + Specifies a dictionary of key/value pairs. The keys are the runbook parameter names. The values are the runbook parameter values. + + IDictionary + + + RunOn + + Specifies an Automation hybrid worker group to run this runbook on. + + String + + + + Start-AzureRMAutomationRunbook + + ResourceGroupName + + Specifies the name of the resource group in which this cmdlet starts a runbook. String @@ -13210,10 +13613,25 @@ PS C:\> Start-AzureRmAutomationDscCompilationJob -ConfigurationName "Config01 RunOn - Specifies a run on value. + Specifies an Automation hybrid worker group to run this runbook on. String + + Wait + + Waits for job to complete, suspend, or fail. + + SwitchParameter + none + + + MaxWaitSeconds + + Maximum time in seconds to wait for job completion. Default max wait time is 10800 seconds. + + Int32 + @@ -13256,7 +13674,7 @@ PS C:\> Start-AzureRmAutomationDscCompilationJob -ConfigurationName "Config01 ResourceGroupName - Specifies the name of the resource group for which this cmdlet starts a runbook. + Specifies the name of the resource group in which this cmdlet starts a runbook. String @@ -13268,7 +13686,7 @@ PS C:\> Start-AzureRmAutomationDscCompilationJob -ConfigurationName "Config01 RunOn - Specifies a run on value. + Specifies an Automation hybrid worker group to run this runbook on. String @@ -13277,6 +13695,25 @@ PS C:\> Start-AzureRmAutomationDscCompilationJob -ConfigurationName "Config01 none + + Wait + + Waits for job to complete, suspend, or fail. + + SwitchParameter + + SwitchParameter + + + none + + + MaxWaitSeconds + + Maximum time in seconds to wait for job completion. Default max wait time is 10800 seconds. + + Int32 + diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/DayOfWeek.cs b/src/ResourceManager/Automation/Commands.Automation/Model/DayOfWeek.cs new file mode 100644 index 000000000000..a42e17de8c86 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Model/DayOfWeek.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + public class DayOfWeek + { + /// + /// Gets or sets the schedule day of the week occurrence. + /// + public string Occurrence { get; set; } + + /// + /// Gets or sets the schedule day of the week. + /// + public string Day { get; set; } + + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/MonthlyScheduleOptions.cs b/src/ResourceManager/Automation/Commands.Automation/Model/MonthlyScheduleOptions.cs new file mode 100644 index 000000000000..2c0a12c04289 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Model/MonthlyScheduleOptions.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Azure.Commands.Automation.Cmdlet; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + public class MonthlyScheduleOptions + { + /// + /// Gets or sets the schedule days of the month. + /// + public IList DaysOfMonth { get; set; } + + /// + /// Gets or sets the day of week. + /// + public DayOfWeek DayOfWeek { get; set; } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/Schedule.cs b/src/ResourceManager/Automation/Commands.Automation/Model/Schedule.cs index b6c7599460c6..c8a3d430e62a 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Model/Schedule.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Model/Schedule.cs @@ -12,8 +12,14 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation.Language; +using Microsoft.Azure.Commands.Automation.Cmdlet; using Microsoft.Azure.Commands.Automation.Common; using System; +using Microsoft.Azure.Management.Automation.Models; namespace Microsoft.Azure.Commands.Automation.Model { @@ -37,24 +43,28 @@ public class Schedule : BaseProperties public Schedule(string resourceGroupName, string automationAccountName, Azure.Management.Automation.Models.Schedule schedule) { Requires.Argument("schedule", schedule).NotNull(); + this.ResourceGroupName = resourceGroupName; this.AutomationAccountName = automationAccountName; this.Name = schedule.Name; this.Description = schedule.Properties.Description; - this.StartTime = schedule.Properties.StartTime.ToLocalTime(); - this.ExpiryTime = schedule.Properties.ExpiryTime.ToLocalTime(); + this.StartTime = AdjustOffset(schedule.Properties.StartTime, schedule.Properties.StartTimeOffsetMinutes); + this.ExpiryTime = AdjustOffset(schedule.Properties.ExpiryTime, schedule.Properties.ExpiryTimeOffsetMinutes); this.CreationTime = schedule.Properties.CreationTime.ToLocalTime(); this.LastModifiedTime = schedule.Properties.LastModifiedTime.ToLocalTime(); this.IsEnabled = schedule.Properties.IsEnabled; - this.NextRun = schedule.Properties.NextRun.HasValue - ? schedule.Properties.NextRun.Value.ToLocalTime() - : this.NextRun; - this.Interval = schedule.Properties.Interval.HasValue ? schedule.Properties.Interval.Value : this.Interval; + this.NextRun = AdjustOffset(schedule.Properties.NextRun, schedule.Properties.NextRunOffsetMinutes); + this.Interval = schedule.Properties.Interval ?? this.Interval; this.Frequency = (ScheduleFrequency)Enum.Parse(typeof(ScheduleFrequency), schedule.Properties.Frequency, true); + this.WeeklyScheduleOptions = this.CreateWeeklyScheduleOptions(schedule); + this.MonthlyScheduleOptions = this.CreateMonthlyScheduleOptions(schedule); + this.TimeZone = schedule.Properties.TimeZone; } + #region Public Properties + /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public Schedule() { @@ -89,5 +99,215 @@ public Schedule() /// Gets or sets the schedule frequency. /// public ScheduleFrequency Frequency { get; set; } + + /// + /// Gets or sets the monthly schedule options. + /// + public MonthlyScheduleOptions MonthlyScheduleOptions { get; set; } + + /// + /// Gets or sets the weekly schedule options. + /// + public WeeklyScheduleOptions WeeklyScheduleOptions { get; set; } + + /// + /// The create advanced schedule. + /// + /// + /// The . + /// + public AdvancedSchedule GetAdvancedSchedule() + { + if (this.AdvancedScheduleIsNull(this)) + { + return null; + } + + var advancedSchedule = new AdvancedSchedule() + { + WeekDays = this.WeeklyScheduleOptions == null ? null : this.WeeklyScheduleOptions.DaysOfWeek, + MonthDays = (this.MonthlyScheduleOptions == null || this.MonthlyScheduleOptions.DaysOfMonth == null) ? null : this.MonthlyScheduleOptions.DaysOfMonth.Select(v => Convert.ToInt32(v)).ToList(), + MonthlyOccurrences = (this.MonthlyScheduleOptions == null || this.MonthlyScheduleOptions.DayOfWeek == null) + ? null + : new AdvancedScheduleMonthlyOccurrence[] + { + new AdvancedScheduleMonthlyOccurrence() + { + Day = this.MonthlyScheduleOptions.DayOfWeek.Day, + Occurrence = this.GetDayOfWeekOccurrence(this.MonthlyScheduleOptions.DayOfWeek.Occurrence) + } + } + }; + + return advancedSchedule; + } + + /// + /// Gets or sets the schedule time zone. + /// + public string TimeZone { get; set; } + + #endregion Public Properties + + #region Private Methods + + /// + /// The is null or empty list. + /// + /// + /// The list. + /// + /// + /// + /// + /// The . + /// + private bool IsNullOrEmptyList(IList list) + { + return list == null || list.Count == 0; + } + + /// + /// The is monthly occurrence null. + /// + /// + /// The advanced schedule. + /// + /// + /// The . + /// + private bool IsMonthlyOccurrenceNull(Azure.Management.Automation.Models.AdvancedSchedule advancedSchedule) + { + return advancedSchedule == null || this.IsNullOrEmptyList(advancedSchedule.MonthlyOccurrences); + } + + /// + /// The advanced schedule is null. + /// + /// + /// The schedule. + /// + /// + /// The . + /// + private bool AdvancedScheduleIsNull(Schedule schedule) + { + return schedule.WeeklyScheduleOptions == null + && schedule.MonthlyScheduleOptions == null; + } + + /// + /// The get day of week occurrence. + /// + /// + /// The day of week occurrence. + /// + /// + /// The . + /// + private int? GetDayOfWeekOccurrence(string dayOfWeekOccurrence) + { + if (string.IsNullOrWhiteSpace(dayOfWeekOccurrence)) + { + return null; + } + + return Convert.ToInt32(Enum.Parse(typeof(DayOfWeekOccurrence), dayOfWeekOccurrence)); + } + + /// + /// The create weekly schedule options. + /// + /// + /// The schedule. + /// + /// + /// The . + /// + private WeeklyScheduleOptions CreateWeeklyScheduleOptions(Microsoft.Azure.Management.Automation.Models.Schedule schedule) + { + return schedule.Properties.AdvancedSchedule == null + ? null + : new WeeklyScheduleOptions() + { + DaysOfWeek = schedule.Properties.AdvancedSchedule.WeekDays + }; + } + + /// + /// The create monthly schedule options. + /// + /// + /// The schedule. + /// + /// + /// The . + /// + private MonthlyScheduleOptions CreateMonthlyScheduleOptions( + Microsoft.Azure.Management.Automation.Models.Schedule schedule) + { + return schedule.Properties.AdvancedSchedule == null + || (schedule.Properties.AdvancedSchedule.MonthDays == null && schedule.Properties.AdvancedSchedule.MonthlyOccurrences == null) + ? null + : new MonthlyScheduleOptions() + { + DaysOfMonth = this.GetDaysOfMonth(schedule.Properties.AdvancedSchedule.MonthDays), + DayOfWeek = this.IsMonthlyOccurrenceNull(schedule.Properties.AdvancedSchedule) + ? null + : new DayOfWeek() + { + Day = schedule.Properties.AdvancedSchedule.MonthlyOccurrences.First().Day, + Occurrence = this.GetDayOfWeekOccurrence(schedule.Properties.AdvancedSchedule.MonthlyOccurrences.First().Occurrence) + } + }; + } + + /// + /// The get day of week occurrence. + /// + /// + /// The day of week occurrence. + /// + /// + /// The . + /// + private string GetDayOfWeekOccurrence(int? dayOfWeekOccurrence) + { + return dayOfWeekOccurrence.HasValue + ? Enum.GetName(typeof(DayOfWeekOccurrence), dayOfWeekOccurrence) + : null; + } + + /// + /// The get days of month. + /// + /// + /// The days of month. + /// + /// + /// The . + /// + private IList GetDaysOfMonth(IList daysOfMonth) + { + return daysOfMonth.Select(value => (DaysOfMonth)value).ToList(); + } + + private static DateTimeOffset? AdjustOffset(DateTimeOffset? dateTimeOffset, double offsetMinutes) + { + if (dateTimeOffset.HasValue) + { + return AdjustOffset(dateTimeOffset.Value, offsetMinutes); + } + + return null; + } + + private static DateTimeOffset AdjustOffset(DateTimeOffset dateTimeOffset, double offsetMinutes) + { + var timeSpan = TimeSpan.FromMinutes(offsetMinutes); + return dateTimeOffset.ToOffset(timeSpan); + } + + #endregion Private Methods } } diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/ScheduleFrequency.cs b/src/ResourceManager/Automation/Commands.Automation/Model/ScheduleFrequency.cs index 509442928739..385463133740 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Model/ScheduleFrequency.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Model/ScheduleFrequency.cs @@ -4,6 +4,8 @@ public enum ScheduleFrequency { Onetime, Day, - Hour + Hour, + Week, + Month, } } diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/WeeklyScheduleOptions.cs b/src/ResourceManager/Automation/Commands.Automation/Model/WeeklyScheduleOptions.cs new file mode 100644 index 000000000000..63c7e05596b6 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Model/WeeklyScheduleOptions.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + public class WeeklyScheduleOptions + { + /// + /// Gets or sets the schedule days of the week. + /// + public IList DaysOfWeek { get; set; } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs index 68a054224f0c..0df53fa8648f 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18449 +// Runtime Version:4.0.30319.34014 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -429,6 +429,15 @@ internal static string ModuleNotFound { } } + /// + /// Looks up a localized string similar to For monthly occurrence, both day of week and occurrence need to be specified.. + /// + internal static string MonthlyScheduleNeedsDayOfWeekAndOccurrence { + get { + return ResourceManager.GetString("MonthlyScheduleNeedsDayOfWeekAndOccurrence", resourceCulture); + } + } + /// /// Looks up a localized string similar to A node configuration already exists. Specify the parameter to force an overwrite.. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx index 176debb5b9aa..8f0239304fda 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx @@ -439,4 +439,8 @@ "Job terminal state : Id {0}, state {1}, time {2}" + + For monthly occurrence, both day of week and occurrence need to be specified. + Automation + \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation/packages.config b/src/ResourceManager/Automation/Commands.Automation/packages.config index 5c5832385ce3..2cd436ec4581 100644 --- a/src/ResourceManager/Automation/Commands.Automation/packages.config +++ b/src/ResourceManager/Automation/Commands.Automation/packages.config @@ -3,7 +3,7 @@ - + diff --git a/src/ServiceManagement/Automation/Commands.Automation/Model/Schedule.cs b/src/ServiceManagement/Automation/Commands.Automation/Model/Schedule.cs index 773ba84a798f..1d8b5183f284 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Model/Schedule.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Model/Schedule.cs @@ -48,7 +48,7 @@ public Schedule(string automationAccountName, WindowsAzure.Management.Automation } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public Schedule() {