Skip to content

Commit 99dc247

Browse files
Many fixes (in comments) (Azure#49)
* virtual-properties, memory increase, minor fixes * inline properties step * remove message about actual path * Added System.AttachDebugger.Break() and fixed string serializition of enum that has a null value * temp fix for wildcard deserializer * explictly set the collection type in wildcard * changing incubator to powershell * incubator => powershell * extending interface to azaccounts * Updated debugability, fixed error handling, extended azmodule suport, and more
1 parent c86bba5 commit 99dc247

File tree

21 files changed

+663
-401
lines changed

21 files changed

+663
-401
lines changed

docs/development.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ load-priority: 1001
118118
119119
120120
``` yaml
121-
powershellincubator: true
122121
enable-multi-api: true
123122

124123
api-folder: private/api

extensions/csharp-v2/src/operation/method.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class OperationMethod extends Method {
148148
${queryParams.length > 0 ? '+ "?"' : ''}${queryParams.joinWith(pp => `
149149
+ ${pp.serializeToNode(KnownMediaType.QueryParameter, pp.param.name).value}`, `
150150
+ "&"`
151-
)}
151+
)}
152152
).TrimEnd('?','&')`)
153153
});
154154
yield url.declarationStatement;
@@ -227,6 +227,12 @@ export class EventListener {
227227
yield `await ${this.expression.value}.Signal(${eventName}${params});`;
228228
}
229229
}
230+
*snycSignalNoCheck(eventName: Expression, ...additionalParameters: Array<string | Expression>) {
231+
if (this.emitSignals) {
232+
const params = additionalParameters.length > 0 ? `, ${additionalParameters.joinWith(each => typeof each === 'string' ? each : each.value)}` : ``;
233+
yield `${this.expression.value}.Signal(${eventName}${params}).Wait();`;
234+
}
235+
}
230236
*signal(eventName: Expression, ...additionalParameters: Array<string | Expression>) {
231237
if (this.emitSignals) {
232238
const params = additionalParameters.length > 0 ? `, ${additionalParameters.joinWith(each => typeof each === 'string' ? each : each.value)}` : ``;

extensions/csharp-v2/src/plugin-namer.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { codemodel, JsonType, processCodeModel, ModelState, VirtualProperty } from '@microsoft.azure/autorest.codemodel-v3';
6+
import { codemodel, JsonType, ModelState, processCodeModel, VirtualProperty } from '@microsoft.azure/autorest.codemodel-v3';
77

8-
import { items, length, values, keys, Dictionary, excludeXDash } from '@microsoft.azure/codegen';
9-
10-
11-
import { camelCase, deconstruct, fixLeadingNumber, pascalCase } from '@microsoft.azure/codegen';
8+
import { camelCase, deconstruct, Dictionary, excludeXDash, fixLeadingNumber, items, keys, length, pascalCase, values } from '@microsoft.azure/codegen';
129
import { System } from '@microsoft.azure/codegen-csharp';
1310

11+
import { Host } from '@microsoft.azure/autorest-extension-base';
1412
import { SchemaDetails } from './code-model';
1513
import { SchemaDefinitionResolver } from './schema/schema-resolver';
16-
import { Host } from '@microsoft.azure/autorest-extension-base';
1714

1815
export async function csnamer(service: Host) {
1916
return processCodeModel(nameStuffRight, service);
@@ -169,21 +166,21 @@ async function nameStuffRight(codeModel: codemodel.Model, service: Host): Promis
169166
}
170167
}
171168
/* IN PROGRESS : GS01
172-
169+
173170
for (const each of values(codeModel.schemas).linq.where(each => !!each.details.csharp.virtualProperties)) {
174171
// on models that have virtual properties, we're going to set nice c# names for each of them.
175172
const virtualProperties = <Dictionary<VirtualProperty>>each.details.csharp.virtualProperties;
176-
173+
177174
const mine = items(virtualProperties).linq.where(each => each.value.kind === 'my-property').linq.toArray();
178175
const parents = items(virtualProperties).linq.where(each => each.value.kind === 'parent-property').linq.toArray();
179176
const children = items(virtualProperties).linq.where(each => each.value.kind === 'child-property').linq.toArray();
180-
177+
181178
// our new virtual properties go here.
182179
const newVirtualProperties = new Dictionary<VirtualProperty>();
183-
180+
184181
// my properties (easy)
185182
for (const kv of values(mine)) {
186-
// strategy: use the least amount of things from 'propertyName' starting with the end.
183+
// strategy: use the least amount of things from 'propertyName' starting with the end.
187184
let name = '';
188185
for (let i = kv.value.propertyName.length; i > 0; i--) {
189186
name = `${name}${toPascal(kv.value.propertyName[i - 1])}`;
@@ -197,10 +194,10 @@ async function nameStuffRight(codeModel: codemodel.Model, service: Host): Promis
197194
}
198195
}
199196
}
200-
197+
201198
// parent properties (easy-ish)
202199
for (const kv of values(parents)) {
203-
// strategy: use the least amount of things from 'propertyName' starting with the end.
200+
// strategy: use the least amount of things from 'propertyName' starting with the end.
204201
let name = '';
205202
for (let i = kv.value.propertyName.length; i > 0; i--) {
206203
name = `${name}${toPascal(kv.value.propertyName[i - 1])}`;

extensions/csharp-v2/src/schema/schema-resolver.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ import { ObjectImplementation } from './object';
2222
import { String } from './string';
2323
import { Uuid } from './Uuid';
2424
import { UntypedWildcard, Wildcard } from './wildcard';
25-
2625
import { EnhancedTypeDeclaration } from './extended-type-declaration';
2726

28-
2927
export class SchemaDefinitionResolver {
30-
private cache = new Map<string, EnhancedTypeDeclaration>();
28+
private readonly cache = new Map<string, EnhancedTypeDeclaration>();
3129
private add(schema: Schema, value: EnhancedTypeDeclaration): EnhancedTypeDeclaration {
3230
this.cache.set(schema.details.default.name, value);
3331
return value;

extensions/csharp-v2/src/schema/wildcard.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ export class Wildcard implements EnhancedTypeDeclaration {
2424
}
2525

2626
get declaration(): string {
27-
return `System.Collections.Generic.IDictionary<string,${this.leafType.declaration}>`;
27+
return `System.Collections.Hashtable`;
2828
}
2929

3030
/** emits an expression to deserialize a property from a member inside a container */
3131
deserializeFromContainerMember(mediaType: KnownMediaType, container: ExpressionOrLiteral, serializedName: string, defaultValue: Expression): Expression {
3232
switch (mediaType) {
3333
case KnownMediaType.Json:
34-
return toExpression(`/* 1 */ System.Linq.Enumerable.ToDictionary<string,string, ${this.leafType.declaration}>( ${valueOf(container)}.Property("${serializedName}")?.Keys ?? System.Linq.Enumerable.Empty<string>(), each => each, each => ${this.leafType.deserializeFromNode(mediaType, `${valueOf(container)}.Property("${serializedName}").PropertyT<${ClientRuntime.JsonNode}>(each)`, toExpression('null'))} )`);
34+
return toExpression(`/* 1 */ new System.Collections.Hashtable( System.Linq.Enumerable.ToDictionary<string,string, ${this.leafType.declaration}>( ${valueOf(container)}.Property("${serializedName}")?.Keys ?? System.Linq.Enumerable.Empty<string>(), each => each, each => ${this.leafType.deserializeFromNode(mediaType, `${valueOf(container)}.Property("${serializedName}").PropertyT<${ClientRuntime.JsonNode}>(each)`, toExpression('null'))} ))`);
3535

3636
case KnownMediaType.Xml:
37-
return toExpression(`System.Linq.Enumerable.ToDictionary<string,string, ${this.leafType.declaration}>( ${valueOf(container)}?.Elements() ?? System.Linq.Enumerable.Empty<System.Xml.Linq.XElement>(), element => element.Name.ToString(), element => ${this.leafType.deserializeFromNode(mediaType, 'element', toExpression('null'))} )`);
37+
return toExpression(`new System.Collections.Hashtable(System.Linq.Enumerable.ToDictionary<string,string, ${this.leafType.declaration}>( ${valueOf(container)}?.Elements() ?? System.Linq.Enumerable.Empty<System.Xml.Linq.XElement>(), element => element.Name.ToString(), element => ${this.leafType.deserializeFromNode(mediaType, 'element', toExpression('null'))} ))`);
3838

3939
case KnownMediaType.Header: {
4040
const prefix = this.schema.extensions['x-ms-header-collection-prefix'];
4141
if (prefix) {
4242
// this is a catch for a specific set of headers
43-
return toExpression(`System.Linq.Enumerable.ToDictionary<string,string, ${this.leafType.declaration}>(System.Linq.Enumerable.Where(${valueOf(container)}, header => header.Key.StartsWith("${serializedName}")), header => header.Key.Substring(${serializedName.length}), header => System.Linq.Enumerable.FirstOrDefault(header.Value))`);
43+
return toExpression(`new System.Collections.Hashtable(System.Linq.Enumerable.ToDictionary<string,string, ${this.leafType.declaration}>(System.Linq.Enumerable.Where(${valueOf(container)}, header => header.Key.StartsWith("${serializedName}")), header => header.Key.Substring(${serializedName.length}), header => System.Linq.Enumerable.FirstOrDefault(header.Value)))`);
4444
}
45-
return toExpression(`System.Linq.Enumerable.ToDictionary<string,string, ${this.leafType.declaration}>( ${valueOf(container)}?.Elements() ?? System.Linq.Enumerable.Empty<System.Xml.Linq.XElement>(), element => element.Name.ToString(), element => ${this.leafType.deserializeFromNode(mediaType, 'element', toExpression('null'))} )`);
45+
return toExpression(`new System.Collections.Hashtable(System.Linq.Enumerable.ToDictionary<string,string, ${this.leafType.declaration}>( ${valueOf(container)}?.Elements() ?? System.Linq.Enumerable.Empty<System.Xml.Linq.XElement>(), element => element.Name.ToString(), element => ${this.leafType.deserializeFromNode(mediaType, 'element', toExpression('null'))} ))`);
4646
}
4747
}
4848
return toExpression(`null /* deserializeFromContainerMember (wildcard) doesn't support '${mediaType}' ${__filename}*/`);
@@ -53,7 +53,7 @@ export class Wildcard implements EnhancedTypeDeclaration {
5353
switch (mediaType) {
5454
case KnownMediaType.Json:
5555
const nodeAsObject = `(${(valueOf(node))} as ${ClientRuntime.JsonObject})`;
56-
return toExpression(`/* 2 */ System.Linq.Enumerable.ToDictionary<string,string, ${this.leafType.declaration}>( ${nodeAsObject}?.Keys ?? System.Linq.Enumerable.Empty<string>(), each => each, each => ${this.leafType.deserializeFromNode(mediaType, `${nodeAsObject}.PropertyT<${ClientRuntime.JsonNode}>(each)`, toExpression('null'))} )`);
56+
return toExpression(`/* 2 */ new System.Collections.Hashtable(System.Linq.Enumerable.ToDictionary<string,string, ${this.leafType.declaration}>( ${nodeAsObject}?.Keys ?? System.Linq.Enumerable.Empty<string>(), each => each, each => ${this.leafType.deserializeFromNode(mediaType, `${nodeAsObject}.PropertyT<${ClientRuntime.JsonNode}>(each)`, toExpression('null'))} ))`);
5757
}
5858
return toExpression(`null /* deserializeFromNode (wildcard) doesn't support '${mediaType}' ${__filename}*/`);
5959
}
@@ -90,13 +90,23 @@ export class Wildcard implements EnhancedTypeDeclaration {
9090

9191
/** emits the code required to serialize this into a container */
9292
serializeToContainerMember(mediaType: KnownMediaType, value: ExpressionOrLiteral, container: Variable, serializedName: string): OneOrMoreStatements {
93+
const $this = this;
9394
try {
9495
const each = pushTempVar();
9596
const item = pushTempVar();
97+
const eachvalue = pushTempVar();
98+
const innerContainer = pushTempVar();
9699

97100
switch (mediaType) {
98101
case KnownMediaType.Json:
99-
return If(`null != ${value}`, ForEach(each, toExpression(value), `AddIf( ${this.leafType.serializeToNode(mediaType, `${each}.Value`, `$$$`)},(${item}) => ${container}.Add(${each}.Key,${item} ) );`));
102+
return If(`null != ${value}`, function* () {
103+
yield `var ${innerContainer} = ${ClientRuntime.JsonObject.new()};`;
104+
yield `${container}.Add("${serializedName}", ${innerContainer});`;
105+
yield ForEach(each, `${toExpression(value)}.Keys`, function* () {
106+
yield `var ${eachvalue} = ${value}[${each}];`;
107+
yield `AddIf( ${$this.leafType.serializeToNode(mediaType, `${eachvalue} as ${$this.leafType.declaration}`, `$$$`)},(${item}) => ${innerContainer}.Add(${each} as string,${item} ) );`;
108+
});
109+
});
100110

101111
case KnownMediaType.Xml:
102112
return If(`null != ${value}`, ForEach(each, toExpression(value), `AddIf( ${this.leafType.serializeToNode(mediaType, `${each}.Value`, `$$$`)},${container}.Add );`.replace('"$$$"', `${each}.Key`)));
@@ -110,6 +120,8 @@ export class Wildcard implements EnhancedTypeDeclaration {
110120
} finally {
111121
popTempVar();
112122
popTempVar();
123+
popTempVar();
124+
popTempVar();
113125
}
114126
return `/* serializeToContainerMember (wildcard) doesn't support '${mediaType}' ${__filename}*/`;
115127
}
@@ -187,7 +199,7 @@ export class UntypedWildcard implements EnhancedTypeDeclaration {
187199
isRequired = false;
188200

189201
get declaration(): string {
190-
return `System.Collections.Generic.Dictionary<string,object>`;
202+
return `System.Collections.Hashtable`;
191203
}
192204
public validatePresence(eventListener: Variable, property: Variable): string {
193205
return `await ${eventListener}.AssertNotNull(${nameof(property.value)},${property});`.trim();

0 commit comments

Comments
 (0)