add uwp support

This commit is contained in:
wing328 2016-03-22 21:24:41 +08:00
parent f66046c932
commit 559e11e6d2
9 changed files with 92 additions and 26 deletions

View File

@ -34,6 +34,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class);
private static final String NET45 = "v4.5";
private static final String NET35 = "v3.5";
private static final String UWP = "uwp";
private static final String DATA_TYPE_WITH_ENUM_EXTENSION = "plainDatatypeWithEnum";
protected String packageGuid = "{" + java.util.UUID.randomUUID().toString().toUpperCase() + "}";
@ -48,6 +49,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
protected String targetFramework = NET45;
protected String targetFrameworkNuget = "net45";
protected boolean supportsAsync = Boolean.TRUE;
protected boolean supportsUWP = Boolean.FALSE;
protected final Map<String, String> frameworks;
@ -89,6 +91,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
frameworks = new ImmutableMap.Builder<String, String>()
.put(NET35, ".NET Framework 3.5 compatible")
.put(NET45, ".NET Framework 4.5+ compatible")
.put(UWP, "Universal Windows Platform (beta support)")
.build();
framework.defaultValue(this.targetFramework);
framework.setEnum(frameworks);
@ -156,6 +159,13 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
if(additionalProperties.containsKey("supportsAsync")){
additionalProperties.remove("supportsAsync");
}
} else if (UWP.equals(this.targetFramework)){
setTargetFrameworkNuget("uwp");
setSupportsAsync(Boolean.TRUE);
setSupportsUWP(Boolean.TRUE);
additionalProperties.put("supportsAsync", this.supportsUWP);
additionalProperties.put("supportsUWP", this.supportsAsync);
} else {
setTargetFrameworkNuget("net45");
setSupportsAsync(Boolean.TRUE);
@ -453,4 +463,8 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
public void setSupportsAsync(Boolean supportsAsync){
this.supportsAsync = supportsAsync;
}
public void setSupportsUWP(Boolean supportsUWP){
this.supportsUWP = supportsUWP;
}
}

View File

@ -103,7 +103,16 @@ namespace {{packageName}}.Client
// add file parameter, if any
foreach(var param in fileParams)
{
{{^supportsUWP}}
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
{{/supportsUWP}}
{{#supportsUWP}}
byte[] paramWriter = null;
param.Value.Writer = delegate (Stream stream) { paramWriter = ToByteArray(stream); };
request.AddFile(param.Value.Name, paramWriter, param.Value.FileName, param.Value.ContentType);
{{/supportsUWP}}
}
if (postBody != null) // http body (model or byte[]) parameter
{
@ -148,7 +157,15 @@ namespace {{packageName}}.Client
// set user agent
RestClient.UserAgent = Configuration.UserAgent;
{{^supportsUWP}}
var response = RestClient.Execute(request);
{{/supportsUWP}}
{{#supportsUWP}}
// TODO: This is obviously not a valid response, but it prevents compiling-errors
// 'RestClient.CallApiAsync(..)' is used instead, because 'RestClient.ExecuteAsync(...)'
// is available for Windows UWP, while 'RestClient.CallApi(...)' is not
var response = new object();
{{/supportsUWP}}
return (Object) response;
}
{{#supportsAsync}}
@ -444,5 +461,20 @@ namespace {{packageName}}.Client
return filename;
}
}
{{#supportsUWP}}
/// <summary>
/// Convert stream to byte array
/// </summary>
/// <param name="stream">IO stream</param>
/// <returns>Byte array</returns>
public static byte[] ToByteArray(Stream stream)
{
stream.Position = 0;
byte[] buffer = new byte[stream.Length];
for (int totalBytesCopied = 0; totalBytesCopied < stream.Length;)
totalBytesCopied += stream.Read(buffer, totalBytesCopied, Convert.ToInt32(stream.Length) - totalBytesCopied);
return buffer;
}
{{/supportsUWP}}
}
}

View File

@ -270,11 +270,13 @@ namespace {{packageName}}.Client
public static String ToDebugReport()
{
String report = "C# SDK ({{packageName}}) Debug Report:\n";
{{^supportsUWP}}
report += " OS: " + Environment.OSVersion + "\n";
report += " .NET Framework Version: " + Assembly
.GetExecutingAssembly()
.GetReferencedAssemblies()
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
{{/supportsUWP}}
report += " Version of the API: {{version}}\n";
report += " SDK Package Version: {{packageVersion}}\n";

View File

@ -8,7 +8,15 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>{{packageTitle}}</RootNamespace>
<AssemblyName>{{packageTitle}}</AssemblyName>
{{^supportsUWP}}
<TargetFrameworkVersion>{{targetFramework}}</TargetFrameworkVersion>
{{/supportsUWP}}
{{#supportsUWP}}
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
{{/supportsUWP}}
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

View File

@ -31,7 +31,7 @@ namespace IO.Swagger.Test
{
instance = new Name();
}
/// <summary>
/// Clean up after each test
/// </summary>
@ -39,7 +39,7 @@ namespace IO.Swagger.Test
public void Cleanup()
{
}
}
/// <summary>
/// Test an instance of Name
@ -50,22 +50,25 @@ namespace IO.Swagger.Test
Assert.IsInstanceOf<Name> (instance, "instance is a Name");
}
/// <summary>
/// Test the property '_Name'
/// Test the property '_Name'
/// </summary>
[Test]
public void _NameTest()
{
// TODO: unit test for the property '_Name'
// TODO: unit test for the property '_Name'
}
/// <summary>
/// Test the property 'SnakeCase'
/// Test the property 'SnakeCase'
/// </summary>
[Test]
public void SnakeCaseTest()
{
// TODO: unit test for the property 'SnakeCase'
// TODO: unit test for the property 'SnakeCase'
}
}

View File

@ -103,7 +103,12 @@ namespace IO.Swagger.Client
// add file parameter, if any
foreach(var param in fileParams)
{
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
}
if (postBody != null) // http body (model or byte[]) parameter
{
@ -148,7 +153,10 @@ namespace IO.Swagger.Client
// set user agent
RestClient.UserAgent = Configuration.UserAgent;
var response = RestClient.Execute(request);
return (Object) response;
}
/// <summary>
@ -443,5 +451,6 @@ namespace IO.Swagger.Client
return filename;
}
}
}
}

