Skip to content

Instantly share code, notes, and snippets.

@ALIENQuake
Created March 16, 2022 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ALIENQuake/3fcaba9fbeb08f8a07d68dd0e6b667c4 to your computer and use it in GitHub Desktop.
Save ALIENQuake/3fcaba9fbeb08f8a07d68dd0e6b667c4 to your computer and use it in GitHub Desktop.
StopPipeline
function Show-StopPipeline {
#region Init
[void][reflection.assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
[void][reflection.assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
[System.Windows.Forms.Application]::EnableVisualStyles()
$formStopPipeline = New-Object 'System.Windows.Forms.Form'
$TestAnyNet = New-Object 'System.Windows.Forms.Button'
$TestAnySimple = New-Object 'System.Windows.Forms.Button'
$textbox1 = New-Object 'System.Windows.Forms.TextBox'
$FilterStop = New-Object 'System.Windows.Forms.Button'
$FilterStopAdv = New-Object 'System.Windows.Forms.Button'
$richtextbox1 = New-Object 'System.Windows.Forms.RichTextBox'
$listbox1 = New-Object 'System.Windows.Forms.ListBox'
$SimpleStop = New-Object 'System.Windows.Forms.Button'
$TestAnyAdv = New-Object 'System.Windows.Forms.Button'
$StopPipeline = New-Object 'System.Windows.Forms.Button'
$tv1 = New-Object 'System.Windows.Forms.TreeView'
$CommandStopper = New-Object 'System.Windows.Forms.Button'
$richtextbox2 = New-Object 'System.Windows.Forms.RichTextBox'
$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
#endregion
#region Code
$Folders = "C:\Program Files", "C:\Program Files (x86)", "C:\Windows"
$Extention = "exe"
$formStopPipeline_Load = {
$textbox1.Text = $Extention
$listbox1.Items.AddRange($Folders)
$listbox1.SetSelected(0, $true)
$richtextbox1.Text += $PSVersionTable.PSVersion; $richtextbox1.Text += [System.Environment]::NewLine
}
$tv1_AfterExpand = [System.Windows.Forms.TreeViewEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.TreeViewEventArgs]
$_.Node
}
function Test-AnySimple {
begin {
$any = $false
}
process {
$any = $true
}
end {
$any
}
}
Function Test-AnyNet {
# works only on PS 5.1
[CmdletBinding()]
param (
[ScriptBlock]$Filter,
[Parameter(ValueFromPipeline = $true)]$InputObject
)
process {
if (-not $Filter -or (Foreach-Object $Filter -InputObject $InputObject)) {
$true # Signal that at least 1 [matching] object was found
# Now that we have our result, stop the upstream commands in the
# pipeline so that they don't create more, no-longer-needed input.
(Add-Type -Passthru -TypeDefinition '
using System.Management.Automation;
namespace net.same2u.PowerShell {
public static class CustomPipelineStopper {
public static void Stop(Cmdlet cmdlet) {
throw (System.Exception) System.Activator.CreateInstance(typeof(Cmdlet).Assembly.GetType("System.Management.Automation.StopUpstreamCommandsException"), cmdlet);
}
}
}')::Stop($PSCmdlet)
}
}
end { $false }
}
function Test-AnyAdv {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline = $true)][scriptBlock]$scriptBlock = { $true },
[scriptBlock]$debugOut = $null
)
if ($debugOut) {
Write-Host("{0} | % {{{1}}}" -f $input, $scriptBlock)
}
$_ret = $false;
$_input = ($input -as [Collections.IEnumerator])
if ($_input) {
while ($_input.MoveNext()) {
$_ = $_input.Current;
Write-Host $_
if ($debugOut) {
Write-Host("Tested: [{0}]" -f (&$debugOut))
}
if (&$scriptBlock) {
if ($debugOut) {
Write-Host("Matched: [{0}]" -f (&$debugOut))
}
$_ret = $true
break
}
}
}
$_ret
}
function EnsureCommandStopperInitialized {
[CmdletBinding()]
param ()
end {
if ('UtilityProfile.CommandStopper' -as [type]) {
return
}
Add-Type -TypeDefinition '
using System;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Management.Automation;
using System.Management.Automation.Internal;
using System.Reflection;
namespace UtilityProfile
{
[EditorBrowsable(EditorBrowsableState.Never)]
[Cmdlet(VerbsLifecycle.Stop, "UpstreamCommand")]
public class CommandStopper : PSCmdlet
{
private static readonly Func<PSCmdlet, Exception> s_creator;
static CommandStopper()
{
ParameterExpression cmdlet = Expression.Parameter(typeof(PSCmdlet), "cmdlet");
s_creator = Expression.Lambda<Func<PSCmdlet, Exception>>(
Expression.New(
typeof(PSObject).Assembly
.GetType("System.Management.Automation.StopUpstreamCommandsException")
.GetConstructor(
BindingFlags.Public | BindingFlags.Instance,
null,
new Type[] { typeof(InternalCommand) },
null),
cmdlet),
"NewStopUpstreamCommandsException",
new ParameterExpression[] { cmdlet })
.Compile();
}
[Parameter(Position = 0, Mandatory = true)]
[ValidateNotNull]
public Exception Exception { get; set; }
[Hidden, EditorBrowsable(EditorBrowsableState.Never)]
public static void Stop(PSCmdlet cmdlet)
{
var exception = s_creator(cmdlet);
cmdlet.SessionState.PSVariable.Set("__exceptionToThrow", exception);
var variable = GetOrCreateVariable(cmdlet, "__exceptionToThrow");
object oldValue = variable.Value;
try
{
variable.Value = exception;
ScriptBlock.Create("& $ExecutionContext.InvokeCommand.GetCmdletByTypeName([UtilityProfile.CommandStopper]) $__exceptionToThrow")
.GetSteppablePipeline(CommandOrigin.Internal)
.Begin(false);
}
finally
{
variable.Value = oldValue;
}
}
private static PSVariable GetOrCreateVariable(PSCmdlet cmdlet, string name)
{
PSVariable result = cmdlet.SessionState.PSVariable.Get(name);
if (result != null)
{
return result;
}
result = new PSVariable(name, null);
cmdlet.SessionState.PSVariable.Set(result);
return result;
}
protected override void BeginProcessing()
{
throw Exception;
}
}
}'
}
}
function Select-FirstObject {
[Alias('first', 'top')][CmdletBinding(PositionalBinding = $false)]
param (
[Parameter(ValueFromPipeline)][psobject]$InputObject,
[Parameter(Position = 0)][ValidateRange(1, [int]::MaxValue)][int]$Count = 1
)
begin {
$amountProcessed = 0
}
process {
if ($null -eq $InputObject) {
return
}
# yield
$InputObject
$amountProcessed++
if ($amountProcessed -ge $Count) {
EnsureCommandStopperInitialized
[UtilityProfile.CommandStopper]::Stop($PSCmdlet)
}
}
}
function CreateTree-CommandStopper($startDir, $fileExt) {
$di = [System.IO.DirectoryInfo]::New("$startDir")
[System.Windows.Forms.TreeNode]$result = New-Object System.Windows.Forms.TreeNode -ArgumentList $di.Name
$searchPattern = '*' + "$fileExt"
function CreateTree($dirInfo, [System.Windows.Forms.TreeNode]$node) {
try {
foreach ($fileInfo in $dirInfo.EnumerateFiles($searchPattern)) {
$node.Nodes.Add($fileInfo.Name) | Out-Null
}
foreach ($subDir in $dirInfo.EnumerateDirectories()) {
try {
While (!($subDir.EnumerateFiles($searchPattern, [System.IO.SearchOption]::AllDirectories))) {
EnsureCommandStopperInitialized
[UtilityProfile.CommandStopper]::Stop($PSCmdlet)
}
$newNode = $null
$newNode = New-Object System.Windows.Forms.TreeNode -ArgumentList $subDir.Name
$node.Nodes.Add($newNode) | Out-Null
CreateTree -dirInfo $subDir -node $newNode
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
Add-Content -Path "C:\Users\ALIEN\Desktop\xxx.log" -Value $_.Exception.Message -Force
}
}
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
Add-Content -Path "C:\Users\ALIEN\Desktop\xxx.log" -Value $_.Exception.Message -Force
}
}
CreateTree -dirInfo $di -node $result
$result
}
function CreateTree-StopPipeline($startDir, $fileExt) {
try {
filter Stop-Pipeline([ScriptBlock]$condition = { $true }) {
$_
if (& $condition) { continue }
}
$di = [System.IO.DirectoryInfo]::New("$startDir")
[System.Windows.Forms.TreeNode]$result = New-Object System.Windows.Forms.TreeNode -ArgumentList $di.Name
$searchPattern = '*' + "$fileExt"
function CreateTree($dirInfo, [System.Windows.Forms.TreeNode]$node) {
try {
foreach ($fileInfo in $dirInfo.EnumerateFiles($searchPattern)) {
$node.Nodes.Add($fileInfo.Name) | Out-Null
}
foreach ($subDir in $dirInfo.EnumerateDirectories()) {
try {
# Optional to skip the branches with no files at any level.
$result = do {
!($subDir.EnumerateFiles($searchPattern, [System.IO.SearchOption]::AllDirectories)) | Stop-Pipeline { $_ }
}
while ($false)
$newNode = $null
$newNode = New-Object System.Windows.Forms.TreeNode -ArgumentList $subDir.Name
$node.Nodes.Add($newNode) | Out-Null
CreateTree -dirInfo $subDir -node $newNode
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
CreateTree -dirInfo $di -node $result
$result
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
function CreateTree-TestAnySimple($startDir, $fileExt) {
try {
filter Stop-Pipeline([ScriptBlock]$condition = { $true }) {
$_
if (& $condition) { continue }
}
$di = [System.IO.DirectoryInfo]::New("$startDir")
[System.Windows.Forms.TreeNode]$result = New-Object System.Windows.Forms.TreeNode -ArgumentList $di.Name
$searchPattern = '*' + "$fileExt"
function CreateTree($dirInfo, [System.Windows.Forms.TreeNode]$node) {
try {
foreach ($fileInfo in $dirInfo.EnumerateFiles($searchPattern)) {
$node.Nodes.Add($fileInfo.Name) | Out-Null
}
foreach ($subDir in $dirInfo.EnumerateDirectories()) {
try {
# Optional to skip the branches with no files at any level.
$result = do {
!($subDir.EnumerateFiles($searchPattern, [System.IO.SearchOption]::AllDirectories)) | Test-AnySimple
}
while ($false)
$newNode = $null
$newNode = New-Object System.Windows.Forms.TreeNode -ArgumentList $subDir.Name
$node.Nodes.Add($newNode) | Out-Null
CreateTree -dirInfo $subDir -node $newNode
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
CreateTree -dirInfo $di -node $result
$result
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
function CreateTree-AnyAdv($startDir, $fileExt) {
try {
filter Stop-Pipeline([ScriptBlock]$condition = { $true }) {
$_
if (& $condition) { continue }
}
$di = [System.IO.DirectoryInfo]::New("$startDir")
[System.Windows.Forms.TreeNode]$result = New-Object System.Windows.Forms.TreeNode -ArgumentList $di.Name
$searchPattern = '*' + "$fileExt"
function CreateTree($dirInfo, [System.Windows.Forms.TreeNode]$node) {
try {
foreach ($fileInfo in $dirInfo.EnumerateFiles($searchPattern)) {
$node.Nodes.Add($fileInfo.Name) | Out-Null
}
foreach ($subDir in $dirInfo.EnumerateDirectories()) {
try {
# Optional to skip the branches with no files at any level.
$result = do {
Test-AnyAdv { !($subDir.EnumerateFiles($searchPattern, [System.IO.SearchOption]::AllDirectories)) }
}
while ($false)
$newNode = $null
$newNode = New-Object System.Windows.Forms.TreeNode -ArgumentList $subDir.Name
$node.Nodes.Add($newNode) | Out-Null
CreateTree -dirInfo $subDir -node $newNode
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
CreateTree -dirInfo $di -node $result
$result
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
function CreateTree-AnyNet($startDir, $fileExt) {
try {
filter Stop-Pipeline([ScriptBlock]$condition = { $true }) {
$_
if (& $condition) { continue }
}
$di = [System.IO.DirectoryInfo]::New("$startDir")
[System.Windows.Forms.TreeNode]$result = New-Object System.Windows.Forms.TreeNode -ArgumentList $di.Name
$searchPattern = '*' + "$fileExt"
function CreateTree($dirInfo, [System.Windows.Forms.TreeNode]$node) {
try {
foreach ($fileInfo in $dirInfo.EnumerateFiles($searchPattern)) {
$node.Nodes.Add($fileInfo.Name) | Out-Null
}
foreach ($subDir in $dirInfo.EnumerateDirectories()) {
try {
# Optional to skip the branches with no files at any level.
$result = do {
!($subDir.EnumerateFiles($searchPattern, [System.IO.SearchOption]::AllDirectories)) | Test-AnyNet
}
while ($false)
$newNode = $null
$newNode = New-Object System.Windows.Forms.TreeNode -ArgumentList $subDir.Name
$node.Nodes.Add($newNode) | Out-Null
CreateTree -dirInfo $subDir -node $newNode
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
CreateTree -dirInfo $di -node $result
$result
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
function CreateTree-SimpleStop($startDir, $fileExt) {
try {
filter Stop-Pipeline([ScriptBlock]$condition = { $true }) {
$_
if (& $condition) { continue }
}
$di = [System.IO.DirectoryInfo]::New("$startDir")
[System.Windows.Forms.TreeNode]$result = New-Object System.Windows.Forms.TreeNode -ArgumentList $di.Name
$searchPattern = '*' + "$fileExt"
function CreateTree($dirInfo, [System.Windows.Forms.TreeNode]$node) {
try {
foreach ($fileInfo in $dirInfo.EnumerateFiles($searchPattern)) {
$node.Nodes.Add($fileInfo.Name) | Out-Null
}
foreach ($subDir in $dirInfo.EnumerateDirectories()) {
try {
# Optional to skip the branches with no files at any level.
$result = do {
!($subDir.EnumerateFiles($searchPattern, [System.IO.SearchOption]::AllDirectories)) | where { $_ } | foreach { $true } | select -first 1
}
while ($false)
$newNode = $null
$newNode = New-Object System.Windows.Forms.TreeNode -ArgumentList $subDir.Name
$node.Nodes.Add($newNode) | Out-Null
CreateTree -dirInfo $subDir -node $newNode
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
CreateTree -dirInfo $di -node $result
$result
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
function CreateTree-FilterStop($startDir, $fileExt) {
try {
filter Stop-Pipeline([ScriptBlock]$condition = { $true }) {
$_
if (& $condition) { continue }
}
$di = [System.IO.DirectoryInfo]::New("$startDir")
[System.Windows.Forms.TreeNode]$result = New-Object System.Windows.Forms.TreeNode -ArgumentList $di.Name
$searchPattern = '*' + "$fileExt"
function CreateTree($dirInfo, [System.Windows.Forms.TreeNode]$node) {
try {
foreach ($fileInfo in $dirInfo.EnumerateFiles($searchPattern)) {
$node.Nodes.Add($fileInfo.Name) | Out-Null
}
foreach ($subDir in $dirInfo.EnumerateDirectories()) {
try {
# Optional to skip the branches with no files at any level.
$result = do {
!($subDir.EnumerateFiles($searchPattern, [System.IO.SearchOption]::AllDirectories)) | ? { Stop-Pipeline }
}
while ($false)
$newNode = $null
$newNode = New-Object System.Windows.Forms.TreeNode -ArgumentList $subDir.Name
$node.Nodes.Add($newNode) | Out-Null
CreateTree -dirInfo $subDir -node $newNode
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
CreateTree -dirInfo $di -node $result
$result
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
function CreateTree-FilterStopAdv($startDir, $fileExt) {
try {
Filter Stop-PipelineAdv {
$sp = { Select-Object -First 1 }.GetSteppablePipeline($MyInvocation.CommandOrigin)
$sp.Begin($true)
$sp.Process(0)
}
# Example
#1 .. 5 | % { if ($_) { Stop-PipelineAdv }; $_ }
$di = [System.IO.DirectoryInfo]::New("$startDir")
[System.Windows.Forms.TreeNode]$result = New-Object System.Windows.Forms.TreeNode -ArgumentList $di.Name
$searchPattern = '*' + "$fileExt"
function CreateTree($dirInfo, [System.Windows.Forms.TreeNode]$node) {
try {
foreach ($fileInfo in $dirInfo.EnumerateFiles($searchPattern)) {
$node.Nodes.Add($fileInfo.Name) | Out-Null
}
foreach ($subDir in $dirInfo.EnumerateDirectories()) {
try {
# Optional to skip the branches with no files at any level.
$result = do {
!($subDir.EnumerateFiles($searchPattern, [System.IO.SearchOption]::AllDirectories)) | ? { Stop-PipelineAdv }
}
while ($false)
$newNode = $null
$newNode = New-Object System.Windows.Forms.TreeNode -ArgumentList $subDir.Name
$node.Nodes.Add($newNode) | Out-Null
CreateTree -dirInfo $subDir -node $newNode
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
CreateTree -dirInfo $di -node $result
$result
}
catch {
# Skip exceptions like UnauthorizedAccessException and continue...
Write-Host $_.Exception.Message
}
}
$CommandStopper_Click = {
$tv1.Nodes.Clear()
$richtextbox1.Clear()
$richtextbox2.Clear()
$dir = $listbox1.SelectedItem.ToString()
$ext = '.' + ($textbox1.Text).TrimStart('.')
$time = Measure-Command -Expression {
$dataNodes = CreateTree-CommandStopper -startDir $dir -fileExt $ext
if ($dataNodes.Nodes.Count -ne 0) {
$tv1.Nodes.Add($dataNodes)
$dataNodes.Expand()
}
}
$time
$richtextbox1.Text += $time.TotalSeconds; $richtextbox1.Text += [System.Environment]::NewLine
}
$StopPipeline_Click = {
$tv1.Nodes.Clear()
$richtextbox1.Clear()
$richtextbox2.Clear()
$dir = $listbox1.SelectedItem.ToString()
$ext = '.' + ($textbox1.Text).TrimStart('.')
$time = Measure-Command -Expression {
$dataNodes = CreateTree-StopPipeline -startDir $dir -fileExt $ext
if ($dataNodes.Nodes.Count -ne 0) {
$tv1.Nodes.Add($dataNodes)
$dataNodes.Expand()
}
}
$time
$richtextbox1.Text += $time.TotalSeconds; $richtextbox1.Text += [System.Environment]::NewLine
}
$TestAnySimple_Click = {
$tv1.Nodes.Clear()
$richtextbox1.Clear()
$richtextbox2.Clear()
$dir = $listbox1.SelectedItem.ToString()
$ext = '.' + ($textbox1.Text).TrimStart('.')
$time = Measure-Command -Expression {
$dataNodes = CreateTree-TestAnySimple -startDir $dir -fileExt $ext
if ($dataNodes.Nodes.Count -ne 0) {
$tv1.Nodes.Add($dataNodes)
$dataNodes.Expand()
}
}
$time
$richtextbox1.Text += $time.TotalSeconds; $richtextbox1.Text += [System.Environment]::NewLine
}
$TestAnyAdv_Click = {
$tv1.Nodes.Clear()
$richtextbox1.Clear()
$richtextbox2.Clear()
$dir = $listbox1.SelectedItem.ToString()
$ext = '.' + ($textbox1.Text).TrimStart('.')
$time = Measure-Command -Expression {
$dataNodes = CreateTree-AnyAdv -startDir $dir -fileExt $ext
if ($dataNodes.Nodes.Count -ne 0) {
$tv1.Nodes.Add($dataNodes)
$dataNodes.Expand()
}
}
$time
$richtextbox1.Text += $time.TotalSeconds; $richtextbox1.Text += [System.Environment]::NewLine
}
$SimpleStop_Click = {
$tv1.Nodes.Clear()
$richtextbox1.Clear()
$richtextbox2.Clear()
$dir = $listbox1.SelectedItem.ToString()
$ext = '.' + ($textbox1.Text).TrimStart('.')
$time = Measure-Command -Expression {
$dataNodes = CreateTree-SimpleStop -startDir $dir -fileExt $ext
if ($dataNodes.Nodes.Count -ne 0) {
$tv1.Nodes.Add($dataNodes)
$dataNodes.Expand()
}
}
$time
$richtextbox1.Text += $time.TotalSeconds; $richtextbox1.Text += [System.Environment]::NewLine
}
$FilterStopAdv_Click={
$tv1.Nodes.Clear()
$richtextbox1.Clear()
$richtextbox2.Clear()
$dir = $listbox1.SelectedItem.ToString()
$ext = '.' + ($textbox1.Text).TrimStart('.')
$time = Measure-Command -Expression {
$dataNodes = CreateTree-FilterStopAdv -startDir $dir -fileExt $ext
if ($dataNodes.Nodes.Count -ne 0) {
$tv1.Nodes.Add($dataNodes)
$dataNodes.Expand()
}
}
$time
$richtextbox1.Text += $time.TotalSeconds; $richtextbox1.Text += [System.Environment]::NewLine
}
$FilterStop_Click= {
$tv1.Nodes.Clear()
$richtextbox1.Clear()
$richtextbox2.Clear()
$dir = $listbox1.SelectedItem.ToString()
$ext = '.' + ($textbox1.Text).TrimStart('.')
$time = Measure-Command -Expression {
$dataNodes = CreateTree-FilterStop -startDir $dir -fileExt $ext
if ($dataNodes.Nodes.Count -ne 0) {
$tv1.Nodes.Add($dataNodes)
$dataNodes.Expand()
}
}
$time
$richtextbox1.Text += $time.TotalSeconds; $richtextbox1.Text += [System.Environment]::NewLine
}
$TestAnyNet_Click={
$tv1.Nodes.Clear()
$richtextbox1.Clear()
$richtextbox2.Clear()
$dir = $listbox1.SelectedItem.ToString()
$ext = '.' + ($textbox1.Text).TrimStart('.')
$time = Measure-Command -Expression {
$dataNodes = CreateTree-AnyAdv -startDir $dir -fileExt $ext
if ($dataNodes.Nodes.Count -ne 0) {
$tv1.Nodes.Add($dataNodes)
$dataNodes.Expand()
}
}
$time
$richtextbox1.Text += $time.TotalSeconds; $richtextbox1.Text += [System.Environment]::NewLine
}
#endregion
#region Generated Events
$Form_Cleanup_FormClosed=
{
#Remove all event handlers from the controls
try
{
$TestAnyNet.remove_Click($TestAnyNet_Click)
$TestAnySimple.remove_Click($TestAnySimple_Click)
$FilterStop.remove_Click($FilterStop_Click)
$FilterStopAdv.remove_Click($FilterStopAdv_Click)
$SimpleStop.remove_Click($SimpleStop_Click)
$TestAnyAdv.remove_Click($TestAnyAdv_Click)
$StopPipeline.remove_Click($StopPipeline_Click)
$tv1.remove_AfterExpand($tv1_AfterExpand)
$CommandStopper.remove_Click($CommandStopper_Click)
$formStopPipeline.remove_Load($formStopPipeline_Load)
$formStopPipeline.remove_FormClosed($Form_Cleanup_FormClosed)
}
catch { Out-Null <# Prevent PSScriptAnalyzer warning #> }
}
#endregion Generated Events
#region Generated Form Code
$formStopPipeline.SuspendLayout()
#
# formStopPipeline
#
$formStopPipeline.Controls.Add($TestAnyNet)
$formStopPipeline.Controls.Add($TestAnySimple)
$formStopPipeline.Controls.Add($textbox1)
$formStopPipeline.Controls.Add($FilterStop)
$formStopPipeline.Controls.Add($FilterStopAdv)
$formStopPipeline.Controls.Add($richtextbox1)
$formStopPipeline.Controls.Add($listbox1)
$formStopPipeline.Controls.Add($SimpleStop)
$formStopPipeline.Controls.Add($TestAnyAdv)
$formStopPipeline.Controls.Add($StopPipeline)
$formStopPipeline.Controls.Add($tv1)
$formStopPipeline.Controls.Add($CommandStopper)
$formStopPipeline.Controls.Add($richtextbox2)
$formStopPipeline.AutoScaleDimensions = New-Object System.Drawing.SizeF(6, 13)
$formStopPipeline.AutoScaleMode = 'Font'
$formStopPipeline.ClientSize = New-Object System.Drawing.Size(1027, 712)
$formStopPipeline.Name = 'formStopPipeline'
$formStopPipeline.Text = 'StopPipeline'
$formStopPipeline.add_Load($formStopPipeline_Load)
#
# TestAnyNet
#
$TestAnyNet.Location = New-Object System.Drawing.Point(844, 42)
$TestAnyNet.Name = 'TestAnyNet'
$TestAnyNet.Size = New-Object System.Drawing.Size(171, 23)
$TestAnyNet.TabIndex = 15
$TestAnyNet.Text = 'TestAnyNet'
$TestAnyNet.UseVisualStyleBackColor = $True
$TestAnyNet.add_Click($TestAnyNet_Click)
#
# TestAnySimple
#
$TestAnySimple.Location = New-Object System.Drawing.Point(654, 70)
$TestAnySimple.Name = 'TestAnySimple'
$TestAnySimple.Size = New-Object System.Drawing.Size(184, 23)
$TestAnySimple.TabIndex = 14
$TestAnySimple.Text = 'TestAnySimple'
$TestAnySimple.UseVisualStyleBackColor = $True
$TestAnySimple.add_Click($TestAnySimple_Click)
#
# textbox1
#
$textbox1.Location = New-Object System.Drawing.Point(295, 13)
$textbox1.Name = 'textbox1'
$textbox1.Size = New-Object System.Drawing.Size(353, 20)
$textbox1.TabIndex = 13
$textbox1.WordWrap = $False
#
# FilterStop
#
$FilterStop.Location = New-Object System.Drawing.Point(654, 99)
$FilterStop.Name = 'FilterStop'
$FilterStop.Size = New-Object System.Drawing.Size(184, 23)
$FilterStop.TabIndex = 12
$FilterStop.Text = 'FilterStop'
$FilterStop.UseVisualStyleBackColor = $True
$FilterStop.add_Click($FilterStop_Click)
#
# FilterStopAdv
#
$FilterStopAdv.Location = New-Object System.Drawing.Point(844, 99)
$FilterStopAdv.Name = 'FilterStopAdv'
$FilterStopAdv.Size = New-Object System.Drawing.Size(171, 23)
$FilterStopAdv.TabIndex = 11
$FilterStopAdv.Text = 'FilterStopAdv'
$FilterStopAdv.UseVisualStyleBackColor = $True
$FilterStopAdv.add_Click($FilterStopAdv_Click)
#
# richtextbox1
#
$richtextbox1.Anchor = 'Top, Bottom, Left'
$richtextbox1.Location = New-Object System.Drawing.Point(294, 127)
$richtextbox1.Name = 'richtextbox1'
$richtextbox1.ScrollBars = 'ForcedVertical'
$richtextbox1.Size = New-Object System.Drawing.Size(354, 573)
$richtextbox1.TabIndex = 10
$richtextbox1.Text = ''
#
# listbox1
#
$listbox1.FormattingEnabled = $True
$listbox1.Location = New-Object System.Drawing.Point(294, 39)
$listbox1.Name = 'listbox1'
$listbox1.Size = New-Object System.Drawing.Size(354, 82)
$listbox1.TabIndex = 9
#
# SimpleStop
#
$SimpleStop.Location = New-Object System.Drawing.Point(844, 13)
$SimpleStop.Name = 'SimpleStop'
$SimpleStop.Size = New-Object System.Drawing.Size(171, 23)
$SimpleStop.TabIndex = 6
$SimpleStop.Text = 'SimpleStop'
$SimpleStop.UseVisualStyleBackColor = $True
$SimpleStop.add_Click($SimpleStop_Click)
#
# TestAnyAdv
#
$TestAnyAdv.Location = New-Object System.Drawing.Point(844, 70)
$TestAnyAdv.Name = 'TestAnyAdv'
$TestAnyAdv.Size = New-Object System.Drawing.Size(171, 23)
$TestAnyAdv.TabIndex = 5
$TestAnyAdv.Text = 'TestAnyAdv'
$TestAnyAdv.UseVisualStyleBackColor = $True
$TestAnyAdv.add_Click($TestAnyAdv_Click)
#
# StopPipeline
#
$StopPipeline.Location = New-Object System.Drawing.Point(654, 39)
$StopPipeline.Name = 'StopPipeline'
$StopPipeline.Size = New-Object System.Drawing.Size(184, 23)
$StopPipeline.TabIndex = 3
$StopPipeline.Text = 'StopPipeline'
$StopPipeline.UseVisualStyleBackColor = $True
$StopPipeline.add_Click($StopPipeline_Click)
#
# tv1
#
$tv1.Anchor = 'Top, Bottom, Left'
$tv1.Location = New-Object System.Drawing.Point(12, 12)
$tv1.Name = 'tv1'
$tv1.Size = New-Object System.Drawing.Size(276, 688)
$tv1.TabIndex = 1
$tv1.add_AfterExpand($tv1_AfterExpand)
#
# CommandStopper
#
$CommandStopper.Location = New-Object System.Drawing.Point(654, 12)
$CommandStopper.Name = 'CommandStopper'
$CommandStopper.Size = New-Object System.Drawing.Size(184, 23)
$CommandStopper.TabIndex = 0
$CommandStopper.Text = 'CommandStopper'
$CommandStopper.UseVisualStyleBackColor = $True
$CommandStopper.add_Click($CommandStopper_Click)
#
# richtextbox2
#
$richtextbox2.Anchor = 'Top, Bottom, Left, Right'
$richtextbox2.Location = New-Object System.Drawing.Point(654, 127)
$richtextbox2.Name = 'richtextbox2'
$richtextbox2.ScrollBars = 'ForcedVertical'
$richtextbox2.Size = New-Object System.Drawing.Size(361, 573)
$richtextbox2.TabIndex = 8
$richtextbox2.Text = ''
$formStopPipeline.ResumeLayout()
#endregion Generated Form Code
#Clean up the control events
$formStopPipeline.add_FormClosed($Form_Cleanup_FormClosed)
#Show the Form
return $formStopPipeline.ShowDialog()
} #End Function
Show-StopPipeline | Out-Null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment