Skip to content

Instantly share code, notes, and snippets.

@AntonZhelezniakou-WTG
Last active September 14, 2024 20:01
Show Gist options
  • Select an option

  • Save AntonZhelezniakou-WTG/96d09880a619173c7dff5a1962152752 to your computer and use it in GitHub Desktop.

Select an option

Save AntonZhelezniakou-WTG/96d09880a619173c7dff5a1962152752 to your computer and use it in GitHub Desktop.
(Powershell) Find linked messages order by EM_SystemCreateTimeUtc
$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