Skip to content

New sdk stacks #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
42 changes: 42 additions & 0 deletions src/Resources/ResourceManager/Comparers/NewChangeTypeComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.NewComparers
{
using Management.Resources.Models;
using System.Collections.Generic;

public class ChangeTypeComparer : IComparer<ChangeType>
{
private static readonly IReadOnlyDictionary<ChangeType, int> WeightsByChangeType =
new Dictionary<ChangeType, int>
{
[ChangeType.Delete] = 0,
[ChangeType.Create] = 1,
[ChangeType.Deploy] = 2,
[ChangeType.Modify] = 3,
[ChangeType.Unsupported] = 4,
[ChangeType.NoChange] = 5,
[ChangeType.Ignore] = 6,
};

public int Compare(ChangeType first, ChangeType second)
{
return WeightsByChangeType[first] - WeightsByChangeType[second];
}
}
}



40 changes: 40 additions & 0 deletions src/Resources/ResourceManager/Comparers/NewPSChangeTypeComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ----------------------------------------------------------------------------------
//
// 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.Collections.Generic;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.NewComparers
{
public class PSChangeTypeComparer : IComparer<PSChangeType>
{
private static readonly IReadOnlyDictionary<PSChangeType, int> WeightsByPSChangeType =
new Dictionary<PSChangeType, int>
{
[PSChangeType.Delete] = 0,
[PSChangeType.Create] = 1,
[PSChangeType.Deploy] = 2,
[PSChangeType.Modify] = 3,
[PSChangeType.Unsupported] = 4,
[PSChangeType.NoEffect] = 5,
[PSChangeType.NoChange] = 6,
[PSChangeType.Ignore] = 7,
};

public int Compare(PSChangeType first, PSChangeType second)
{
return WeightsByPSChangeType[first] - WeightsByPSChangeType[second];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.NewComparers
{
using Management.Resources.Models;
using System.Collections.Generic;

public class PropertyChangeTypeComparer : IComparer<PropertyChangeType>
{
private static readonly IReadOnlyDictionary<PropertyChangeType, int> WeightsByPropertyChangeType =
new Dictionary<PropertyChangeType, int>
{
[PropertyChangeType.Delete] = 0,
[PropertyChangeType.Create] = 1,
// Modify and Array are set to have the same weight by intention.
[PropertyChangeType.Modify] = 2,
[PropertyChangeType.Array] = 2,
[PropertyChangeType.NoEffect] = 3,
};

public int Compare(PropertyChangeType first, PropertyChangeType second)
{
return WeightsByPropertyChangeType[first] - WeightsByPropertyChangeType[second];
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components
{
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Azure.Management.Resources.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
Expand Down
100 changes: 100 additions & 0 deletions src/Resources/ResourceManager/Extensions/NewChangeTypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.NewExtensions
{
using Formatters;
using Management.Resources.Models;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
using System;
using System.Collections.Generic;

public static class ChangeTypeExtensions
{
private static readonly IReadOnlyDictionary<ChangeType, Color> ColorsByChangeType =
new Dictionary<ChangeType, Color>
{
[ChangeType.NoChange] = Color.Reset,
[ChangeType.Ignore] = Color.Gray,
[ChangeType.Deploy] = Color.Blue,
[ChangeType.Create] = Color.Green,
[ChangeType.Delete] = Color.Orange,
[ChangeType.Modify] = Color.Purple,
[ChangeType.Unsupported] = Color.Gray,
};

private static readonly IReadOnlyDictionary<ChangeType, Symbol> SymbolsByChangeType =
new Dictionary<ChangeType, Symbol>
{
[ChangeType.NoChange] = Symbol.Equal,
[ChangeType.Ignore] = Symbol.Asterisk,
[ChangeType.Deploy] = Symbol.ExclamationPoint,
[ChangeType.Create] = Symbol.Plus,
[ChangeType.Delete] = Symbol.Minus,
[ChangeType.Modify] = Symbol.Tilde,
[ChangeType.Unsupported] = Symbol.Cross,
};

private static readonly IReadOnlyDictionary<ChangeType, PSChangeType> PSChangeTypesByChangeType =
new Dictionary<ChangeType, PSChangeType>
{
[ChangeType.NoChange] = PSChangeType.NoChange,
[ChangeType.Ignore] = PSChangeType.Ignore,
[ChangeType.Deploy] = PSChangeType.Deploy,
[ChangeType.Create] = PSChangeType.Create,
[ChangeType.Delete] = PSChangeType.Delete,
[ChangeType.Modify] = PSChangeType.Modify,
[ChangeType.Unsupported] = PSChangeType.Unsupported,
};

public static Color ToColor(this ChangeType changeType)
{
bool success = ColorsByChangeType.TryGetValue(changeType, out Color colorCode);

if (!success)
{
throw new ArgumentOutOfRangeException(nameof(changeType));
}

return colorCode;
}

public static Symbol ToSymbol(this ChangeType changeType)
{
bool success = SymbolsByChangeType.TryGetValue(changeType, out Symbol symbol);

if (!success)
{
throw new ArgumentOutOfRangeException(nameof(changeType));
}

return symbol;
}

public static PSChangeType ToPSChangeType(this ChangeType changeType)
{
bool success = PSChangeTypesByChangeType.TryGetValue(changeType, out PSChangeType psChangeType);

if (!success)
{
throw new ArgumentOutOfRangeException(nameof(changeType));
}

return psChangeType;
}

}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.NewExtensions
{
using Formatters;
using Management.Resources.Models;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
using System;
using System.Collections.Generic;

public static class PropertyChangeTypeExtensions
{
private static readonly IReadOnlyDictionary<PropertyChangeType, Color> ColorsByPropertyChangeType =
new Dictionary<PropertyChangeType, Color>
{
[PropertyChangeType.Create] = Color.Green,
[PropertyChangeType.Delete] = Color.Orange,
[PropertyChangeType.Modify] = Color.Purple,
[PropertyChangeType.Array] = Color.Purple,
[PropertyChangeType.NoEffect] = Color.Gray,
};

private static readonly IReadOnlyDictionary<PropertyChangeType, Symbol> SymbolsByPropertyChangeType =
new Dictionary<PropertyChangeType, Symbol>
{
[PropertyChangeType.Create] = Symbol.Plus,
[PropertyChangeType.Delete] = Symbol.Minus,
[PropertyChangeType.Modify] = Symbol.Tilde,
[PropertyChangeType.Array] = Symbol.Tilde,
[PropertyChangeType.NoEffect] = Symbol.Cross,
};

private static readonly IReadOnlyDictionary<PropertyChangeType, PSChangeType> PSChangeTypesByPropertyChangeType =
new Dictionary<PropertyChangeType, PSChangeType>
{
[PropertyChangeType.Create] = PSChangeType.Create,
[PropertyChangeType.Delete] = PSChangeType.Delete,
[PropertyChangeType.Modify] = PSChangeType.Modify,
[PropertyChangeType.Array] = PSChangeType.Modify,
[PropertyChangeType.NoEffect] = PSChangeType.NoEffect,
};

public static Color ToColor(this PropertyChangeType propertyChangeType)
{
bool success = ColorsByPropertyChangeType.TryGetValue(propertyChangeType, out Color colorCode);

if (!success)
{
throw new ArgumentOutOfRangeException(nameof(propertyChangeType));
}

return colorCode;
}

public static Symbol ToSymbol(this PropertyChangeType propertyChangeType)
{
bool success = SymbolsByPropertyChangeType.TryGetValue(propertyChangeType, out Symbol symbol);

if (!success)
{
throw new ArgumentOutOfRangeException(nameof(propertyChangeType));
}

return symbol;
}

public static PSChangeType ToPSChangeType(this PropertyChangeType propertyChangeType)
{
bool success = PSChangeTypesByPropertyChangeType.TryGetValue(propertyChangeType, out PSChangeType changeType);

if (!success)
{
throw new ArgumentOutOfRangeException(nameof(propertyChangeType));
}

return changeType;
}

public static bool IsDelete(this PropertyChangeType propertyChangeType)
{
return propertyChangeType == PropertyChangeType.Delete;
}

public static bool IsCreate(this PropertyChangeType propertyChangeType)
{
return propertyChangeType == PropertyChangeType.Create;
}

public static bool IsModify(this PropertyChangeType propertyChangeType)
{
return propertyChangeType == PropertyChangeType.Modify;
}

public static bool IsArray(this PropertyChangeType propertyChangeType)
{
return propertyChangeType == PropertyChangeType.Array;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Formatters
using System;
using System.Collections.Generic;
using System.Linq;
using Comparers;
using NewComparers;
using NewExtensions;
using Extensions;
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Newtonsoft.Json.Linq;
using Properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.Cmdlet
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Azure.Management.Resources.Models;

public abstract class DeploymentCreateCmdlet: DeploymentWhatIfCmdlet
{
Expand Down Expand Up @@ -83,11 +83,11 @@ protected void ExecuteDeployment()

if (this.DeploymentParameters.ScopeType == DeploymentScopeType.ResourceGroup)
{
this.WriteObject(this.ResourceManagerSdkClient.ExecuteResourceGroupDeployment(this.DeploymentParameters));
this.WriteObject(this.NewResourceManagerSdkClient.ExecuteResourceGroupDeployment(this.DeploymentParameters));
}
else
{
this.WriteObject(this.ResourceManagerSdkClient.ExecuteDeployment(this.DeploymentParameters));
this.WriteObject(this.NewResourceManagerSdkClient.ExecuteDeployment(this.DeploymentParameters));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected PSWhatIfOperationResult ExecuteWhatIf()
// Write status message.
this.WriteInformation(information, tags);

PSWhatIfOperationResult whatIfResult = ResourceManagerSdkClient.ExecuteDeploymentWhatIf(this.WhatIfParameters);
PSWhatIfOperationResult whatIfResult = NewResourceManagerSdkClient.ExecuteDeploymentWhatIf(this.WhatIfParameters);

// Clear status before returning result.
this.WriteInformation(clearInformation, tags);
Expand Down
Loading