@@ -291,4 +291,92 @@ function removeSpecialChars
291291 return $resultStr
292292}
293293
294+ # endregion
295+
296+ # region Module Generation Helpers
297+
298+ function GenerateCsharpCode
299+ {
300+ param (
301+ [Parameter (Mandatory = $true )]
302+ [string ] $swaggerSpecPath ,
303+
304+ [Parameter (Mandatory = $true )]
305+ [string ] $path ,
306+
307+ [Parameter (Mandatory = $true )]
308+ [string ] $moduleName ,
309+
310+ [Parameter (Mandatory = $true )]
311+ [string ] $nameSpace
312+
313+ )
314+
315+ Write-Verbose " Generating CSharp Code using AutoRest"
316+
317+ $autoRestExePath = get-command autorest.exe | % source
318+ if (-not $autoRestExePath )
319+ {
320+ throw " Unable to find AutoRest.exe in PATH environment. Ensure the PATH is updated."
321+ }
322+
323+ $outputDirectory = $path
324+ $outAssembly = join-path $outputDirectory azure.csharp.ps.generated.dll
325+ $net45Dir = join-path $outputDirectory " Net45"
326+ $generatedCSharpPath = Join-Path $outputDirectory " Generated.Csharp"
327+ $startUpScriptFile = (join-path $outputDirectory $moduleName ) + " .StartupScript.ps1"
328+ $moduleManifestFile = (join-path $outputDirectory $moduleName ) + " .psd1"
329+
330+ if (Test-Path $outAssembly )
331+ {
332+ del $outAssembly - Force
333+ }
334+
335+ if (Test-Path $net45Dir )
336+ {
337+ del $net45Dir - Force - Recurse
338+ }
339+
340+ & $autoRestExePath - input $swaggerSpecPath - CodeGenerator CSharp - OutputDirectory $generatedCSharpPath - NameSpace $nameSpace
341+ if ($LastExitCode )
342+ {
343+ throw " AutoRest resulted in an error"
344+ }
345+
346+ Write-Verbose " Generating assembly from the CSharp code"
347+
348+ $srcContent = dir $generatedCSharpPath - Filter * .cs - Recurse - Exclude Program.cs, TemporaryGeneratedFile* | ? DirectoryName -notlike ' *Azure.Csharp.Generated*' | % { " // File $ ( $_.FullName ) " ; get-content $_.FullName }
349+ $oneSrc = $srcContent -join " `n "
350+
351+ $refassemlbiles = @ (" System.dll" , " System.Core.dll" , " System.Net.Http.dll" ,
352+ " System.Net.Http.WebRequest" , " System.Runtime.Serialization.dll" , " System.Xml.dll" ,
353+ " $PSScriptRoot \Generated.Azure.Common.Helpers\Net45\Microsoft.Rest.ClientRuntime.dll" ,
354+ " $PSScriptRoot \Generated.Azure.Common.Helpers\Net45\Newtonsoft.Json.dll" )
355+
356+ Add-Type - TypeDefinition $oneSrc - ReferencedAssemblies $refassemlbiles - OutputAssembly $outAssembly
357+ }
358+
359+ function GenerateModuleManifest
360+ {
361+ param (
362+ [Parameter (Mandatory = $true )]
363+ [string ] $path ,
364+
365+ [Parameter (Mandatory = $true )]
366+ [string ] $moduleName ,
367+
368+ [Parameter (Mandatory = $true )]
369+ [string ] $rootModule
370+ )
371+
372+ $startUpScriptFile = (join-path $path $moduleName ) + " .StartupScript.ps1"
373+ $moduleManifestFile = (join-path $path $moduleName ) + " .psd1"
374+
375+ @'
376+ Add-Type -LiteralPath "$PSScriptRoot\azure.csharp.ps.generated.dll"
377+ '@ | out-file - Encoding Ascii $startUpScriptFile
378+
379+ New-ModuleManifest - Path $moduleManifestFile - Guid (New-Guid ) - Author (whoami) - ScriptsToProcess ($moduleName + " .StartupScript.ps1" ) - RequiredModules " Generated.Azure.Common.Helpers" - RootModule " $rootModule "
380+ }
381+
294382# endregion
0 commit comments