Skip to content

Commit

Permalink
updates for #144
Browse files Browse the repository at this point in the history
  • Loading branch information
scrthq committed Jan 15, 2019
1 parent b94bd96 commit 943acf8
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 66 deletions.
2 changes: 1 addition & 1 deletion PSGSuite/PSGSuite.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSGSuite.psm1'

# Version number of this module.
ModuleVersion = '2.22.1'
ModuleVersion = '2.22.2'

# ID used to uniquely identify this module
GUID = '9d751152-e83e-40bb-a6db-4c329092aaec'
Expand Down
58 changes: 29 additions & 29 deletions PSGSuite/Public/Drive/Get-GSDriveFileUploadStatus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ function Get-GSDriveFileUploadStatus {
<#
.SYNOPSIS
Gets the current Drive file upload status
.DESCRIPTION
Gets the current Drive file upload status
.PARAMETER Id
The upload Id for the task you'd like to retrieve the status of
.PARAMETER InProgress
If passed, only returns upload statuses that are not 'Failed' or 'Completed'. If nothing is returned when passing this parameter, all tracked uploads have stopped
.EXAMPLE
Get-GSDriveFileUploadStatus -InProgress
Expand Down Expand Up @@ -51,19 +51,19 @@ function Get-GSDriveFileUploadStatus {
if ($Id) {
if ($Id -contains $task.Id) {
$obj = [PSCustomObject]@{
Id = $task.Id
Status = $progress.Status
Id = $task.Id
Status = $progress.Status
PercentComplete = $percentComplete
Remaining = $remaining
StartTime = $task.StartTime
Elapsed = $elapsed
File = $task.File.FullName
Length = $task.Length
Parents = $task.Parents
BytesSent = $bytesSent
FileLocked = $(Test-FileLock -Path $task.File)
User = $task.User
Exception = $progress.Exception
Remaining = $remaining
StartTime = $task.StartTime
Elapsed = $elapsed
File = $task.File.FullName
Length = $task.Length
Parents = $task.Parents
BytesSent = $bytesSent
FileLocked = $(Test-FileLock -Path $task.File)
User = $task.User
Exception = $progress.Exception
}
if (!$InProgress -or $obj.Status -notin @('Failed','Completed')) {
$obj
Expand All @@ -72,19 +72,19 @@ function Get-GSDriveFileUploadStatus {
}
else {
$obj = [PSCustomObject]@{
Id = $task.Id
Status = $progress.Status
Id = $task.Id
Status = $progress.Status
PercentComplete = $percentComplete
Remaining = $remaining
StartTime = $task.StartTime
Elapsed = $elapsed
File = $task.File.FullName
Length = $task.Length
Parents = $task.Parents
BytesSent = $bytesSent
FileLocked = $(Test-FileLock -Path $task.File)
User = $task.User
Exception = $progress.Exception
Remaining = $remaining
StartTime = $task.StartTime
Elapsed = $elapsed
File = $task.File.FullName
Length = $task.Length
Parents = $task.Parents
BytesSent = $bytesSent
FileLocked = $(Test-FileLock -Path $task.File)
User = $task.User
Exception = $progress.Exception
}
if (!$InProgress -or $obj.Status -notin @('Failed','Completed')) {
$obj
Expand All @@ -93,4 +93,4 @@ function Get-GSDriveFileUploadStatus {
}
}
}
}
}
50 changes: 28 additions & 22 deletions PSGSuite/Public/Drive/Start-GSDriveFileUpload.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,31 @@ function Start-GSDriveFileUpload {
if ($Description) {
$body.Description = $Description
}
$stream = New-Object 'System.IO.FileStream' $detPart.FullName,'Open','Read'
$stream = New-Object 'System.IO.FileStream' $detPart.FullName,([System.IO.FileMode]::Open),([System.IO.FileAccess]::Read),([System.IO.FileShare]::Delete + [System.IO.FileShare]::ReadWrite)
$request = $service.Files.Create($body,$stream,$contentType)
$request.QuotaUser = $User
$request.SupportsTeamDrives = $true
$request.ChunkSize = 512KB
$upload = $request.UploadAsync()
$task = $upload.ContinueWith([System.Action[System.Threading.Tasks.Task]] {$stream.Dispose()})
$task = $upload.ContinueWith([System.Action[System.Threading.Tasks.Task]] {if ($stream) {
$stream.Dispose()
}})
Write-Verbose "[$($detPart.Name)] Upload Id $($upload.Id) has started"
if (!$Script:DriveUploadTasks) {
$Script:DriveUploadTasks = [System.Collections.ArrayList]@()
}
$script:DriveUploadTasks += [PSCustomObject]@{
Id = $upload.Id
File = $detPart
Length = $detPart.Length
SizeInMB = [Math]::Round(($detPart.Length / 1MB),2,[MidPointRounding]::AwayFromZero)
StartTime = $(Get-Date)
Parents = $body.Parents
User = $User
Upload = $upload
Request = $request
Id = $upload.Id
File = $detPart
Length = $detPart.Length
SizeInMB = [Math]::Round(($detPart.Length / 1MB),2,[MidPointRounding]::AwayFromZero)
StartTime = $(Get-Date)
Parents = $body.Parents
User = $User
Upload = $upload
Request = $request
Stream = $stream
StreamDisposed = $false
}
$taskList += [PSCustomObject]@{
Id = $upload.Id
Expand Down Expand Up @@ -217,7 +221,7 @@ function Start-GSDriveFileUpload {
}
}
End {
if (!$Wait) {
if (-not $Wait) {
$fullTaskList
}
else {
Expand Down Expand Up @@ -250,7 +254,7 @@ function Start-GSDriveFileUpload {
if ($Description) {
$body.Description = $Description
}
$stream = New-Object 'System.IO.FileStream' $detPart.FullName,'Open','Read'
$stream = New-Object 'System.IO.FileStream' $detPart.FullName,([System.IO.FileMode]::Open),([System.IO.FileAccess]::Read),([System.IO.FileShare]::Delete + [System.IO.FileShare]::ReadWrite)
$request = $service.Files.Create($body,$stream,$contentType)
$request.QuotaUser = $User
$request.SupportsTeamDrives = $true
Expand All @@ -262,15 +266,17 @@ function Start-GSDriveFileUpload {
$Script:DriveUploadTasks = [System.Collections.ArrayList]@()
}
$script:DriveUploadTasks += [PSCustomObject]@{
Id = $upload.Id
File = $detPart
Length = $detPart.Length
SizeInMB = [Math]::Round(($detPart.Length / 1MB),2,[MidPointRounding]::AwayFromZero)
StartTime = $(Get-Date)
Parents = $body.Parents
User = $User
Upload = $upload
Request = $request
Id = $upload.Id
File = $detPart
Length = $detPart.Length
SizeInMB = [Math]::Round(($detPart.Length / 1MB),2,[MidPointRounding]::AwayFromZero)
StartTime = $(Get-Date)
Parents = $body.Parents
User = $User
Upload = $upload
Request = $request
Stream = $stream
StreamDisposed = $false
}
$taskList += [PSCustomObject]@{
Id = $upload.Id
Expand Down
26 changes: 13 additions & 13 deletions PSGSuite/Public/Drive/Watch-GSDriveUpload.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ function Watch-GSDriveUpload {
<#
.SYNOPSIS
Shows progress in the console of current Drive file uploads
.DESCRIPTION
Shows progress in the console of current Drive file uploads
.PARAMETER Id
The upload Id(s) that you would like to watch
.PARAMETER Action
Whether the action is uploading or retrying. This is mainly for use in Start-GSDriveFileUpload and defaults to 'Uploading'
.PARAMETER CountUploaded
Current file count being uploaded
.PARAMETER TotalUploading
Total file count being uploaded
.EXAMPLE
Watch-GSDriveUpload
Expand Down Expand Up @@ -47,10 +47,10 @@ function Watch-GSDriveUpload {
do {
$i = 1
if ($PSBoundParameters.Keys -contains 'Id') {
$statusList = Get-GSDriveFileUploadStatus -Verbose:$false
$statusList = Get-GSDriveFileUploadStatus -Id @($Id) -Verbose:$false
}
else {
$statusList = Get-GSDriveFileUploadStatus -Id @($Id) -Verbose:$false
$statusList = Get-GSDriveFileUploadStatus -Verbose:$false
}
if ($statusList) {
$totalPercent = 0
Expand All @@ -76,7 +76,7 @@ function Watch-GSDriveUpload {
$totalPercent = $totalPercent / $totalCount
$totalSecondsRemaining = $totalSecondsRemaining / $totalCount
$parentParams = @{
Activity = "[$([Math]::Round($totalPercent,4))%] $Action [$curCount / $totalCount] files to Google Drive"
Activity = "[$([Math]::Round($totalPercent,4))%] $Action [$curCount / $totalCount] files to Google Drive"
SecondsRemaining = $($statusList.Remaining.TotalSeconds | Sort-Object | Select-Object -Last 1)
}
if (!($statusList | Where-Object {$_.Status -ne "Completed"})) {
Expand All @@ -102,10 +102,10 @@ function Watch-GSDriveUpload {
$status.Status
}
$progParams = @{
Activity = "[$($status.PercentComplete)%] [ID: $($status.Id)] $($statusFmt) file '$($status.File)' to Google Drive$(if($status.Parents){" (Parents: '$($status.Parents -join "', '")')"})"
Activity = "[$($status.PercentComplete)%] [ID: $($status.Id)] $($statusFmt) file '$($status.File)' to Google Drive$(if($status.Parents){" (Parents: '$($status.Parents -join "', '")')"})"
SecondsRemaining = $status.Remaining.TotalSeconds
Id = $i
ParentId = 1
Id = $i
ParentId = 1
}
if ($_.Status -eq "Completed") {
$progParams['Completed'] = $true
Expand All @@ -121,4 +121,4 @@ function Watch-GSDriveUpload {
}
until (!$statusList -or !($statusList | Where-Object {$_.Status -notin @("Failed","Completed")}))
}
}
}
6 changes: 5 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ else {
" + NuGet API key is not null : $($null -ne $env:NugetApiKey)`n" +
" + Commit message matches '!deploy' : $($env:BUILD_SOURCEVERSIONMESSAGE -match '!deploy') [$env:BUILD_SOURCEVERSIONMESSAGE]"| Write-Host -ForegroundColor Green
}
'BuildHelpers','psake' | Resolve-Module @update -Verbose
Write-Verbose "Installing BuildHelpers v2.0.1" -Verbose
Install-Module 'BuildHelpers' -RequiredVersion 2.0.1 -Scope CurrentUser -Repository PSGallery -AllowClobber -SkipPublisherCheck -Force
Write-Verbose "Importing BuildHelpers v2.0.1" -Verbose
Import-Module 'BuildHelpers' -RequiredVersion 2.0.1
'psake' | Resolve-Module @update -Verbose
Set-BuildEnvironment -Force
Write-Host -ForegroundColor Green "Modules successfully resolved..."
Write-Host -ForegroundColor Green "Invoking psake with task list: [ $($Task -join ', ') ]`n"
Expand Down

0 comments on commit 943acf8

Please sign in to comment.