Skip to content

Instantly share code, notes, and snippets.

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 PragmaticPraxis/38cebda38d152db8729f524520a6919c to your computer and use it in GitHub Desktop.
Save PragmaticPraxis/38cebda38d152db8729f524520a6919c to your computer and use it in GitHub Desktop.
class ProcessQueue {
# Properties
hidden static [ProcessQueue] $singleton = $null
hidden [System.Collections.Generic.List[object]]$Queue = [System.Collections.Generic.List[object]]::New()
# hide instance constructor, no one should call this directly
hidden ProcessQueue () {}
# Use a static constructor to initialize singleton
static ProcessQueue () {
[ProcessQueue]::singleton = [ProcessQueue]::New()
}
# Methods
static [ProcessQueue] Get() {
return [ProcessQueue]::singleton
}
[Void] Add([Set]$newSet) {
$this.Queue.Add($newSet)
}
[Void] Initiate () {
foreach ($item in $this.Queue) {
$item.Initiate()
}
}
[Bool] Find ([String]$string, [String]$ignoreID) {
$found = $false
foreach ($item in $this.Queue) {
if ($item.Find($string, $ignoreID)) {
$found = $true
}
}
return $found
}
}
class Set {
# Properties
[String]$ID
hidden [System.Collections.Generic.List[object]]$Queue = [System.Collections.Generic.List[object]]::New()
# Constructor
Set ([String]$id) {
$this.ID = $id
}
# Methods
[Void] add([Package]$newPackage) {
$this.Queue.Add($newPackage)
}
[Void] Initiate () {
Write-Host "$($this.ID)"
foreach ($item in $this.Queue) {
$item.Initiate()
}
}
[Bool] Find ([String]$string, [String]$ignoreID) {
$found = $false
foreach ($item in $this.Queue) {
if ($item.Find($string, $ignoreID)) {
$found = $true
}
}
return $found
}
}
class Package {
# Properties
[String]$ID
hidden [System.Collections.Generic.List[object]]$Queue = [System.Collections.Generic.List[object]]::New()
# Constructor
Package ([String]$id) {
$this.ID = $id
}
# Methods
[Void] add([Task]$newPackage) {
$this.Queue.Add($newPackage)
}
[Void] Initiate () {
Write-Host " $($this.ID)"
foreach ($item in $this.Queue) {
$item.Initiate()
}
}
[Bool] Find ([String]$string, [String]$ignoreID) {
$found = $false
foreach ($item in $this.Queue) {
if ($item.Find($string, $ignoreID)) {
$found = $true
}
}
return $found
}
}
class Task {
# Properties
[String]$ID
[String]$DisplayName
hidden [Bool]$Completed
#hidden [System.Collections.Generic.List[object]]$Queue = [System.Collections.Generic.List[object]]::New()
# Constructor
Task ([String]$id) {
$this.ID = $id
}
# Methods
[Void] Initiate () {
if ($this.DisplayName -eq 'Find') {
if ([ProcessQueue]::Get().Find('Find', $this.ID)) {
Write-Host " $($this.ID) $($this.DisplayName) (Skipped)"
} else {
Write-Host " $($this.ID) $($this.DisplayName) (Last)"
}
} else {
Write-Host " $($this.ID) $($this.DisplayName)"
}
$this.Completed = $true
}
[Bool] Find ([String]$string, [String]$ignoreID) {
$found = $null
if (-not ($this.Completed -or ($ignoreID -eq $this.ID))) {
if ($this.DisplayName -eq $string) {
$found = $true
} else {
$found = $false
}
}
return $found
}
}
$set = [Set]::New('Set1')
foreach ($i in 65..90) {
$newPackage = [Package]::New([char]$i)
foreach ($j in 1..10) {
$newTask = [Task]::New("$([char]$i).$j")
if ((Get-Random -Minimum:0 -Maximum:100) -lt 3) {
$newTask.DisplayName = 'Find'
} else {
$newTask.DisplayName = 'Ignore'
}
$newPackage.Add($newTask)
}
$set.Add($newPackage)
}
[ProcessQueue]::Get().Add($set)
CLS
[ProcessQueue]::Get().Initiate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment