Skip to content
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
10 changes: 5 additions & 5 deletions sdk/resourcemanager/Azure.ResourceManager.Core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ AvailabilitySetOperations availabilitySetOperations = armClient.GetAvailabilityS
AvailabilitySet availabilitySet = await availabilitySetOperations.GetAsync();
```

### `tryGet` and `doesExists` convenience methods
If you are not sure if a resource you want to get exists, or you just want to check if it exists, you can use `tryGet()` or `doesExists()` methods, which can be invoque from any [Resource]Container class.
### `tryGet` and `CheckIfExistss` convenience methods
If you are not sure if a resource you want to get exists, or you just want to check if it exists, you can use `tryGet()` or `CheckIfExistss()` methods, which can be invoque from any [Resource]Container class.

`tryGet()` and `tryGetAsync()` are going to return a null object if the specified resource name or id does not exists. On the other hand, `doesExists()` and `doesExistsAsync()` is going to return a boolean, depending if the specified resource exists.
`tryGet()` and `tryGetAsync()` are going to return a null object if the specified resource name or id does not exists. On the other hand, `CheckIfExistss()` and `CheckIfExistssAsync()` is going to return a boolean, depending if the specified resource exists.

You can find an example for these methods [below](#check-if-resource-group-exists).

Expand Down Expand Up @@ -205,12 +205,12 @@ await resourceGroup.DeleteAsync();
```

### Check if Resource Group exists
```C# Snippet:Readme_DoesExistsRG
```C# Snippet:Readme_CheckIfExistssRG
var armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
string rgName = "myRgName";

var exists = await subscription.GetResourceGroups().DoesExistAsync(rgName);
var exists = await subscription.GetResourceGroups().CheckIfExistsAsync(rgName);

if (exists)
{
Expand Down

Large diffs are not rendered by default.

50 changes: 38 additions & 12 deletions sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,23 @@ protected ArmClient()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ArmClient"/> class.
/// </summary>
/// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
/// <exception cref="ArgumentNullException"> If <see cref="TokenCredential"/> is null. </exception>
public ArmClient(TokenCredential credential)
: this(null, new Uri(DefaultUri), credential, null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ArmClient"/> class.
/// </summary>
/// <param name="credential"> A credential used to authenticate to an Azure Service. </param>
/// <param name="options"> The client parameters to use in these operations. </param>
/// <exception cref="ArgumentNullException"> If <see cref="TokenCredential"/> is null. </exception>
public ArmClient(TokenCredential credential, ArmClientOptions options = default)
public ArmClient(TokenCredential credential, ArmClientOptions options)
: this(null, new Uri(DefaultUri), credential, options)
{
}
Expand Down Expand Up @@ -158,30 +168,46 @@ private Subscription GetDefaultSubscription()
}

/// <summary>
/// Creates a container using the lambda expression passed in.
/// Provides a way to reuse the protected client context.
/// </summary>
/// <typeparam name="T"> The type of container to construct. </typeparam>
/// <param name="func"> The lambda expression to execute. </param>
/// <returns> The container type requested. </returns>
/// <typeparam name="T"> The actual type returned by the delegate. </typeparam>
/// <param name="func"> The method to pass the internal properties to. </param>
/// <returns> Whatever the delegate returns. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public T GetContainer<T>(Func<ArmClientOptions, TokenCredential, Uri, HttpPipeline, T> func)
[ForwardsClientCalls]
public virtual T UseClientContext<T>(Func<Uri, TokenCredential, ArmClientOptions, HttpPipeline, T> func)
{
return func(ClientOptions, Credential, BaseUri, Pipeline);
return func(BaseUri, Credential, ClientOptions, Pipeline);
}

/// <summary>
/// Get the operations for a list of specific resources.
/// </summary>
/// <param name="ids"> A list of the IDs of the resources to retrieve. </param>
/// <returns> The list of operations that can be performed over the GenericResources. </returns>
public virtual IList<GenericResourceOperations> GetGenericResourceOperations(IEnumerable<string> ids)
public virtual IReadOnlyList<GenericResourceOperations> GetGenericResourceOperations(params string[] ids)
{
return GetGenericResourceOperationsInternal(ids);
}

/// <summary>
/// Get the operations for a list of specific resources.
/// </summary>
/// <param name="ids"> A list of the IDs of the resources to retrieve. </param>
/// <returns> The list of operations that can be performed over the GenericResources. </returns>
public virtual IReadOnlyList<GenericResourceOperations> GetGenericResourceOperations(IEnumerable<string> ids)
{
return GetGenericResourceOperationsInternal(ids);
}

private IReadOnlyList<GenericResourceOperations> GetGenericResourceOperationsInternal(IEnumerable<string> ids)
{
if (ids == null)
{
throw new ArgumentNullException(nameof(ids));
}

IList<GenericResourceOperations> genericRespirceOperations = new List<GenericResourceOperations>();
var genericRespirceOperations = new ChangeTrackingList<GenericResourceOperations>();
foreach (string id in ids)
{
genericRespirceOperations.Add(new GenericResourceOperations(DefaultSubscription, id));
Expand All @@ -207,11 +233,11 @@ public virtual GenericResourceOperations GetGenericResourceOperations(string id)
/// <summary>
/// Gets the RestApi definition for a given Azure namespace.
/// </summary>
/// <param name="nameSpace"> The namespace to get the rest API for. </param>
/// <param name="azureNamespace"> The namespace to get the rest API for. </param>
/// <returns> A container representing the rest apis for the namespace. </returns>
public virtual RestApiContainer GetRestApis(string nameSpace)
public virtual RestApiContainer GetRestApis(string azureNamespace)
{
return new RestApiContainer(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), nameSpace);
return new RestApiContainer(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline), azureNamespace);
}

/// <summary> Gets all resource providers for a subscription. </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace Azure.ResourceManager.Core
{
public partial class PreDefinedTagCount
public partial class PredefinedTagCount
{
internal static PreDefinedTagCount DeserializeTagCount(JsonElement element)
internal static PredefinedTagCount DeserializeTagCount(JsonElement element)
{
Optional<string> type = default;
Optional<int> value = default;
Expand All @@ -30,7 +30,7 @@ internal static PreDefinedTagCount DeserializeTagCount(JsonElement element)
continue;
}
}
return new PreDefinedTagCount(type.Value, Optional.ToNullable(value));
return new PredefinedTagCount(type.Value, Optional.ToNullable(value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
namespace Azure.ResourceManager.Core
{
/// <summary> Tag count. </summary>
public partial class PreDefinedTagCount
public partial class PredefinedTagCount
{
/// <summary> Initializes a new instance of TagCount. </summary>
internal PreDefinedTagCount()
internal PredefinedTagCount()
{
}

/// <summary> Initializes a new instance of TagCount. </summary>
/// <param name="type"> Type of count. </param>
/// <param name="value"> Value of count. </param>
internal PreDefinedTagCount(string type, int? value)
internal PredefinedTagCount(string type, int? value)
{
Type = type;
Value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

namespace Azure.ResourceManager.Core
{
public partial class PreDefinedTagData
public partial class PredefinedTagData
{
internal static PreDefinedTagData DeserializeTagDetails(JsonElement element)
internal static PredefinedTagData DeserializeTagDetails(JsonElement element)
{
Optional<string> id = default;
Optional<string> tagName = default;
Optional<PreDefinedTagCount> count = default;
Optional<IReadOnlyList<PreDefinedTagValue>> values = default;
Optional<PredefinedTagCount> count = default;
Optional<IReadOnlyList<PredefinedTagValue>> values = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("id"))
Expand All @@ -34,7 +34,7 @@ internal static PreDefinedTagData DeserializeTagDetails(JsonElement element)
property.ThrowNonNullablePropertyIsNull();
continue;
}
count = PreDefinedTagCount.DeserializeTagCount(property.Value);
count = PredefinedTagCount.DeserializeTagCount(property.Value);
continue;
}
if (property.NameEquals("values"))
Expand All @@ -44,16 +44,16 @@ internal static PreDefinedTagData DeserializeTagDetails(JsonElement element)
property.ThrowNonNullablePropertyIsNull();
continue;
}
List<PreDefinedTagValue> array = new List<PreDefinedTagValue>();
List<PredefinedTagValue> array = new List<PredefinedTagValue>();
foreach (var item in property.Value.EnumerateArray())
{
array.Add(PreDefinedTagValue.DeserializeTagValue(item));
array.Add(PredefinedTagValue.DeserializeTagValue(item));
}
values = array;
continue;
}
}
return new PreDefinedTagData(id.Value, tagName.Value, count.Value, Optional.ToList(values));
return new PredefinedTagData(id.Value, tagName.Value, count.Value, Optional.ToList(values));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
namespace Azure.ResourceManager.Core
{
/// <summary> Tag details. </summary>
public partial class PreDefinedTagData : SubResource
public partial class PredefinedTagData : SubResource
{
/// <summary> Initializes a new instance of TagDetails. </summary>
internal PreDefinedTagData()
internal PredefinedTagData()
{
Values = new ChangeTrackingList<PreDefinedTagValue>();
Values = new ChangeTrackingList<PredefinedTagValue>();
}

/// <summary> Initializes a new instance of TagDetails. </summary>
/// <param name="id"> The tag name ID. </param>
/// <param name="tagName"> The tag name. </param>
/// <param name="count"> The total number of resources that use the resource tag. When a tag is initially created and has no associated resources, the value is 0. </param>
/// <param name="values"> The list of tag values. </param>
internal PreDefinedTagData(string id, string tagName, PreDefinedTagCount count, IReadOnlyList<PreDefinedTagValue> values) : base(id)
internal PredefinedTagData(string id, string tagName, PredefinedTagCount count, IReadOnlyList<PredefinedTagValue> values) : base(id)
{
TagName = tagName;
Count = count;
Expand All @@ -30,8 +30,8 @@ internal PreDefinedTagData(string id, string tagName, PreDefinedTagCount count,
/// <summary> The tag name. </summary>
public string TagName { get; }
/// <summary> The total number of resources that use the resource tag. When a tag is initially created and has no associated resources, the value is 0. </summary>
public PreDefinedTagCount Count { get; }
public PredefinedTagCount Count { get; }
/// <summary> The list of tag values. </summary>
public IReadOnlyList<PreDefinedTagValue> Values { get; }
public IReadOnlyList<PredefinedTagValue> Values { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Azure.ResourceManager.Core
{
public partial class PreDefinedTagValue
public partial class PredefinedTagValue
{
internal static PreDefinedTagValue DeserializeTagValue(JsonElement element)
internal static PredefinedTagValue DeserializeTagValue(JsonElement element)
{
Optional<string> id = default;
Optional<string> tagValue = default;
Optional<PreDefinedTagCount> count = default;
Optional<PredefinedTagCount> count = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("id"))
Expand All @@ -32,11 +32,11 @@ internal static PreDefinedTagValue DeserializeTagValue(JsonElement element)
property.ThrowNonNullablePropertyIsNull();
continue;
}
count = PreDefinedTagCount.DeserializeTagCount(property.Value);
count = PredefinedTagCount.DeserializeTagCount(property.Value);
continue;
}
}
return new PreDefinedTagValue(id.Value, tagValue.Value, count.Value);
return new PredefinedTagValue(id.Value, tagValue.Value, count.Value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
namespace Azure.ResourceManager.Core
{
/// <summary> Tag information. </summary>
public partial class PreDefinedTagValue
public partial class PredefinedTagValue
{
/// <summary> Initializes a new instance of TagValue. </summary>
internal PreDefinedTagValue()
internal PredefinedTagValue()
{
}

/// <summary> Initializes a new instance of TagValue. </summary>
/// <param name="id"> The tag value ID. </param>
/// <param name="tagValueValue"> The tag value. </param>
/// <param name="count"> The tag value count. </param>
internal PreDefinedTagValue(string id, string tagValueValue, PreDefinedTagCount count)
internal PredefinedTagValue(string id, string tagValueValue, PredefinedTagCount count)
{
Id = id;
TagValueValue = tagValueValue;
Expand All @@ -27,6 +27,6 @@ internal PreDefinedTagValue(string id, string tagValueValue, PreDefinedTagCount
/// <summary> The tag value. </summary>
public string TagValueValue { get; }
/// <summary> The tag value count. </summary>
public PreDefinedTagCount Count { get; }
public PredefinedTagCount Count { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace Azure.ResourceManager.Core
{
internal partial class PreDefinedTagsListResult
internal partial class PredefinedTagsListResult
{
internal static PreDefinedTagsListResult DeserializeTagsListResult(JsonElement element)
internal static PredefinedTagsListResult DeserializeTagsListResult(JsonElement element)
{
Optional<IReadOnlyList<PreDefinedTagData>> value = default;
Optional<IReadOnlyList<PredefinedTagData>> value = default;
Optional<string> nextLink = default;
foreach (var property in element.EnumerateObject())
{
Expand All @@ -22,10 +22,10 @@ internal static PreDefinedTagsListResult DeserializeTagsListResult(JsonElement e
property.ThrowNonNullablePropertyIsNull();
continue;
}
List<PreDefinedTagData> array = new List<PreDefinedTagData>();
List<PredefinedTagData> array = new List<PredefinedTagData>();
foreach (var item in property.Value.EnumerateArray())
{
array.Add(PreDefinedTagData.DeserializeTagDetails(item));
array.Add(PredefinedTagData.DeserializeTagDetails(item));
}
value = array;
continue;
Expand All @@ -36,7 +36,7 @@ internal static PreDefinedTagsListResult DeserializeTagsListResult(JsonElement e
continue;
}
}
return new PreDefinedTagsListResult(Optional.ToList(value), nextLink.Value);
return new PredefinedTagsListResult(Optional.ToList(value), nextLink.Value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
namespace Azure.ResourceManager.Core
{
/// <summary> List of subscription tags. </summary>
internal partial class PreDefinedTagsListResult
internal partial class PredefinedTagsListResult
{
/// <summary> Initializes a new instance of TagsListResult. </summary>
internal PreDefinedTagsListResult()
internal PredefinedTagsListResult()
{
Value = new ChangeTrackingList<PreDefinedTagData>();
Value = new ChangeTrackingList<PredefinedTagData>();
}

/// <summary> Initializes a new instance of TagsListResult. </summary>
/// <param name="value"> An array of tags. </param>
/// <param name="nextLink"> The URL to use for getting the next set of results. </param>
internal PreDefinedTagsListResult(IReadOnlyList<PreDefinedTagData> value, string nextLink)
internal PredefinedTagsListResult(IReadOnlyList<PredefinedTagData> value, string nextLink)
{
Value = value;
NextLink = nextLink;
}

/// <summary> An array of tags. </summary>
public IReadOnlyList<PreDefinedTagData> Value { get; }
public IReadOnlyList<PredefinedTagData> Value { get; }
/// <summary> The URL to use for getting the next set of results. </summary>
public string NextLink { get; }
}
Expand Down
Loading