Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
2ca81d9
move mgmt test classes into mgmt
ArcturusZhang Oct 10, 2024
2c3d949
some in progress changes
ArcturusZhang Oct 11, 2024
30fe506
wip, now the new provider could generate those methods
ArcturusZhang Oct 11, 2024
1553bc9
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 11, 2024
066cd2d
follow up
ArcturusZhang Oct 11, 2024
3a03f71
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 14, 2024
6f25ddb
a few progress on creating id for a resource
ArcturusZhang Oct 14, 2024
d0d5df2
a few update
ArcturusZhang Oct 14, 2024
d209e5a
add get resource statement
ArcturusZhang Oct 14, 2024
1ac3fe2
add implementation for normal operations
ArcturusZhang Oct 16, 2024
36685a3
implmeent some bodies
ArcturusZhang Oct 16, 2024
834618d
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 16, 2024
ad43b46
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Oct 17, 2024
403e9ab
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Oct 17, 2024
77d3ebf
some more progress
ArcturusZhang Oct 17, 2024
ce40019
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Oct 21, 2024
64824ce
fix the scope issue
ArcturusZhang Oct 21, 2024
33bfeca
fix another scope path issue
ArcturusZhang Oct 21, 2024
f88e7c1
enable generation for collections
ArcturusZhang Oct 21, 2024
e0efd6e
implement part of the resource collection methods
ArcturusZhang Oct 21, 2024
fdeb1b0
fix inline parameter issue
ArcturusZhang Oct 21, 2024
ee9c3d8
some updates with issues
ArcturusZhang Oct 21, 2024
123c66c
fix the scope issue
ArcturusZhang Oct 22, 2024
12efc8e
fix isuses in mgmttestconfiguration
ArcturusZhang Oct 23, 2024
f1273f0
fix casing and empty lines
ArcturusZhang Oct 23, 2024
4576226
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 31, 2024
9cfffd1
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 31, 2024
48f7f2f
honor the skipped operation config
ArcturusZhang Oct 31, 2024
3894a9b
regen
ArcturusZhang Nov 4, 2024
2cf792d
regen
ArcturusZhang Nov 4, 2024
2931a53
implement the extension operation samples
ArcturusZhang Nov 4, 2024
010f4cf
implement the property bag part 1
ArcturusZhang Nov 5, 2024
8468e13
implement the property bag part 2
ArcturusZhang Nov 5, 2024
600b4d0
remove the configureawait part
ArcturusZhang Nov 5, 2024
d1d9e0d
fix the null value issue in code model converter
ArcturusZhang Nov 5, 2024
e65f290
fix a case in resourcemanager
ArcturusZhang Nov 5, 2024
f5c2441
fix some issues found in real rps
ArcturusZhang Nov 5, 2024
e17b225
find another case that has configureawait
ArcturusZhang Nov 5, 2024
7936159
remove useless code
ArcturusZhang Nov 5, 2024
7461fff
more removals
ArcturusZhang Nov 5, 2024
c032d67
adjust namespaces
ArcturusZhang Nov 5, 2024
441dde0
clean up
ArcturusZhang Nov 5, 2024
c323542
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 6, 2024
c5704f9
refactor
ArcturusZhang Nov 6, 2024
fbf2968
more refactor
ArcturusZhang Nov 6, 2024
bf49918
regen
ArcturusZhang Nov 6, 2024
ad7549e
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Nov 11, 2024
9d7e62c
fix some more issues
ArcturusZhang Nov 11, 2024
97762f3
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Nov 12, 2024
855d575
fix userassignedidentity
ArcturusZhang Nov 12, 2024
8180473
add some notes
ArcturusZhang Nov 12, 2024
5027003
fix the optional parameter issue and regen
ArcturusZhang Nov 13, 2024
f1210ae
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 13, 2024
9ce9211
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 15, 2024
75098c2
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 21, 2024
c36dc84
fix the armclient issue
ArcturusZhang Nov 21, 2024
642a3bd
fix some minor issues in code
ArcturusZhang Nov 21, 2024
0754dde
regen
ArcturusZhang Nov 21, 2024
0e8aac7
resolve comments
ArcturusZhang Nov 22, 2024
f861682
refine
ArcturusZhang Nov 22, 2024
1f13f5b
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 25, 2024
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
Prev Previous commit
Next Next commit
a few update
  • Loading branch information
