Skip to content

Commit

Permalink
New-AzureVm SimpleParameterSet, Strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Dec 6, 2017
1 parent 339519b commit db1f851
Show file tree
Hide file tree
Showing 81 changed files with 3,583 additions and 125 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,5 @@ FakesAssemblies/
/tools/*.dll
*.GhostDoc.xml
pingme.txt
groupMapping*.json
groupMapping*.json
.vscode/
4 changes: 4 additions & 0 deletions setup/azurecmdfiles.wxi
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@
<Component Id="cmp4677B0CE124023330EDD7AA4FECFF45E" Guid="*">
<File Id="fil58F144170E43C2EFEC66E5F3DE2FA977" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.Compute\AzureRM.Compute.psm1" />
</Component>
<Component Id="cmp32CF42EA1F0A7DA716459A5A6A21C24D" Guid="*">
<File Id="fil5AE28BCCEED67270ECF02C93C9688AD5" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.Compute\Microsoft.Azure.Commands.Common.Strategies.dll" />
</Component>
<Component Id="cmpFBB75A5451448B356C97E62D2C6C10A0" Guid="*">
<File Id="fil24BE7D514EE83ED7D31C68CBFFA8FBB8" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.Compute\Microsoft.Azure.Commands.Compute.dll" />
</Component>
Expand Down Expand Up @@ -3148,6 +3151,7 @@
<ComponentRef Id="cmpD2516E302D41812368A84BD6010FB066" />
<ComponentRef Id="cmp594709EB2E69BD7173BC8833BE2061B4" />
<ComponentRef Id="cmp4677B0CE124023330EDD7AA4FECFF45E" />
<ComponentRef Id="cmp32CF42EA1F0A7DA716459A5A6A21C24D" />
<ComponentRef Id="cmpFBB75A5451448B356C97E62D2C6C10A0" />
<ComponentRef Id="cmp1CB1E6D6A2D939FB32D9ACD70681644D" />
<ComponentRef Id="cmpAA00FCFEE63D9A20C2618B36B1848D7C" />
Expand Down
7 changes: 6 additions & 1 deletion src/Common/Commands.Common/AzureLongRunningJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ public static U CopyCmdlet<U>(U cmdlet) where U : AzurePSCmdlet
returnValue.MyInvocation.BoundParameters.Add(parameter.Key, parameter.Value);
}

foreach (var field in returnType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))

foreach (var field in returnType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
field.SafeCopyValue(source: cmdlet, target: returnValue);
}

cmdlet.SafeCopyParameterSet(returnValue);
return returnValue as U;
}

Expand Down Expand Up @@ -829,6 +831,9 @@ private bool InvokeShouldMethodAndWaitForResults(Func<Cmdlet, bool> shouldMethod
}
}

/// <summary>
/// Stop job execution
/// </summary>
public override void StopJob()
{
ShouldMethodStreamItem stream;
Expand Down
24 changes: 24 additions & 0 deletions src/Common/Commands.Common/Extensions/CmdletExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,30 @@ public static void SafeCopyValue<T>(this FieldInfo field, T source, T target)
}
}

/// <summary>
/// Safely copy the selected parameter set from one cmdlet to another
/// </summary>
/// <typeparam name="T">The cmdlet type</typeparam>
/// <param name="source">The cmdlet to copy the parameter set name from</param>
/// <param name="target">The cmdlet to copy to</param>
public static void SafeCopyParameterSet<T>(this T source, T target) where T: AzurePSCmdlet
{
if (source != null && target != null)
{
if (!string.IsNullOrWhiteSpace(source.ParameterSetName))
{
try
{
target.SetParameterSet(source.ParameterSetName);
}
catch
{

}
}
}
}

public static string AsAbsoluteLocation(this string realtivePath)
{
return Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, realtivePath));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5C052681-DA3C-4FEA-8E02-7DFBB2A18B22}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Azure.Commands.Common.Strategies.UnitTest</RootNamespace>
<AssemblyName>Microsoft.Azure.Commands.Common.Strategies.UnitTest</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="TimeSlotTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Commands.Common.Strategies\Commands.Common.Strategies.csproj">
<Project>{eea69772-d41b-482a-9252-2b4595c59e53}</Project>
<Name>Commands.Common.Strategies</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Commands.Common.Strategies.UnitTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Commands.Common.Strategies.UnitTest")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5c052681-da3c-4fea-8e02-7dfbb2a18b22")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.Azure.Commands.Common.Strategies.UnitTest
{
[TestClass]
public class TimeSlotTest
{
[TestMethod]
public void AddTest()
{
var first = new TimeSlot();

Assert.AreEqual(0, first.Duration);
Assert.AreEqual(0, first.TaskCount);
Assert.AreEqual(null, first.Next);

var next = first.AddTask(50);

Assert.AreEqual(50, first.Duration);
Assert.AreEqual(1, first.TaskCount);
Assert.AreEqual(next, first.Next);

Assert.AreEqual(10.0, first.GetTaskProgress(10));

Assert.AreEqual(0, next.Duration);
Assert.AreEqual(0, next.TaskCount);
Assert.AreEqual(null, next.Next);

var next2 = first.AddTask(50);

Assert.AreEqual(50, first.Duration);
Assert.AreEqual(2, first.TaskCount);
Assert.AreEqual(next2, first.Next);
Assert.AreEqual(next, first.Next);

Assert.AreEqual(20.0, first.GetTaskProgress(40));

Assert.AreEqual(0, next2.Duration);
Assert.AreEqual(0, next2.TaskCount);
Assert.AreEqual(null, next2.Next);

var next3 = first.AddTask(30);
Assert.AreEqual(30, first.Duration);
Assert.AreEqual(3, first.TaskCount);
Assert.AreEqual(next3, first.Next);

Assert.AreEqual(3.0, first.GetTaskProgress(9));

Assert.AreEqual(20, next3.Duration);
Assert.AreEqual(2, next3.TaskCount);
Assert.AreEqual(next2, next3.Next);
Assert.AreEqual(next, next3.Next);

Assert.AreEqual(10.0 + 5, first.GetTaskProgress(40));

Assert.AreEqual(0, next2.Duration);
Assert.AreEqual(0, next2.TaskCount);
Assert.AreEqual(null, next2.Next);

var next4 = first.AddTask(75);
Assert.AreEqual(25, next2.Duration);
Assert.AreEqual(1, next2.TaskCount);
Assert.AreEqual(next4, next2.Next);

Assert.AreEqual((30.0 / 4) + (20.0 / 3) + 20, first.GetTaskProgress(70));

Assert.AreEqual(0, next4.Duration);
Assert.AreEqual(0, next4.TaskCount);
Assert.AreEqual(null, next4.Next);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EEA69772-D41B-482A-9252-2B4595C59E53}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Azure.Commands.Common.Strategies</RootNamespace>
<AssemblyName>Microsoft.Azure.Commands.Common.Strategies</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\Package\Debug\ResourceManager\AzureResourceManager\AzureRM.Compute\</OutputPath>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;SIGN</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>MSSharedLibKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.10\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.10\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IReportProgress.cs" />
<Compile Include="IResourceConfig.cs" />
<Compile Include="IResourceConfigVisitor.cs" />
<Compile Include="IResourceStrategy.cs" />
<Compile Include="IShouldProcess.cs" />
<Compile Include="ProgressMap.cs" />
<Compile Include="TimeSlot.cs" />
<Compile Include="StateOperationContext.cs" />
<Compile Include="SyncTaskScheduler.cs" />
<Compile Include="TimeSlotExtensions.cs" />
<Compile Include="UpdateStateExtensions.cs" />
<Compile Include="CreateOrUpdateAsyncParams.cs" />
<Compile Include="EntityConfigExtensions.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="GetStateExtensions.cs" />
<Compile Include="GetAsyncParams.cs" />
<Compile Include="IClient.cs" />
<Compile Include="IEntityConfig.cs" />
<Compile Include="IEntityConfigVisitor.cs" />
<Compile Include="IEntityStrategy.cs" />
<Compile Include="IState.cs" />
<Compile Include="NestedResourceConfigExtensions.cs" />
<Compile Include="ResourceConfigExtensions.cs" />
<Compile Include="StateExtensions.cs" />
<Compile Include="NestedResourceConfig.cs" />
<Compile Include="NestedResourceStrategy.cs" />
<Compile Include="TargetStateExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResourceConfig.cs" />
<Compile Include="ResourceStrategy.cs" />
<Compile Include="State.cs" />
<Compile Include="LocationExtensions.cs" />
<Compile Include="Void.cs" />
</ItemGroup>
<ItemGroup>
<None Include="MSSharedLibKey.snk" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading

0 comments on commit db1f851

Please sign in to comment.