Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Propagated SyncWrapper property
Browse files Browse the repository at this point in the history
stankovski committed May 27, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e4be13a commit b338faa
Showing 12 changed files with 56 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ public override async Task Generate(ServiceClient serviceClient)
{
var extensionsTemplate = new ExtensionsTemplate
{
Model = new AzureExtensionsTemplateModel(serviceClient, null),
Model = new AzureExtensionsTemplateModel(serviceClient, null, SyncWrappers),
};
await Write(extensionsTemplate, serviceClient.Name + "Extensions.cs");
}
@@ -124,7 +124,7 @@ public override async Task Generate(ServiceClient serviceClient)
// Service client extensions
var operationExtensionsTemplate = new ExtensionsTemplate
{
Model = new AzureExtensionsTemplateModel(serviceClient, group),
Model = new AzureExtensionsTemplateModel(serviceClient, group, SyncWrappers),
};
await Write(operationExtensionsTemplate, operationExtensionsTemplate.Model.ExtensionName + "Extensions.cs");

Original file line number Diff line number Diff line change
@@ -12,12 +12,12 @@ namespace Microsoft.Rest.Generator.CSharp.Azure
{
public class AzureExtensionsTemplateModel : ExtensionsTemplateModel
{
public AzureExtensionsTemplateModel(ServiceClient serviceClient, string operationName)
: base(serviceClient, operationName)
public AzureExtensionsTemplateModel(ServiceClient serviceClient, string operationName, SyncWrapperGenerationMode syncWrappers)
: base(serviceClient, operationName, syncWrappers)
{
MethodTemplateModels.Clear();
Methods.Where(m => m.Group == operationName)
.ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient)));
.ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient, syncWrappers)));
if (ExtensionName != Name)
{
ExtensionName = ExtensionName + "Operations";
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ public AzureMethodGroupTemplateModel(ServiceClient serviceClient, string methodG
// AzureMethodTemplateModel
MethodTemplateModels.Clear();
Methods.Where(m => m.Group == methodGroupName)
.ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient)));
.ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient, SyncWrapperGenerationMode.None)));
}

/// <summary>
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ namespace Microsoft.Rest.Generator.CSharp.Azure
{
public class AzureMethodTemplateModel : MethodTemplateModel
{
public AzureMethodTemplateModel(Method source, ServiceClient serviceClient)
: base(source, serviceClient)
public AzureMethodTemplateModel(Method source, ServiceClient serviceClient, SyncWrapperGenerationMode syncWrappers)
: base(source, serviceClient, syncWrappers)
{
if (source == null)
{
@@ -54,7 +54,7 @@ public AzureMethodTemplateModel GetMethod
Resources.InvalidLongRunningOperationForCreateOrUpdate,
Name, Group));
}
return new AzureMethodTemplateModel(getMethod, ServiceClient);
return new AzureMethodTemplateModel(getMethod, ServiceClient, SyncWrappers);
}
}

Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ public AzureServiceClientTemplateModel(ServiceClient serviceClient, bool interna
// TODO: Initialized in the base constructor. Why Clear it?
MethodTemplateModels.Clear();
Methods.Where(m => m.Group == null)
.ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient)));
.ForEach(m => MethodTemplateModels.Add(new AzureMethodTemplateModel(m, serviceClient, SyncWrapperGenerationMode.None)));
}

/// <summary>
10 changes: 8 additions & 2 deletions AutoRest/Generators/CSharp/CSharp/CSharpCodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -29,6 +29,12 @@ public CSharpCodeGenerator(Settings settings) : base(settings)
[SettingsAlias("internal")]
public bool InternalConstructors { get; set; }

/// <summary>
/// Specifies mode for generating sync wrappers.
/// </summary>
[SettingsInfo("Specifies mode for generating sync wrappers.")]
public SyncWrapperGenerationMode SyncWrappers { get; set; }