ArcturusZhang committed Oct 14, 2024
commit d0d5df2c1a203323666945210fc8ab92a930441c
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ private static ValueExpression GetExpressionForFrameworkType(Type frameworkType,
return frameworkType.IsValueType ? Default.CastTo(frameworkType) : Null.CastTo(frameworkType);
}

public static ValueExpression GetExpression(CSharpType type, InputExampleValue value)
{
return GetExpression(type, value, SerializationFormat.Default);
}
public static ValueExpression GetExpression(CSharpType type, InputExampleValue? value)
=> value != null ?
GetExpression(type, value, SerializationFormat.Default) :
Default.CastTo(type);

public static ValueExpression GetExpression(InputExampleParameterValue exampleParameterValue, SerializationFormat serializationFormat)
{
Expand Down
36 changes: 27 additions & 9 deletions src/AutoRest.CSharp/Mgmt/Output/Samples/NewMgmtSampleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using AutoRest.CSharp.Output.Models.Serialization;
using AutoRest.CSharp.Output.Models.Shared;
using AutoRest.CSharp.Output.Models.Types;
using AutoRest.CSharp.Utilities;
using Azure.Core;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
Expand Down Expand Up @@ -58,7 +59,7 @@ private MethodBodyStatement BuildSampleMethodBody(MgmtOperationSample sample, bo
var statements = new List<MethodBodyStatement>()
{
new SingleLineCommentStatement($"Generated from example definition: {sample.ExampleFilepath}"),
new SingleLineCommentStatement($"this example is just showing the usage of \"{sample.OperationId}\" operation, for the dependent resource, they will have to be created separately."),
new SingleLineCommentStatement($"this example is just showing the usage of \"{sample.OperationId}\" operation, for the dependent resources, they will have to be created separately."),
EmptyLine,
new SingleLineCommentStatement("get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line"),
Declare(typeof(TokenCredential), "cred", new FormattableStringToExpression($"new DefaultAzureCredential()"), out var cred), // this project does not use Azure.Identity as a dependency, therefore this is the only way to write this.
Expand Down Expand Up @@ -125,19 +126,15 @@ private MethodBodyStatement BuildGetResourceStatementFromResource(Resource carri

private MethodBodyStatement BuildCreateResourceIdentifier(Resource resource, OperationExample example, out TypedValueExpression id)
{
var resourcePath = resource.RequestPath;
var scopePath = resourcePath.GetScopePath();
var scopePath = resource.RequestPath.GetScopePath();
if (scopePath.IsRawParameterizedScope())
{
throw new NotImplementedException();
return BuildCreateResourceIdentifierForScopePath(example, resource, out id);
}
else
{
return BuildCreateResourceIdentifierForUsualPath(example, resource, out id);
}
//var idParts = example.ComposeResourceIdentifierParts();
//var statement = Declare(typeof(ResourceIdentifier), "id", new InvokeStaticMethodExpression(resource.Type, resource.CreateResourceIdentifierMethod.Signature.Name, idParts), out id);
//return statement;
}

private MethodBodyStatement BuildCreateResourceIdentifierForUsualPath(OperationExample example, Resource resource, out TypedValueExpression id)
Expand All @@ -155,12 +152,33 @@ private MethodBodyStatement BuildCreateResourceIdentifierForUsualPath(OperationE
foreach (var reference in myRefs.Take(resourceRefCount))
{
var exampleValue = example.FindInputExampleValueFromReference(reference.Reference);
var referenceStatement = Declare(reference.Type, reference.ReferenceName, exampleValue != null ? ExampleValueSnippets.GetExpression(reference.Type, exampleValue) : Default, out var referenceVar);
var referenceStatement = Declare(reference.Type, reference.ReferenceName, ExampleValueSnippets.GetExpression(reference.Type, exampleValue), out var referenceVar);
statements.Add(referenceStatement);
references.Add(referenceVar);
}

var idStatement = Declare(typeof(ResourceIdentifier), "id", new InvokeStaticMethodExpression(resource.Type, resource.CreateResourceIdentifierMethod.Signature.Name, references), out id);
var idStatement = Declare(typeof(ResourceIdentifier), $"{resource.Type.Name}Id".ToVariableName(), new InvokeStaticMethodExpression(resource.Type, resource.CreateResourceIdentifierMethod.Signature.Name, references), out id);
statements.Add(idStatement);

return statements;
}

private MethodBodyStatement BuildCreateResourceIdentifierForScopePath(OperationExample example, Resource resource, out TypedValueExpression id)
{
var statements = new List<MethodBodyStatement>();
var operationScopePath = example.RequestPath.GetScopePath();
var operationTrimeedPath = example.RequestPath.TrimScope();

var scopeValues = new List<ValueExpression>();
foreach (var reference in operationScopePath.Where(segment => segment.IsReference))
{
var exampleValue = example.FindInputExampleValueFromReference(reference.Reference);
var scopeRefStatement = Declare(reference.Type, reference.ReferenceName, ExampleValueSnippets.GetExpression(reference.Type, exampleValue), out var scopeRefVar);
statements.Add(scopeRefStatement);
scopeValues.Add(scopeRefVar);
}

var idStatement = Declare(typeof(ResourceIdentifier), $"{resource.Type.Name}Id".ToVariableName(), new InvokeStaticMethodExpression(resource.Type, resource.CreateResourceIdentifierMethod.Signature.Name, scopeValues), out id);
statements.Add(idStatement);

return statements;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using NUnit.Framework;

namespace MgmtMockAndSample.Samples
{
public partial class Sample_DeletedManagedHsmResource
{
[Test]
[Ignore("Only validating compilation of examples")]
public async Task Get_RetrieveADeletedManagedHSM()
{
// Generated from example definition:
// this example is just showing the usage of "ManagedHsms_GetDeleted" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this DeletedManagedHsmResource created on azure
// for more information of creating DeletedManagedHsmResource, please refer to the document of DeletedManagedHsmResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
AzureLocation location = new AzureLocation("westus");
string name = "hsm1";
ResourceIdentifier deletedManagedHsmResourceId = DeletedManagedHsmResource.CreateResourceIdentifier(subscriptionId, location, name);
}

[Test]
[Ignore("Only validating compilation of examples")]
public async Task PurgeDeleted_PurgeAManagedHSMPool()
{
// Generated from example definition:
// this example is just showing the usage of "ManagedHsms_PurgeDeleted" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this DeletedManagedHsmResource created on azure
// for more information of creating DeletedManagedHsmResource, please refer to the document of DeletedManagedHsmResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
AzureLocation location = new AzureLocation("westus");
string name = "hsm1";
ResourceIdentifier deletedManagedHsmResourceId = DeletedManagedHsmResource.CreateResourceIdentifier(subscriptionId, location, name);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using NUnit.Framework;

namespace MgmtMockAndSample.Samples
{
public partial class Sample_DeletedVaultResource
{
[Test]
[Ignore("Only validating compilation of examples")]
public async Task Get_RetrieveADeletedVault()
{
// Generated from example definition:
// this example is just showing the usage of "Vaults_GetDeleted" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this DeletedVaultResource created on azure
// for more information of creating DeletedVaultResource, please refer to the document of DeletedVaultResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
AzureLocation location = new AzureLocation("westus");
string vaultName = "sample-vault";
ResourceIdentifier deletedVaultResourceId = DeletedVaultResource.CreateResourceIdentifier(subscriptionId, location, vaultName);
}

[Test]
[Ignore("Only validating compilation of examples")]
public async Task PurgeDeleted_PurgeADeletedVault()
{
// Generated from example definition:
// this example is just showing the usage of "Vaults_PurgeDeleted" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this DeletedVaultResource created on azure
// for more information of creating DeletedVaultResource, please refer to the document of DeletedVaultResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
AzureLocation location = new AzureLocation("westus");
string vaultName = "sample-vault";
ResourceIdentifier deletedVaultResourceId = DeletedVaultResource.CreateResourceIdentifier(subscriptionId, location, vaultName);
}
}
}
Loading