in powershell/cmdlets/class.ts [421:528]
async init() {
// basic stuff
this.addCommonStuff();
this.description = escapeString(this.operation.details.csharp.description);
const $this = this;
this.disableTransformIdentityType = await $this.state.getValue('disable-transform-identity-type', false);
this.flattenUserAssignedIdentity = await $this.state.getValue('flatten-userassignedidentity', true);
this.add(new Method('BeginProcessing', dotnet.Void, {
override: Modifier.Override,
access: Access.Protected,
description: `(overrides the default BeginProcessing method in ${PSCmdlet})`,
*body() {
if ($this.state.project.azure) {
yield `var telemetryId = ${$this.state.project.serviceNamespace.moduleClass.declaration}.Instance.GetTelemetryId.Invoke();`;
yield If('telemetryId != "" && telemetryId != "internal"', '__correlationId = telemetryId;');
}
yield 'Module.Instance.SetProxyConfiguration(Proxy, ProxyCredential, ProxyUseDefaultCredentials);';
yield If($this.$<Property>('Break'), `${ClientRuntime.AttachDebugger}.Break();`);
yield $this.eventListener.syncSignal(Events.CmdletBeginProcessing);
}
}));
// construct the class
this.NewAddClassAttributes(this.operation, this.variantName);
if (this.hasStreamOutput) {
this.outFileParameter = this.add(new Property('OutFile', System.String, { attributes: [], description: 'Path to write output file to.' }));
this.outFileParameter.add(new Attribute(ParameterAttribute, { parameters: ['Mandatory = true', 'HelpMessage = "Path to write output file to"'] }));
this.outFileParameter.add(new Attribute(ValidateNotNull));
this.outFileParameter.add(new Attribute(CategoryAttribute, { parameters: [`${ParameterCategory}.Body`] }));
}
this.NewAddPowershellParameters(this.operation);
// implement IEventListener
this.implementIEventListener();
// implement part of the IContext
this.implementIContext();
// add constructors
this.implementConstructors();
// add callback methods
this.NewImplementResponseMethod();
// processRecord
this.NewImplementProcessRecord();
// find each parameter to the method, and find out where the value is going to come from.
this.operationParameters =
values(this.apiCall.parameters).
// filter out constants and path parameters when using piping for identity
where(each => !(each.language.csharp?.constantValue) && each.language.default?.name !== '$host'/* && (!$this.isViaIdentity || each.in !== ParameterLocation.Path) */).
select(p => {
return {
name: p.language.csharp?.name,
param: values(this.properties).
where(each => each.metadata.parameterDefinition).
first(each => each.metadata.parameterDefinition.language.csharp?.serializedName === p.language.csharp?.serializedName), // xichen: Is it safe enough to use serializedName?
parameterLocation: p.protocol?.http?.in
};
}).
select(each => {
if (each.param) {
const httpParam = (<HttpParameter>(each.param.metadata.parameterDefinition));
if (httpParam.required) {
return {
name: each.param,
expression: each.param,
parameterLocation: each.parameterLocation
};
}
const httpParamTD = this.state.project.schemaDefinitionResolver.resolveTypeDeclaration((<NewSchema>httpParam.schema), httpParam.required, this.state, this.state.project.fixedArray);
return {
name: each.param,
expression: toExpression(`this.InvocationInformation.BoundParameters.ContainsKey("${each.param.value}") ? ${each.param.value} : ${httpParamTD.defaultOfType}`),
parameterLocation: each.parameterLocation
};
}
return { name: each.name, expression: dotnet.Null, parameterLocation: each.parameterLocation };
}).toArray();
this.NewImplementProcessRecordAsync();
if (this.state.project.azure) {
this.NewImplementWriteObject();
}
this.debugMode = await this.state.getValue('debug', false);
// json serialization
this.NewImplementSerialization(this.operation);
for (const prop of this.properties) {
if (prop.name === 'Host') {
prop['new'] = Modifier.New;
}
}
return this;
}