mirror of
https://github.com/dotnet/skills.git
synced 2026-09-20 09:49:54 +08:00
042a9d2b2c
* Reorganize plugins per agreed structure (#271) Split the dotnet plugin into domain-specific plugins per discussion in #271: - dotnet: narrowed to common everyday C#/.NET coding tasks - dotnet-diag: perf investigations, debugging, incident analysis - dotnet-data: data access and Entity Framework - dotnet-aspnet, dotnet-wpf, dotnet-winforms, dotnet-maui: scaffolded empty to convey intent for future framework-specific skills Moved skills, tests, and CODEOWNERS entries accordingly. No file content was changed; all skill/test moves are pure renames. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Improve dotnet-diag and dotnet-winforms descriptions - dotnet-diag: add '.NET' qualifier to clarify scope - dotnet-winforms: use official 'Windows Forms (WinForms)' name Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add .NET qualifier to dotnet-data description Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove empty plugins; list them in CONTRIBUTING.md as future options Remove the four empty placeholder plugins (dotnet-aspnet, dotnet-wpf, dotnet-winforms, dotnet-maui) that had only plugin.json and no skills. Add a 'Plugin organization' section to CONTRIBUTING.md that describes the domain-specific plugin groupings introduced in this PR and lists the four removed plugin names as reserved candidates for future contributions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Create dotnet-upgrade plugin with migration/upgrade skills Move migrate-nullable-references, thread-abort-migration, and dotnet-aot-compat from dotnet to the new dotnet-upgrade plugin. Update CODEOWNERS paths (same owners), CONTRIBUTING.md plugin table, and fix the thread-abort-migration SKILL.md link in CONTRIBUTING.md. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
141 lines
6.9 KiB
C#
141 lines
6.9 KiB
C#
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Azure.Core;
|
|
using Azure.Core.Pipeline;
|
|
using Azure.ResourceManager.Resources;
|
|
using Azure.ResourceManager.Resources.Models;
|
|
|
|
namespace Azure.ResourceManager
|
|
{
|
|
/// <summary>
|
|
/// A class representing the operations that can be performed over a specific resource.
|
|
/// </summary>
|
|
public abstract partial class ArmResource
|
|
{
|
|
private readonly ConcurrentDictionary<Type, object> _clientCache = new ConcurrentDictionary<Type, object>();
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="ArmResource"/> class for mocking.
|
|
/// </summary>
|
|
protected ArmResource()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="ArmResource"/> class.
|
|
/// </summary>
|
|
/// <param name="client"> The <see cref="ArmClient"/> this resource client should be created from. </param>
|
|
/// <param name="id"> The identifier of the resource that is the target of operations. </param>
|
|
protected internal ArmResource(ArmClient client, ResourceIdentifier id)
|
|
{
|
|
Argument.AssertNotNull(id, nameof(id));
|
|
Argument.AssertNotNull(client, nameof(client));
|
|
|
|
Client = client;
|
|
Id = id;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the resource identifier.
|
|
/// </summary>
|
|
public virtual ResourceIdentifier Id { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the <see cref="ArmClient"/> this resource client was created from.
|
|
/// </summary>
|
|
protected internal virtual ArmClient Client { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the diagnostic options for this resource client.
|
|
/// </summary>
|
|
protected internal DiagnosticsOptions Diagnostics => Client.Diagnostics;
|
|
|
|
/// <summary>
|
|
/// Gets the pipeline for this resource client.
|
|
/// </summary>
|
|
protected internal HttpPipeline Pipeline => Client.Pipeline;
|
|
|
|
/// <summary>
|
|
/// Gets the base uri for this resource client.
|
|
/// </summary>
|
|
protected internal Uri Endpoint => Client.Endpoint;
|
|
|
|
/// <summary>
|
|
/// Gets the api version override if it has been set for the current client options.
|
|
/// </summary>
|
|
/// <param name="resourceType"> The resource type to get the version for. </param>
|
|
/// <param name="apiVersion"> The api version to variable to set. </param>
|
|
protected virtual bool TryGetApiVersion(ResourceType resourceType, out string apiVersion) => Client.TryGetApiVersion(resourceType, out apiVersion);
|
|
|
|
/// <summary>
|
|
/// Lists all available geo-locations.
|
|
/// </summary>
|
|
/// <param name="cancellationToken"> A token to allow the caller to cancel the call to the service. The default value is <see cref="CancellationToken.None" />. </param>
|
|
/// <returns> A collection of location that may take multiple service requests to iterate over. </returns>
|
|
[ForwardsClientCalls]
|
|
public virtual Response<IEnumerable<AzureLocation>> GetAvailableLocations(CancellationToken cancellationToken = default)
|
|
{
|
|
string nameSpace = Id.ResourceType.Namespace;
|
|
string type = Id.ResourceType.Type;
|
|
Response<TenantResourceProvider> resourcePageableProviderResponse = Client.GetTenantResourceProvider(nameSpace, null, cancellationToken);
|
|
TenantResourceProvider resourcePageableProvider = resourcePageableProviderResponse.Value;
|
|
if (resourcePageableProvider is null)
|
|
throw new InvalidOperationException($"{type} not found for {nameSpace}");
|
|
var theResource = resourcePageableProvider.ResourceTypes.FirstOrDefault(r => type.Equals(r.ResourceType, StringComparison.Ordinal));
|
|
if (theResource is null)
|
|
throw new InvalidOperationException($"{type} not found for {nameSpace}");
|
|
return Response.FromValue(theResource.Locations.Select(l => new AzureLocation(l)), resourcePageableProviderResponse.GetRawResponse());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lists all available geo-locations.
|
|
/// </summary>
|
|
/// <param name="cancellationToken"> A token to allow the caller to cancel the call to the service. The default value is <see cref="CancellationToken.None" />. </param>
|
|
/// <returns> A collection of location that may take multiple service requests to iterate over. </returns>
|
|
[ForwardsClientCalls]
|
|
public virtual async Task<Response<IEnumerable<AzureLocation>>> GetAvailableLocationsAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
string nameSpace = Id.ResourceType.Namespace;
|
|
string type = Id.ResourceType.Type;
|
|
Response<TenantResourceProvider> resourcePageableProviderResponse = await Client.GetTenantResourceProviderAsync(nameSpace, null, cancellationToken).ConfigureAwait(false);
|
|
TenantResourceProvider resourcePageableProvider = resourcePageableProviderResponse.Value;
|
|
if (resourcePageableProvider is null)
|
|
throw new InvalidOperationException($"{type} not found for {nameSpace}");
|
|
var theResource = resourcePageableProvider.ResourceTypes.FirstOrDefault(r => type.Equals(r.ResourceType, StringComparison.Ordinal));
|
|
if (theResource is null)
|
|
throw new InvalidOperationException($"{type} not found for {nameSpace}");
|
|
return Response.FromValue(theResource.Locations.Select(l => new AzureLocation(l)), resourcePageableProviderResponse.GetRawResponse());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a cached client to use for extension methods.
|
|
/// </summary>
|
|
/// <typeparam name="T"> The type of client to get. </typeparam>
|
|
/// <param name="clientFactory"> The constructor factory for the client. </param>
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public virtual T GetCachedClient<T>(Func<ArmClient, T> clientFactory)
|
|
where T : class
|
|
{
|
|
return _clientCache.GetOrAdd(typeof(T), (type) => { return clientFactory(Client); }) as T;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks to see if the TagResource API is deployed in the current environment.
|
|
/// </summary>
|
|
protected virtual bool CanUseTagResource(CancellationToken cancellationToken = default) => Client.CanUseTagResource(cancellationToken);
|
|
|
|
/// <summary>
|
|
/// Checks to see if the TagResource API is deployed in the current environment.
|
|
/// </summary>
|
|
protected virtual Task<bool> CanUseTagResourceAsync(CancellationToken cancellationToken = default) => Client.CanUseTagResourceAsync(cancellationToken);
|
|
}
|
|
}
|