Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@
<Reference Include="Microsoft.Azure.Common.NetFramework">
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.Automation">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Automation.2.0.0\lib\net40\Microsoft.Azure.Management.Automation.dll</HintPath>
<Reference Include="Microsoft.Azure.Management.Automation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Automation.2.0.1\lib\net40\Microsoft.Azure.Management.Automation.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -130,8 +131,10 @@
<HintPath>..\..\..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Xml" /> <Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath> <Private>True</Private>
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\xunit.assert.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.assert.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -44,7 +45,7 @@ public void SetupTest()
}

[TestMethod]
public void NewAzureAutomationRunbookByNameSuccessfull()
public void NewAzureAutomationRunbookByNameSuccessful()
{
// Setup
string resourceGroupName = "resourceGroup";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<package id="Hyak.Common" version="1.0.3" targetFramework="net45" />
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Automation" version="2.0.1" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Test.Framework" version="1.0.5945.28173-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5945.28173-prerelease" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ public class ImportAzureAutomationRunbook : AzureAutomationBaseCmdlet
/// Gets or sets the runbook version type
/// </summary>
[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; }

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ public class NewAzureAutomationRunbook : AzureAutomationBaseCmdlet
/// Gets or sets the runbook version type
/// </summary>
[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; }

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -57,6 +61,30 @@ public NewAzureAutomationSchedule()
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The schedule description.")]
public string Description { get; set; }

/// <summary>
/// Gets or sets the schedule days of the week.
/// </summary>
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByWeekly, Mandatory = false, HelpMessage = "The list of days of week for the weekly schedule.")]
public System.DayOfWeek[] DaysOfWeek { get; set; }

/// <summary>
/// Gets or sets the schedule days of the month.
/// </summary>
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByMonthlyDaysOfMonth, Mandatory = false, HelpMessage = "The list of days of month for the monthly schedule.")]
public DaysOfMonth[] DaysOfMonth { get; set; }

/// <summary>
/// Gets or sets the schedule day of the week.
/// </summary>
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByMonthlyDayOfWeek, Mandatory = false, HelpMessage = "The day of week for the monthly occurrence.")]
public System.DayOfWeek? DayOfWeek { get; set; }

/// <summary>
/// Gets or sets the schedule day of the week.
/// </summary>
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByMonthlyDayOfWeek, Mandatory = false, HelpMessage = "The Occurrence of the week within the month.")]
public DayOfWeekOccurrence DayOfWeekOccurrence { get; set; }

/// <summary>
/// Gets or sets the switch parameter to create a one time schedule.
/// </summary>
Expand All @@ -68,6 +96,9 @@ public NewAzureAutomationSchedule()
/// </summary>
[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; }

/// <summary>
Expand All @@ -84,6 +115,27 @@ public NewAzureAutomationSchedule()
[ValidateRange(1, byte.MaxValue)]
public byte HourInterval { get; set; }

/// <summary>
/// Gets or sets the weekly schedule week interval.
/// </summary>
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByWeekly, Mandatory = true, HelpMessage = "The weekly schedule week interval.")]
[ValidateRange(1, byte.MaxValue)]
public byte WeekInterval { get; set; }

/// <summary>
/// Gets or sets the weekly schedule week interval.
/// </summary>
[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; }

/// <summary>
/// Gets or sets the schedule time zone.
/// </summary>
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The schedule time zone.")]
public string TimeZone { get; set; }

/// <summary>
/// Execute this cmdlet.
/// </summary>
Expand All @@ -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);
}

/// <summary>
/// The validate.
/// </summary>
/// <returns>
/// The <see cref="Schedule"/>.
/// </returns>
/// <exception cref="Exception">
/// throws exception
/// </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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this string to resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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

/// <summary>
/// The is monthly schedule null.
/// </summary>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
private bool IsMonthlyScheduleNull()
{
return this.DaysOfMonth == null && this.DayOfWeek == null && this.DayOfWeekOccurrence == 0;
}

/// <summary>
/// The create weekly schedule model.
/// </summary>
/// <returns>
/// The <see cref="Schedule"/>.
/// </returns>
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;
}
}

/// <summary>
/// The day of week occurrence.
/// </summary>
public enum DayOfWeekOccurrence
{
First = 1,
Second = 2,
Third = 3,
Fourth = 4,
Last = -1
}

/// <summary>
/// The day of week occurrence.
/// </summary>
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
}
}
Loading