Skip to content

Commit 59b6fcc

Browse files
committed
Refactoring
Extracted Get-PipelineProcessor
1 parent f365fda commit 59b6fcc

File tree

4 files changed

+34
-26
lines changed

4 files changed

+34
-26
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function Get-PipelineProcessor {
2+
param (
3+
[Parameter(Mandatory = $true, Position = 0 )]
4+
[string]$Name,
5+
6+
[Parameter(Mandatory = $true, Position = 0 )]
7+
[System.Object[]]$Parameters
8+
)
9+
process {
10+
Get-Command -Name $Name -CommandType Alias | `
11+
Sort-Object -Property Name | `
12+
? { $_.Parameters.Count -gt 0 } | `
13+
? {
14+
$commandParameters = $_.Parameters
15+
$valid = $true
16+
$Parameters | % {
17+
$valid = $valid -and ($commandParameters.ContainsKey($_.Name) -and $commandParameters[$_.Name].ParameterType.Name -eq $_.Type)
18+
}
19+
$valid
20+
}
21+
}
22+
}

Slack.Backup/Private/pipelines/Invoke-FileDataProcessingPipeline.ps1

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ function Invoke-FileDataProcessingPipeline {
44
[byte[]]$SlackFile
55
)
66
process {
7-
Get-Command -Name Invoke-FileDataProcessor* -CommandType Alias | `
8-
Sort-Object -Property Name | `
9-
? { $_.Parameters.Count -gt 0 } | `
10-
? { $_.Parameters.ContainsKey("SlackFile") } | `
11-
? { $_.Parameters['SlackFile'].ParameterType.Name -eq [byte[]] } | `
12-
% {
13-
Write-Verbose "Invoking processor: $($_.Name)"
14-
$SlackFile = &($_.Name) -SlackFile $SlackFile
15-
}
7+
Get-PipelineProcessor -Name Invoke-FileDataProcessor* -Parameters @( @{Name = "SlackFile"; Type = [byte[]] } ) | % {
8+
Write-Verbose "Invoking processor: $($_.Name)"
9+
$SlackFile = &($_.Name) -SlackFile $SlackFile
10+
}
1611
$SlackFile
1712
}
1813
}

Slack.Backup/Private/pipelines/Invoke-FileProcessingPipeline.ps1

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ function Invoke-FileProcessingPipeline {
44
[System.Object]$SlackFile
55
)
66
process {
7-
Get-Command -Name Invoke-FileProcessor* -CommandType Alias | `
8-
Sort-Object -Property Name | `
9-
? { $_.Parameters.Count -gt 0 } | `
10-
? { $_.Parameters.ContainsKey("SlackFile") } | `
11-
? { $_.Parameters['SlackFile'].ParameterType.Name -eq "Object" } | `
12-
% {
13-
Write-Verbose "Invoking processor: $($_.Name)"
14-
$SlackFile = &($_.Name) -SlackFile $SlackFile
15-
}
7+
Get-PipelineProcessor -Name Invoke-FileProcessor* -Parameters @( @{Name = "SlackFile"; Type = "Object" } ) | % {
8+
Write-Verbose "Invoking processor: $($_.Name)"
9+
$SlackFile = &($_.Name) -SlackFile $SlackFile
10+
}
1611
$SlackFile
1712
}
1813
}

Slack.Backup/Private/pipelines/Invoke-MessageProcessingPipeline.ps1

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ function Invoke-MessageProcessingPipeline {
44
[System.Object]$SlackMessage
55
)
66
process {
7-
Get-Command -Name Invoke-MessageProcessor* -CommandType Alias | `
8-
Sort-Object -Property Name | `
9-
? { $_.Parameters.ContainsKey("SlackMessage") } | `
10-
? { $_.Parameters['SlackMessage'].ParameterType.Name -eq "Object" } | `
11-
% {
12-
Write-Verbose "Invoking processor: $($_.Name)"
13-
$SlackMessage = &($_.Name) -SlackMessage $SlackMessage
14-
}
7+
Get-PipelineProcessor -Name Invoke-MessageProcessor* -Parameters @( @{Name = "SlackMessage"; Type = "Object" } ) | % {
8+
Write-Verbose "Invoking processor: $($_.Name)"
9+
$SlackMessage = &($_.Name) -SlackMessage $SlackMessage
10+
}
1511
$SlackMessage
1612
}
1713
}

0 commit comments

Comments
 (0)