public override string Name
{
get { return "CSharp"; }
@@ -106,7 +112,7 @@ public override async Task Generate(ServiceClient serviceClient)
{
var extensionsTemplate = new ExtensionsTemplate
{
Model = new ExtensionsTemplateModel(serviceClient, null),
Model = new ExtensionsTemplateModel(serviceClient, null, SyncWrappers),
};
await Write(extensionsTemplate, serviceClient.Name + "Extensions.cs");
}
@@ -131,7 +137,7 @@ public override async Task Generate(ServiceClient serviceClient)
// Service client extensions
var operationExtensionsTemplate = new ExtensionsTemplate
{
Model = new ExtensionsTemplateModel(serviceClient, group),
Model = new ExtensionsTemplateModel(serviceClient, group, SyncWrappers),
};
await Write(operationExtensionsTemplate, group + "Extensions.cs");

Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@ namespace Microsoft.Rest.Generator.CSharp
/// </summary>
public enum SyncWrapperGenerationMode
{
All = 0,
Essential = 1,
None = 2
Essential,
All,
None
}
}
Original file line number Diff line number Diff line change
@@ -10,13 +10,13 @@ namespace Microsoft.Rest.Generator.CSharp
{
public class ExtensionsTemplateModel : ServiceClient
{
public ExtensionsTemplateModel(ServiceClient serviceClient, string operationName)
public ExtensionsTemplateModel(ServiceClient serviceClient, string operationName, SyncWrapperGenerationMode syncWrappers)
{
this.LoadFrom(serviceClient);
MethodTemplateModels = new List<MethodTemplateModel>();
ExtensionName = operationName ?? this.Name;
this.Methods.Where(m => m.Group == operationName)
.ForEach(m => MethodTemplateModels.Add(new MethodTemplateModel(m, serviceClient)));
.ForEach(m => MethodTemplateModels.Add(new MethodTemplateModel(m, serviceClient, syncWrappers)));
}


Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ public MethodGroupTemplateModel(ServiceClient serviceClient, string methodGroupN
MethodGroupName = methodGroupName;
MethodGroupType = methodGroupName;
Methods.Where(m => m.Group == MethodGroupName)
.ForEach(m => MethodTemplateModels.Add(new MethodTemplateModel(m, serviceClient)));
.ForEach(m => MethodTemplateModels.Add(new MethodTemplateModel(m, serviceClient, SyncWrapperGenerationMode.None)));
}

public List<MethodTemplateModel> MethodTemplateModels { get; private set; }
Original file line number Diff line number Diff line change
@@ -14,9 +14,10 @@ namespace Microsoft.Rest.Generator.CSharp
{
public class MethodTemplateModel : Method
{
public MethodTemplateModel(Method source, ServiceClient serviceClient)
public MethodTemplateModel(Method source, ServiceClient serviceClient, SyncWrapperGenerationMode syncWrappers)
{
this.LoadFrom(source);
SyncWrappers = syncWrappers;
ParameterTemplateModels = new List<ParameterTemplateModel>();
LogicalParameterTemplateModels = new List<ParameterTemplateModel>();
source.Parameters.ForEach(p => ParameterTemplateModels.Add(new ParameterTemplateModel(p)));
@@ -30,6 +31,8 @@ public MethodTemplateModel(Method source, ServiceClient serviceClient)

public bool IsCustomBaseUri { get; private set; }

public SyncWrapperGenerationMode SyncWrappers { get; private set; }

public ServiceClient ServiceClient { get; set; }

public List<ParameterTemplateModel> ParameterTemplateModels { get; private set; }
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ public ServiceClientTemplateModel(ServiceClient serviceClient, bool internalCons
this.LoadFrom(serviceClient);
MethodTemplateModels = new List<MethodTemplateModel>();
Methods.Where(m => m.Group == null)
.ForEach(m => MethodTemplateModels.Add(new MethodTemplateModel(m, serviceClient)));
.ForEach(m => MethodTemplateModels.Add(new MethodTemplateModel(m, serviceClient, SyncWrapperGenerationMode.None)));
ConstructorVisibility = internalConstructors ? "internal" : "public";
this.IsCustomBaseUri = serviceClient.Extensions.ContainsKey(Microsoft.Rest.Generator.Extensions.ParameterizedHostExtension);
}
Original file line number Diff line number Diff line change
@@ -6,25 +6,27 @@
@using Microsoft.Rest.Generator.Utilities
@inherits Microsoft.Rest.Generator.Template<Microsoft.Rest.Generator.CSharp.MethodTemplateModel>
@{
@if (!String.IsNullOrEmpty(Model.Description) || !String.IsNullOrEmpty(Model.Summary))
if (Model.SyncWrappers == SyncWrapperGenerationMode.All || Model.SyncWrappers == SyncWrapperGenerationMode.Essential)
{
if (!String.IsNullOrEmpty(Model.Description) || !String.IsNullOrEmpty(Model.Summary))
{
@:/// <summary>
@:@WrapComment("/// ", String.IsNullOrEmpty(Model.Summary) ? Model.Description.EscapeXmlComment() : Model.Summary.EscapeXmlComment())
@:/// </summary>
}
@if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary))
{
}
if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary))
{
@:@WrapComment("/// ", Model.Description.EscapeXmlComment())
}
}
@:/// <param name='operations'>
@:/// The operations group for this extension method.
@:/// </param>
foreach (var parameter in Model.LocalParameters)
{
foreach (var parameter in Model.LocalParameters)
{
@:/// <param name='@parameter.Name'>
@:@WrapComment("/// ", parameter.Documentation.EscapeXmlComment())
@:/// </param>
}
}
@:public static @Model.ReturnTypeString @(Model.Name)(@Model.GetExtensionParameters(Model.SyncMethodParameterDeclaration))
@:{
if (Model.ReturnType.Body != null)
@@ -40,15 +42,16 @@ foreach (var parameter in Model.LocalParameters)
@:Task.Factory.StartNew(s => ((I@(Model.MethodGroupName))s).@(Model.Name)Async(@(Model.SyncMethodInvocationArgs)), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
}
@:}

@EmptyLine
@if (!String.IsNullOrEmpty(Model.Description) || !String.IsNullOrEmpty(Model.Summary))
}

if (!String.IsNullOrEmpty(Model.Description) || !String.IsNullOrEmpty(Model.Summary))
{
@:/// <summary>
@:@WrapComment("/// ", String.IsNullOrEmpty(Model.Summary) ? Model.Description.EscapeXmlComment() : Model.Summary.EscapeXmlComment())
@:/// </summary>
}
@if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary))
if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary))
{
@:@WrapComment("/// ", Model.Description.EscapeXmlComment())
}
@@ -95,26 +98,28 @@ foreach (var parameter in Model.LocalParameters)
}
@:}

