Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 164553b

Browse files
committed
Adding the C# functions back
1 parent c3b1ea6 commit 164553b

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

PSSwagger.psm1

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,92 @@ function removeSpecialChars
277277
return $resultStr
278278
}
279279

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

0 commit comments

Comments
 (0)