@@ -138,56 +138,54 @@ function Start-WebScrapping {
138138 $Snippets = New-Object - TypeName ' System.Collections.ArrayList' ;
139139 try {
140140 ($readStream , $HttpWebResponse , $IsSuccess ) = FetchStream - GraphDocsUrl $GraphDocsUrl
141- if ($IsSuccess -eq $False ) {
142- Write-Host " The url $GraphDocsUrl is invalid. Please ensure that the url is correct"
143- return
144- }
145- while (-not $readStream.EndOfStream ) {
146- $Line = $readStream.ReadLine ()
147- if ($Line -match " ^### Example" ) {
148- $H = $HeaderList.Add ($Line )
149- }
150- if ($Line -match " /includes/snippets/powershell/" ) {
151- $Line = $Line.Replace (" [!INCLUDE [sample-code](.." , " " )
152- $SnippetPath = $Line.Replace (" )" , " " ).Replace(" ]" , " " )
153- $SnippetUrl = $GraphDocsUrl.Replace (" /api/$LastPathSegment " , $SnippetPath )
154- $E = $ExampleLinks.Add ($SnippetUrl )
141+ if ($IsSuccess ) {
142+ while (-not $readStream.EndOfStream ) {
143+ $Line = $readStream.ReadLine ()
144+ if ($Line -match " ^### Example" ) {
145+ $H = $HeaderList.Add ($Line )
146+ }
147+ if ($Line -match " /includes/snippets/powershell/" ) {
148+ $Line = $Line.Replace (" [!INCLUDE [sample-code](.." , " " )
149+ $SnippetPath = $Line.Replace (" )" , " " ).Replace(" ]" , " " )
150+ $SnippetUrl = $GraphDocsUrl.Replace (" /api/$LastPathSegment " , $SnippetPath )
151+ $E = $ExampleLinks.Add ($SnippetUrl )
152+ }
155153 }
156- }
157- $HttpWebResponse.Close ()
158- $readStream.Close ()
154+ $HttpWebResponse.Close ()
155+ $readStream.Close ()
159156
160- foreach ($Link in $ExampleLinks ) {
161- $ConstructedSnippet = " " ;
157+ foreach ($Link in $ExampleLinks ) {
158+ $ConstructedSnippet = " " ;
162159 ($Rs , $HttpResponse ) = FetchStream - GraphDocsUrl $Link
163- while (-not $Rs.EndOfStream ) {
164- $Snippet = $Rs.ReadLine ()
160+ while (-not $Rs.EndOfStream ) {
161+ $Snippet = $Rs.ReadLine ()
165162
166- # Write-Host $desc
167- $Snippet = $Snippet.Replace (" ---" , " " )
168- $Snippet = $Snippet.Replace (' description: "Automatically generated file. DO NOT MODIFY"' , " " )
169- $ConstructedSnippet += $Snippet + " `n "
163+ # Write-Host $desc
164+ $Snippet = $Snippet.Replace (" ---" , " " )
165+ $Snippet = $Snippet.Replace (' description: "Automatically generated file. DO NOT MODIFY"' , " " )
166+ $ConstructedSnippet += $Snippet + " `n "
170167
168+ }
169+ $S = $Snippets.Add ($ConstructedSnippet )
171170 }
172- $S = $Snippets.Add ($ConstructedSnippet )
173- }
174- if ($HeaderList.Count -ne $Snippets.Count ) {
175- $HeaderList.Clear ()
176- for ($d = 0 ; $d -lt $Snippets.Count ; $d ++ ) {
177- $sum = $d + 1
178- $H = $HeaderList.Add (" ### Example " + $sum + " : Code snippet" .Trim())
171+ if ($HeaderList.Count -ne $Snippets.Count ) {
172+ $HeaderList.Clear ()
173+ for ($d = 0 ; $d -lt $Snippets.Count ; $d ++ ) {
174+ $sum = $d + 1
175+ $H = $HeaderList.Add (" ### Example " + $sum + " : Code snippet" .Trim())
176+ }
179177 }
180- }
181178
182- $ExampleFile = " $GraphProfilePath /$Command .md"
183- $url = $ExternalDocUrl
184- if ($GraphProfile -eq " beta" ) {
185- $url = $url.Replace (" graph-rest-1.0" , " graph-rest-beta" )
186- }
187- $DescriptionCommand = $Command
188- $Description = " This example shows how to use the $DescriptionCommand Cmdlet."
179+ $ExampleFile = " $GraphProfilePath /$Command .md"
180+ $url = $ExternalDocUrl
181+ if ($GraphProfile -eq " beta" ) {
182+ $url = $url.Replace (" graph-rest-1.0" , " graph-rest-beta" )
183+ }
184+ $DescriptionCommand = $Command
185+ $Description = " This example shows how to use the $DescriptionCommand Cmdlet."
189186
190- Update-ExampleFile - GraphProfile $GraphProfile - HeaderList $HeaderList - ExampleList $Snippets - ExampleFile $ExampleFile - Description $Description - Command $Command - ExternalDocUrl $url - UriPath $UriPath - Module $Module
187+ Update-ExampleFile - GraphProfile $GraphProfile - HeaderList $HeaderList - ExampleList $Snippets - ExampleFile $ExampleFile - Description $Description - Command $Command - ExternalDocUrl $url - UriPath $UriPath - Module $Module
188+ }
191189 }
192190 catch {
193191 Write-Host " `n Error Message: " $_.Exception.Message
@@ -226,13 +224,13 @@ function FetchStream {
226224 param (
227225 [string ]$GraphDocsUrl
228226 )
229- try {
230- $HttpWebRequest = [System.Net.WebRequest ]::Create($GraphDocsUrl )
231- $HttpWebResponse = $HttpWebRequest.GetResponse ()
232- $ReceiveStream = $HttpWebResponse.GetResponseStream ()
233- $Encode = [System.Text.Encoding ]::GetEncoding(" utf-8" )
234- $ReadStream = [System.IO.StreamReader ]::new($ReceiveStream , $Encode )
235- return ($ReadStream , $HttpWebResponse , $True )
227+ try {
228+ $HttpWebRequest = [System.Net.WebRequest ]::Create($GraphDocsUrl )
229+ $HttpWebResponse = $HttpWebRequest.GetResponse ()
230+ $ReceiveStream = $HttpWebResponse.GetResponseStream ()
231+ $Encode = [System.Text.Encoding ]::GetEncoding(" utf-8" )
232+ $ReadStream = [System.IO.StreamReader ]::new($ReceiveStream , $Encode )
233+ return ($ReadStream , $HttpWebResponse , $True )
236234 }
237235 catch {
238236 return ($null , $null , $False )
0 commit comments