@EmptyLine
@if (!String.IsNullOrEmpty(Model.Description) || !String.IsNullOrEmpty(Model.Summary))
if (Model.SyncWrappers == SyncWrapperGenerationMode.All)
{
@EmptyLine
if (!String.IsNullOrEmpty(Model.Description) || !String.IsNullOrEmpty(Model.Summary))
{
@:/// <summary>
@:@WrapComment("/// ", String.IsNullOrEmpty(Model.Summary) ? Model.Description.EscapeXmlComment() : Model.Summary.EscapeXmlComment())
@:/// </summary>
}
@if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary))
{
}
if (!String.IsNullOrEmpty(Model.Description) && !String.IsNullOrEmpty(Model.Summary))
{
@:@WrapComment("/// ", Model.Description.EscapeXmlComment())
}
}
@:/// <param name='operations'>
@:/// The operations group for this extension method.
@:/// </param>
foreach (var parameter in Model.LocalParameters)
{
foreach (var parameter in Model.LocalParameters)
{
@:/// <param name='@parameter.Name'>
@:@WrapComment("/// ", parameter.Documentation.EscapeXmlComment())
@:/// </param>
}
}
@:/// <param name='customHeaders'>
@:/// Headers that will be added to request.
@:/// </param>
@@ -123,4 +128,5 @@ foreach (var parameter in Model.LocalParameters)
@: return operations.@(Model.Name)WithHttpMessagesAsync(@(Model.GetAsyncMethodInvocationArgs("customHeaders", "CancellationToken.None"))).ConfigureAwait(false).GetAwaiter().GetResult();
@:}
@:
}
}
}

0 comments on commit b338faa

Please sign in to comment.