View File

@ -270,11 +270,13 @@ namespace IO.Swagger.Client
public static String ToDebugReport()
{
String report = "C# SDK (IO.Swagger) Debug Report:\n";
report += " OS: " + Environment.OSVersion + "\n";
report += " .NET Framework Version: " + Assembly
.GetExecutingAssembly()
.GetReferencedAssemblies()
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
report += " Version of the API: 1.0.0\n";
report += " SDK Package Version: 1.0.0\n";

View File

@ -12,7 +12,7 @@ using Newtonsoft.Json.Converters;
namespace IO.Swagger.Model
{
/// <summary>
/// Model for testing model name same as property name
///
/// </summary>
[DataContract]
public partial class Name : IEquatable<Name>
@ -22,22 +22,16 @@ namespace IO.Swagger.Model
/// Initializes a new instance of the <see cref="Name" /> class.
/// Initializes a new instance of the <see cref="Name" />class.
/// </summary>
/// <param name="_Name">_Name (required).</param>
/// <param name="_Name">_Name.</param>
/// <param name="SnakeCase">SnakeCase.</param>
public Name(int? _Name = null)
public Name(int? _Name = null, int? SnakeCase = null)
{
// to ensure "_Name" is required (not null)
if (_Name == null)
{
throw new InvalidDataException("_Name is a required property for Name and cannot be null");
}
else
{
this._Name = _Name;
}
this._Name = _Name;
this.SnakeCase = SnakeCase;
}
/// <summary>
/// Gets or Sets _Name
@ -49,7 +43,7 @@ namespace IO.Swagger.Model
/// Gets or Sets SnakeCase
/// </summary>
[DataMember(Name="snake_case", EmitDefaultValue=false)]
public int? SnakeCase { get; private set; }
public int? SnakeCase { get; set; }
/// <summary>
/// Returns the string presentation of the object
@ -60,11 +54,12 @@ namespace IO.Swagger.Model
var sb = new StringBuilder();
sb.Append("class Name {\n");
sb.Append(" _Name: ").Append(_Name).Append("\n");
sb.Append(" SnakeCase: ").Append(SnakeCase).Append("\n");
sb.Append(" SnakeCase: ").Append(SnakeCase).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
@ -120,10 +115,13 @@ sb.Append(" SnakeCase: ").Append(SnakeCase).Append("\n");
{
int hash = 41;
// Suitable nullity checks etc, of course :)
if (this._Name != null)
hash = hash * 59 + this._Name.GetHashCode();
if (this.SnakeCase != null)
hash = hash * 59 + this.SnakeCase.GetHashCode();
return hash;
}
}

View File

@ -1,11 +1,9 @@
<Properties StartupItem="SwaggerClientTest.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Name.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
<Files>
<File FileName="TestPet.cs" Line="1" Column="1" />
<File FileName="TestPet.cs" Line="222" Column="29" />
<File FileName="TestOrder.cs" Line="1" Column="1" />
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Cat.cs" Line="1" Column="1" />
<File FileName="Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Name.cs" Line="18" Column="50" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>