diff --git a/src/azure/Model/CodeModelCsa.cs b/src/azure/Model/CodeModelCsa.cs index 841b1fec121..a944ca44d3e 100644 --- a/src/azure/Model/CodeModelCsa.cs +++ b/src/azure/Model/CodeModelCsa.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. // @@ -6,6 +6,10 @@ using System.Linq; using AutoRest.CSharp.Model; using AutoRest.Extensions.Azure; +using Newtonsoft.Json; +using System.Text.RegularExpressions; +using AutoRest.Core.Utilities; +using AutoRest.Core; namespace AutoRest.CSharp.Azure.Model { @@ -32,5 +36,26 @@ public override IEnumerable Usings } } } + + /// + /// Attempts to infer the name of the service referenced by this CodeModel. + /// + [JsonIgnore] + public string ServiceName + { + get + { + var serviceNameSetting = Settings.Instance.Host?.GetValue("service-name").Result; + if (!string.IsNullOrEmpty(serviceNameSetting)) + { + return serviceNameSetting; + } + + var method = Methods[0]; + var match = Regex.Match(input: method.Url, pattern: @"/providers/microsoft\.(\w+)/", options: RegexOptions.IgnoreCase); + var serviceName = match.Groups[1].Value.ToPascalCase(); + return serviceName; + } + } } } \ No newline at end of file diff --git a/src/azure/Templates/AzureAssemblyInfoTemplate.cshtml b/src/azure/Templates/AzureAssemblyInfoTemplate.cshtml new file mode 100644 index 00000000000..7cd2812b44f --- /dev/null +++ b/src/azure/Templates/AzureAssemblyInfoTemplate.cshtml @@ -0,0 +1,31 @@ +@using System +@using AutoRest.CSharp.Azure.Templates +@using System.Linq +@using AutoRest.Core.Utilities +@using AutoRest.CSharp.Azure.Model +@using AutoRest.CSharp.Model +@using AutoRest.CSharp.Templates.Rest.Client +@inherits AutoRest.Core.Template + +@{ + var serviceName = Model.ServiceName; +} + +@Header("// ") +@EmptyLine +using System.Reflection; +using System.Resources; +@EmptyLine +[assembly: AssemblyTitle("Microsoft Azure @serviceName Management Library")] +[assembly: AssemblyDescription("Provides Microsoft Azure @serviceName management APIs.")] +@EmptyLine +[assembly: AssemblyVersion("1.0.0.60")] +[assembly: AssemblyFileVersion("1.1.3.0")] +@EmptyLine +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Microsoft Azure .NET SDK")] +[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: NeutralResourcesLanguage("en")] diff --git a/src/azure/Templates/AzureCsprojTemplate.cshtml b/src/azure/Templates/AzureCsprojTemplate.cshtml new file mode 100644 index 00000000000..f9bdaced299 --- /dev/null +++ b/src/azure/Templates/AzureCsprojTemplate.cshtml @@ -0,0 +1,74 @@ +@using System +@using AutoRest.CSharp.Azure.Templates +@using System.Linq +@using AutoRest.Core.Utilities +@using AutoRest.CSharp.Azure.Model +@using AutoRest.CSharp.Model +@using AutoRest.CSharp.Templates.Rest.Client +@inherits AutoRest.Core.Template + +@{ + var serviceName = Model.ServiceName; +} + + + + Microsoft.Azure.Management.@(serviceName).Fluent + 1.1.3 + Microsoft.Azure.Management.@(serviceName).Fluent + Microsoft.Azure.Management.@(serviceName).Fluent + Microsoft Azure @(serviceName) Management Library + Microsoft + Provides @(serviceName) service management (Fluent) capabilities for Microsoft Azure. + http://go.microsoft.com/fwlink/?LinkID=288890 + Microsoft Azure @(serviceName) management;@(serviceName.ToLower());REST HTTP client;azureofficial;windowsazureofficial;Fluent + https://github.com/Azure/azure-sdk-for-net/tree/Fluent + https://raw.githubusercontent.com/Microsoft/dotnet/master/LICENSE + true + + + + false + false + true + true + ../../../tools/MSSharedLibKey.snk + + + + $(PackageTargetFallback);dnxcore50 + 1.6.1 + net452;netstandard1.3 + + + + + + + + + $(DefineConstants);NETSTANDARD13;PORTABLE + + + + + + + $(DefineConstants);NET45 + portable + + + + + + + + + + + + + + + + diff --git a/src/azure/Templates/AzureServiceManagerTemplate.cshtml b/src/azure/Templates/AzureServiceManagerTemplate.cshtml new file mode 100644 index 00000000000..a107effca4f --- /dev/null +++ b/src/azure/Templates/AzureServiceManagerTemplate.cshtml @@ -0,0 +1,117 @@ +@using System +@using AutoRest.CSharp.Azure.Templates +@using System.Linq +@using AutoRest.Core.Utilities +@using AutoRest.CSharp.Azure.Model +@using AutoRest.CSharp.Model +@using AutoRest.CSharp.Templates.Rest.Client +@inherits AutoRest.Core.Template + +@{ + var serviceName = Model.ServiceName; + var className = serviceName + "Manager"; +} + +@Header("// ") + +using Microsoft.Azure.Management.ResourceManager.Fluent.Core; +using System; +using System.Linq; +using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication; + +namespace Microsoft.Azure.Management.@(serviceName).Fluent +{ + public class @className : Manager, I@(className) + { + #region ctrs + + private @(className)(RestClient restClient, string subscriptionId) : + base(restClient, subscriptionId, new @(Model.Name)(new Uri(restClient.BaseUri), + restClient.Credentials, + restClient.RootHttpHandler, + restClient.Handlers.ToArray()) + { + SubscriptionId = subscriptionId + }) + { + } + + #endregion + + #region @className builder + + /// + /// Creates an instance of @(className) that exposes storage resource management API entry points. + /// + /// the credentials to use + /// the subscription UUID + /// the @(className) + public static I@(className) Authenticate(AzureCredentials credentials, string subscriptionId) + { + return Authenticate(RestClient.Configure() + .WithEnvironment(credentials.Environment) + .WithCredentials(credentials) + .WithDelegatingHandler(new ProviderRegistrationDelegatingHandler(credentials)) + .Build(), subscriptionId); + } + + /// + /// Creates an instance of @(className) that exposes storage resource management API entry points. + /// + /// the RestClient to be used for API calls. + /// the subscription UUID + /// the @(className) + public static I@(className) Authenticate(RestClient restClient, string subscriptionId) + { + return new @(className)(restClient, subscriptionId); + } + + /// + /// Get a Configurable instance that can be used to create StorageManager with optional configuration. + /// + /// the instance allowing configurations + public static IConfigurable Configure() + { + return new Configurable(); + } + + #endregion + + + #region IConfigurable and it's implementation + + /// + /// The inteface allowing configurations to be set. + /// + public interface IConfigurable : IAzureConfigurable + { + I@(className) Authenticate(AzureCredentials credentials, string subscriptionId); + } + + protected class Configurable : + AzureConfigurable, + IConfigurable + { + /// + /// Creates an instance of @(className) that exposes @(serviceName) management API entry points. + /// + /// credentials the credentials to use + /// The subscription UUID + /// the interface exposing @(serviceName) management API entry points that work in a subscription + public I@(className) Authenticate(AzureCredentials credentials, string subscriptionId) + { + return new @(className)(BuildRestClient(credentials), subscriptionId); + } + } + + #endregion + } + + + /// + /// Entry point to Azure @(serviceName) resource management. + /// + public interface I@(className) : IManager + { + } +} diff --git a/src/azurefluent/CodeGeneratorCsaf.cs b/src/azurefluent/CodeGeneratorCsaf.cs index 02745f5a2da..3717630259c 100644 --- a/src/azurefluent/CodeGeneratorCsaf.cs +++ b/src/azurefluent/CodeGeneratorCsaf.cs @@ -116,6 +116,21 @@ await Write(exceptionTemplate, Path.Combine(Settings.Instance.ModelsName, var xmlSerializationTemplate = new XmlSerializationTemplate { Model = null }; await Write(xmlSerializationTemplate, Path.Combine(Settings.Instance.ModelsName, $"{XmlSerialization.XmlDeserializationClass}{ImplementationFileExtension}")); } + + if (true == Settings.Instance.Host?.GetValue("regenerate-manager").Result) + { + await Write( + new AzureServiceManagerTemplate { Model = codeModel }, + codeModel.ServiceName + "Manager" + ImplementationFileExtension); + + await Write( + new AzureCsprojTemplate { Model = codeModel }, + $"Microsoft.Azure.Management.{codeModel.ServiceName}.Fluent.csproj"); + + await Write( + new AzureAssemblyInfoTemplate { Model = codeModel }, + "Properties/AssemblyInfo.cs"); + } } } }