Skip to content

Commit

Permalink
Test removing automapper (Azure#21135)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoriZC authored Mar 7, 2023
1 parent b9d947b commit bdb97bf
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 57 deletions.
3 changes: 1 addition & 2 deletions src/Monitor/Monitor/Az.Monitor.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ DotNetFrameworkVersion = '4.7.2'
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.11.2'; })

# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = 'Microsoft.Azure.Management.Monitor.dll',
'Microsoft.Azure.PowerShell.AutoMapper.dll',
RequiredAssemblies = 'Microsoft.Azure.Management.Monitor.dll',
'ActivityLogAlert.Autorest\bin\Az.ActivityLogAlert.private.dll',
'DiagnosticSetting.Autorest\bin\Az.DiagnosticSetting.private.dll',
'ScheduledQueryRule.Autorest\bin\Az.ScheduledQueryRule.private.dll',
Expand Down
1 change: 0 additions & 1 deletion src/Monitor/Monitor/Monitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Monitor" Version="0.28.0-preview" />
<PackageReference Include="Microsoft.Azure.PowerShell.AutoMapper" Version="6.2.2" />
</ItemGroup>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., build.proj))\src\Az.Post.props" />
Expand Down
14 changes: 14 additions & 0 deletions src/Monitor/Monitor/OutputClasses/PSMonitorPrivateLinkScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------

using System.Collections.Generic;
using Microsoft.Azure.Management.Monitor.Models;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Insights.OutputClasses
Expand All @@ -34,6 +35,19 @@ public PSMonitorPrivateLinkScope() { }
this.ProvisioningState = provisioningState;
}

internal static PSMonitorPrivateLinkScope ToPSMonitorPrivateLinkScope(AzureMonitorPrivateLinkScope scope)
{
return new PSMonitorPrivateLinkScope
{
Id = scope.Id,
Name = scope.Name,
Type = scope.Type,
Location = scope.Location,
Tags = scope.Tags,
ProvisioningState = scope.ProvisioningState
};
}

/// <summary>
/// Gets azure resource Id
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// ----------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Net.Mail;
using Microsoft.Azure.Management.Monitor.Models;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Insights.OutputClasses
Expand Down Expand Up @@ -57,5 +59,17 @@ public class PSMonitorPrivateLinkScopedResource
/// </summary>
[JsonProperty(PropertyName = "properties.provisioningState")]
public string ProvisioningState { get; private set; }

internal static PSMonitorPrivateLinkScopedResource ToPSMonitorPrivateLinkScopedResource(ScopedResource scope)
{
return new PSMonitorPrivateLinkScopedResource
{
Id = scope.Id,
Name = scope.Name,
Type = scope.Type,
LinkedResourceId = scope.LinkedResourceId,
ProvisioningState = scope.ProvisioningState
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Monitor.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.Azure.Commands.Insights.Utils;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Microsoft.Azure.Commands.Insights.OutputClasses;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.Azure.Commands.Insights.Utils;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System.Linq;

Expand Down Expand Up @@ -72,14 +71,14 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopes
.ListByResourceGroupWithHttpMessagesAsync(this.ResourceGroupName)
.Result;
WriteObject(response.Body.Select(scope => PSMapper.Instance.Map<PSMonitorPrivateLinkScope>(scope)).ToList(), true);
WriteObject(response.Body.Select(scope => PSMonitorPrivateLinkScope.ToPSMonitorPrivateLinkScope(scope)).ToList(), true);
}
else
{
var response = this.MonitorManagementClient
.PrivateLinkScopes.ListWithHttpMessagesAsync()
.Result;
WriteObject(response.Body.Select(scope => PSMapper.Instance.Map<PSMonitorPrivateLinkScope>(scope)).ToList(), true);
WriteObject(response.Body.Select(scope => PSMonitorPrivateLinkScope.ToPSMonitorPrivateLinkScope(scope)).ToList(), true);
}
}
else if (ParameterSetName.Equals(ByResourceNameParameterSet) || ParameterSetName.Equals(ResourceId))
Expand All @@ -95,7 +94,7 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopes
.GetWithHttpMessagesAsync(this.ResourceGroupName, this.Name)
.Result;
WriteObject(PSMapper.Instance.Map<PSMonitorPrivateLinkScope>(response.Body));
WriteObject(PSMonitorPrivateLinkScope.ToPSMonitorPrivateLinkScope(response.Body));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Microsoft.Azure.Commands.Insights.OutputClasses;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.Azure.Commands.Insights.Utils;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System.Linq;

Expand Down Expand Up @@ -98,15 +97,15 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopedResources
.ListByPrivateLinkScopeWithHttpMessagesAsync(this.ResourceGroupName, this.ScopeName)
.Result;
WriteObject(response.Body.Select(scope => PSMapper.Instance.Map<PSMonitorPrivateLinkScopedResource>(scope)).ToList(), true);
WriteObject(response.Body.Select(scope => PSMonitorPrivateLinkScopedResource.ToPSMonitorPrivateLinkScopedResource(scope)).ToList(), true);
}
else if (this.IsParameterBound(c => c.Name))
{
var response = this.MonitorManagementClient
.PrivateLinkScopedResources
.GetWithHttpMessagesAsync(this.ResourceGroupName, this.ScopeName, this.Name)
.Result;
WriteObject(PSMapper.Instance.Map<PSMonitorPrivateLinkScopedResource>(response.Body));
WriteObject(PSMonitorPrivateLinkScopedResource.ToPSMonitorPrivateLinkScopedResource(response.Body));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using System.Management.Automation;
using Microsoft.Azure.Commands.Insights.OutputClasses;
using Microsoft.Azure.Management.Monitor.Models;
using Microsoft.Azure.Commands.Insights.Utils;
using System.Linq;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

Expand Down Expand Up @@ -67,7 +66,7 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopes
.CreateOrUpdateWithHttpMessagesAsync(this.ResourceGroupName, this.Name, payLoad)
.Result;
WriteObject(PSMapper.Instance.Map<PSMonitorPrivateLinkScope>(response.Body));
WriteObject(PSMonitorPrivateLinkScope.ToPSMonitorPrivateLinkScope(response.Body));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System.Management.Automation;
using Microsoft.Azure.Commands.Insights.OutputClasses;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.Azure.Commands.Insights.Utils;
using Microsoft.Azure.Management.Monitor.Models;

namespace Microsoft.Azure.Commands.Insights.PrivateLinkScopes
Expand Down Expand Up @@ -56,7 +55,7 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopedResources
.CreateOrUpdateWithHttpMessagesAsync(this.ResourceGroupName, this.ScopeName, this.Name, this.LinkedResourceId)
.Result;
WriteObject(PSMapper.Instance.Map<PSMonitorPrivateLinkScopedResource>(response.Body));
WriteObject(PSMonitorPrivateLinkScopedResource.ToPSMonitorPrivateLinkScopedResource(response.Body));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Monitor.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.Azure.Commands.Insights.Utils;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -71,7 +70,7 @@ protected override void ProcessRecordInternal()
.PrivateLinkScopes
.UpdateTagsWithHttpMessagesAsync(this.ResourceGroupName, this.Name, this.Tags.ToDictionary(s => s.Split(':')[0], s => s.Split(':')[1]))
.Result;
WriteObject(PSMapper.Instance.Map<PSMonitorPrivateLinkScope>(response.Body));
WriteObject(PSMonitorPrivateLinkScope.ToPSMonitorPrivateLinkScope(response.Body));
}
}
}
Expand Down
40 changes: 0 additions & 40 deletions src/Monitor/Monitor/Utils/PSMapper.cs

This file was deleted.

0 comments on commit bdb97bf

Please sign in to comment.