Skip to content
27 changes: 26 additions & 1 deletion src/azure/Model/CodeModelCsa.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// 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.
//

using System.Collections.Generic;
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
{
Expand All @@ -32,5 +36,26 @@ public override IEnumerable<string> Usings
}
}
}

/// <summary>
/// Attempts to infer the name of the service referenced by this CodeModel.
/// </summary>
[JsonIgnore]
public string ServiceName
{
get
{
var serviceNameSetting = Settings.Instance.Host?.GetValue<string>("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;
}
}
}
}
31 changes: 31 additions & 0 deletions src/azure/Templates/AzureAssemblyInfoTemplate.cshtml
Original file line number Diff line number Diff line change
@@ -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<AutoRest.CSharp.Azure.Model.CodeModelCsa>

@{
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")]
74 changes: 74 additions & 0 deletions src/azure/Templates/AzureCsprojTemplate.cshtml
Original file line number Diff line number Diff line change
@@ -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<AutoRest.CSharp.Azure.Model.CodeModelCsa>

@{
var serviceName = Model.ServiceName;
}
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>Microsoft.Azure.Management.@(serviceName).Fluent</PackageId>
<Version>1.1.3</Version>
<AssemblyName>Microsoft.Azure.Management.@(serviceName).Fluent</AssemblyName>
<RootNamespace>Microsoft.Azure.Management.@(serviceName).Fluent</RootNamespace>
<AssemblyTitle>Microsoft Azure @(serviceName) Management Library</AssemblyTitle>
<Authors>Microsoft</Authors>
<Description>Provides @(serviceName) service management (Fluent) capabilities for Microsoft Azure.</Description>
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
<PackageTags>Microsoft Azure @(serviceName) management;@(serviceName.ToLower());REST HTTP client;azureofficial;windowsazureofficial;Fluent</PackageTags>
<PackageProjectUrl>https://github.com/Azure/azure-sdk-for-net/tree/Fluent</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/Microsoft/dotnet/master/LICENSE</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
</PropertyGroup>

<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>../../../tools/MSSharedLibKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.3' ">$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.3' ">1.6.1</NetStandardImplicitPackageVersion>
<TargetFrameworks>net452;netstandard1.3</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.8" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager.Fluent" Version="1.1.3" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<DefineConstants>$(DefineConstants);NETSTANDARD13;PORTABLE</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
<DefineConstants>$(DefineConstants);NET45</DefineConstants>
<DebugType>portable</DebugType>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ResourceManager\Microsoft.Azure.Management.ResourceManager.Fluent.csproj" />
</ItemGroup>

</Project>
117 changes: 117 additions & 0 deletions src/azure/Templates/AzureServiceManagerTemplate.cshtml
Original file line number Diff line number Diff line change
@@ -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<AutoRest.CSharp.Azure.Model.CodeModelCsa>

@{
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@(Model.Name)>, 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

/// <summary>
/// Creates an instance of @(className) that exposes storage resource management API entry points.
/// </summary>
/// <param name="credentials">the credentials to use</param>
/// <param name="subscriptionId">the subscription UUID</param>
/// <returns>the @(className)</returns>
public static I@(className) Authenticate(AzureCredentials credentials, string subscriptionId)
{
return Authenticate(RestClient.Configure()
.WithEnvironment(credentials.Environment)
.WithCredentials(credentials)
.WithDelegatingHandler(new ProviderRegistrationDelegatingHandler(credentials))
.Build(), subscriptionId);
}

/// <summary>
/// Creates an instance of @(className) that exposes storage resource management API entry points.
/// </summary>
/// <param name="restClient">the RestClient to be used for API calls.</param>
/// <param name="subscriptionId">the subscription UUID</param>
/// <returns>the @(className)</returns>
public static I@(className) Authenticate(RestClient restClient, string subscriptionId)
{
return new @(className)(restClient, subscriptionId);
}

/// <summary>
/// Get a Configurable instance that can be used to create StorageManager with optional configuration.
/// </summary>
/// <returns>the instance allowing configurations</returns>
public static IConfigurable Configure()
{
return new Configurable();
}

#endregion


#region IConfigurable and it's implementation

/// <summary>
/// The inteface allowing configurations to be set.
/// </summary>
public interface IConfigurable : IAzureConfigurable<IConfigurable>
{
I@(className) Authenticate(AzureCredentials credentials, string subscriptionId);
}

protected class Configurable :
AzureConfigurable<IConfigurable>,
IConfigurable
{
/// <summary>
/// Creates an instance of @(className) that exposes @(serviceName) management API entry points.
/// </summary>
/// <param name="credentials">credentials the credentials to use</param>
/// <param name="subscriptionId">The subscription UUID</param>
/// <returns>the interface exposing @(serviceName) management API entry points that work in a subscription</returns>
public I@(className) Authenticate(AzureCredentials credentials, string subscriptionId)
{
return new @(className)(BuildRestClient(credentials), subscriptionId);
}
}

#endregion
}


/// <summary>
/// Entry point to Azure @(serviceName) resource management.
/// </summary>
public interface I@(className) : IManager<I@(Model.Name)>
{
}
}
15 changes: 15 additions & 0 deletions src/azurefluent/CodeGeneratorCsaf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool?>("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");
}
}
}
}