-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask14.psm1
More file actions
50 lines (46 loc) · 1.66 KB
/
task14.psm1
File metadata and controls
50 lines (46 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<#
Функция скачки для N объектов (задается как параметр).
Дополнительно в режиме диалога задаются символы визуализации.
#>
$JobFunctions = {
function StartRiding {
$RidingFinishNumber = 1000
for ($CurrentNumber = 0; $CurrentNumber -le $RidingFinishNumber; $CurrentNumber++) {
Write-Output $($CurrentNumber / $RidingFinishNumber * 100)
$MillisecondsTimeout = Get-Random -Minimum 10 -Maximum 100
Start-Sleep -Milliseconds $MillisecondsTimeout
}
}
}
function Start-Riding([array] $RiderNames) {
$RiderIndex = 1
$Riders = @()
foreach ($RiderName in $RiderNames) {
$Riders += @{
Index = $RiderIndex++;
Name = $RiderName;
Job = $(Start-Job -InitializationScript $JobFunctions -ScriptBlock { StartRiding });
Progress = 0;
}
}
while (Get-Job -State "Running") {
Start-Sleep -Milliseconds 10
foreach ($Rider in $Riders) {
$JobOutput = $Rider.Job | Receive-Job
if ($JobOutput) {
$Rider.Progress = $JobOutput | Select-Object -Last 1
}
Write-Progress -Id $Rider.Index -Activity $Rider.Name -PercentComplete $Rider.Progress
}
}
Remove-Job *
}
function Start-RidingDialog([int] $RidersNumber = 2) {
$RiderNames = @()
for ($RiderIndex = 1; $RiderIndex -le $RidersNumber; $RiderIndex++) {
$RiderNames += $(Read-Host "Rider #$RiderIndex name")
}
Start-Riding $RiderNames
}
Export-ModuleMember Start-RidingDialog
Export-ModuleMember Start-Riding