Skip to content
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

Remove dependencies #13113

Merged
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.14.0" />
<PackageReference Include="System.Management.Automation" Version="7.1.0-preview.7" />
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.23-preview" />
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.23-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Description = 'Microsoft Azure PowerShell Predictor: Provide prediction while us
PowerShellVersion = '7.1'

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(@{ModuleName = 'Az'; ModuleVersion = '3.0.0'; })
# RequiredModules = @()

NestedModules = @("Microsoft.Azure.PowerShell.Tools.AzPredictor.dll")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ internal static class AzPredictorConstants
/// <summary>
/// The azure profile directory name.
/// </summary>
// See AzureDirectoryName in https://github.com/Azure/azure-powershell/blob/master/src/Accounts/Authentication/Properties/Resources.resx
public const string AzureProfileDirectoryName = ".Azure";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.PowerShell.Tools.AzPredictor.Profile;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
Expand All @@ -30,40 +29,6 @@ namespace Microsoft.Azure.PowerShell.Tools.AzPredictor
/// </summary>
sealed class AzPredictorTelemetryClient : ITelemetryClient
{
/// <summary>
/// A simple session class that provides neccessary information to get the profile.
/// </summary>
private sealed class TelemetrySession : AzureSession
{
/// <summary>
/// Constructs a new instance of <see cref="TelemetrySession" />
/// </summary>
public TelemetrySession()
{
DataStore = new DiskDataStore();
ProfileDirectory = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
AzPredictorConstants.AzureProfileDirectoryName);
}

/// <inheritdoc/>
public override TraceLevel AuthenticationLegacyTraceLevel
{
get => TraceLevel.Off;
set { }
}

/// <inheritdoc/>
public override TraceListenerCollection AuthenticationTraceListeners => Trace.Listeners;

/// <inheritdoc/>
public override SourceLevels AuthenticationTraceSourceLevel
{
get => SourceLevels.Off;
set { }
}
}

private const string TelemetryEventPrefix = "Az.Tools.Predictor";

/// <inheritdoc/>
Expand All @@ -74,31 +39,6 @@ public override SourceLevels AuthenticationTraceSourceLevel

private readonly TelemetryClient _telemetryClient;

private object lockObject = new object();
private AzurePSDataCollectionProfile _cachedProfile;

private AzurePSDataCollectionProfile DataCollectionProfile
{
get
{
if (_cachedProfile != null)
{
return _cachedProfile;
}

lock (lockObject)
{
if (_cachedProfile == null)
{
var controller = DataCollectionController.Create(new TelemetrySession());
_cachedProfile = controller.GetProfile(() => { });
}

return _cachedProfile;
}
}
}

/// <summary>
/// Constructs a new instance of <see cref="AzPredictorTelemetryClient"/>
/// </summary>
Expand Down Expand Up @@ -255,9 +195,7 @@ public void OnGetSuggestionError(Exception e)
/// <returns>true if allowed</returns>
private bool IsDataCollectionAllowed()
{
if (DataCollectionProfile != null &&
DataCollectionProfile.EnableAzureDataCollection.HasValue &&
DataCollectionProfile.EnableAzureDataCollection.Value)
if (AzurePSDataCollectionProfile.Instance.EnableAzureDataCollection == true)
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/Az.Tools.Predictor/Az.Tools.Predictor/Predictor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Predictor(IList<string> modelPredictions, ParameterValuePredictor paramet
this._parameterValuePredictor = parameterValuePredictor;
this._predictions = new List<Prediction>();

foreach (var predictionTextRaw in modelPredictions)
foreach (var predictionTextRaw in modelPredictions ?? Enumerable.Empty<string>())
{
var predictionText = EscapePredictionText(predictionTextRaw);
Ast ast = Parser.ParseInput(predictionText, out Token[] tokens, out _);
Expand Down
10 changes: 1 addition & 9 deletions tools/Az.Tools.Predictor/build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@

<Target Name="Build">
<PropertyGroup>
<BuildAction Condition="'$(Configuration)' != 'Release'">build</BuildAction>
<BuildAction Condition="'$(Configuration)' == 'Release'">publish</BuildAction>
<BuildAction>build</BuildAction>
</PropertyGroup>
<Message Text="Build $(ModuleName)" />
<MakeDir Directories="$(ArtifactFolder)/$(ModuleName)" />
<Exec Command="dotnet --version" />

<Exec Command="dotnet $(BuildAction) $(ModuleSolutionFile) -c $(Configuration)" />

<ItemGroup>
<PublishedFiles Include="$(ArtifactFolder)/$(ModuleName)/publish/**/*" />
</ItemGroup>

<Move SourceFiles="@(PublishedFiles)" DestinationFiles="@(PublishedFiles->'$(ArtifactFolder)/$(ModuleName)/%(RecursiveDir)%(FileName)%(Extension)')" />
<RemoveDir Directories="$(ArtifactFolder)/$(ModuleName)/publish" Condition="'$(Configuration)' == 'Release'" />
</Target>

<Target Name="Test" DependsOnTargets="Build">
Expand Down