Last active
September 14, 2024 20:01
-
-
Save AntonZhelezniakou-WTG/96d09880a619173c7dff5a1962152752 to your computer and use it in GitHub Desktop.
(Powershell) Find linked messages order by EM_SystemCreateTimeUtc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $SearchPath = 'c:\git\wtg\CargoWise\Dev\Enterprise\Product\' | |
| $OutputFile = 'result.txt' | |
| if (Test-Path $OutputFile) { | |
| Remove-Item $OutputFile | |
| } | |
| Get-ChildItem -Path $SearchPath -Filter *.cs -Recurse | Where-Object { | |
| $_.Name -notmatch 'Test\.cs$' -and $_.FullName -notmatch '\.Test[\\/]' -notmatch '\.Designer\.cs$' | |
| } | ForEach-Object { | |
| $file = $_.FullName | |
| $lines = Get-Content -Path $file | |
| $lineCount = $lines.Length | |
| $linesWithCreateTime = @(for($i=0; $i -lt $lineCount; $i++) { if($lines[$i] -cmatch '\bEM_SystemCreateTimeUtc\b') { $i } }) | |
| $linesWithOtherPatterns = @(for($i=0; $i -lt $lineCount; $i++) { if($lines[$i] -cmatch '\bEM_LinkUniqueID\b|\bMessages\b') { $i } }) | |
| foreach($lineNum in $linesWithCreateTime) { | |
| foreach($otherLineNum in $linesWithOtherPatterns) { | |
| if([math]::Abs($lineNum - $otherLineNum) -le 5) { | |
| Add-Content -Path $OutputFile -Value '// ---------------------' | |
| Add-Content -Path $OutputFile -Value "// $file" | |
| Add-Content -Path $OutputFile -Value '' | |
| $startLine = [math]::Max($lineNum - 5, 0) | |
| $endLine = [math]::Min($lineNum + 5, $lineCount - 1) | |
| for($j = $startLine; $j -le $endLine; $j++) { | |
| Add-Content -Path $OutputFile -Value $lines[$j] | |
| } | |
| Add-Content -Path $OutputFile -Value '' | |
| break | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment