Created
October 17, 2021 21:01
-
-
Save joshooaj/e321f3129b5fb7f65720f5c1d8b920dc to your computer and use it in GitHub Desktop.
A potential replacement for Get-PlaybackInfo which in limited testing is 249% faster by using a SequenceDataSource instead of a RawDataSource.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-PlaybackInfo2 { | |
| [CmdletBinding()] | |
| param ( | |
| # Accepts a Milestone Configuration Item path string like Camera[A64740CF-5511-4957-9356-2922A25FF752] | |
| [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName, ParameterSetName = 'FromPath')] | |
| [ValidateScript( { | |
| if ($_ -notmatch '^(?<ItemType>\w+)\[(?<Id>[a-fA-F0-9\-]{36})\]$') { | |
| throw "$_ does not a valid Milestone Configuration API Item path" | |
| } | |
| if ($Matches.ItemType -notin @('Camera', 'Microphone', 'Speaker', 'Metadata')) { | |
| throw "$_ represents an item of type '$($Matches.ItemType)'. Only camera, microphone, speaker, or metadata item types are allowed." | |
| } | |
| return $true | |
| })] | |
| [string] | |
| $Path, | |
| # Accepts a Camera, Microphone, Speaker, or Metadata object | |
| [Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'FromDevice')] | |
| [VideoOS.Platform.ConfigurationItems.IConfigurationItem] | |
| $Device, | |
| [Parameter()] | |
| [string] | |
| $SequenceType = 'RecordingSequence' | |
| ) | |
| begin { | |
| $site = Get-Site -ErrorAction Stop | |
| $epoch = [datetime]::SpecifyKind([datetimeoffset]::FromUnixTimeSeconds(0).DateTime, [datetimekind]::utc) | |
| } | |
| process { | |
| if ($PSCmdlet.ParameterSetName -eq 'FromDevice') { | |
| $Path = $Device.Path | |
| } | |
| if ($Path -notmatch '^(?<ItemType>\w+)\[(?<Id>[a-fA-F0-9\-]{36})\]$') { | |
| Write-Error "Path '$Path' is not a valid Milestone Configuration API item path." | |
| return | |
| } | |
| try { | |
| $item = [videoos.platform.Configuration]::Instance.GetItem($site.FQID.ServerId, $Matches.Id, [VideoOS.Platform.Kind]::($Matches.ItemType)) | |
| $sds = [VideoOS.Platform.Data.SequenceDataSource]::new($item) | |
| $sequenceTypeGuid = [VideoOS.Platform.Data.DataType+SequenceTypeGuids]::$SequenceType | |
| $first = $sds.GetData($epoch, [timespan]::zero, 0, ([datetime]::utcnow - $epoch), 1, $sequenceTypeGuid) | Select-Object -First 1 | |
| $last = $sds.GetData([datetime]::utcnow, ([datetime]::utcnow - $epoch), 1, [timespan]::zero, 0, $sequenceTypeGuid) | Select-Object -First 1 | |
| if ($first.EventSequence -and $last.EventSequence) { | |
| [PSCustomObject]@{ | |
| Begin = $first.EventSequence.StartDateTime | |
| End = $last.EventSequence.EndDateTime | |
| } | |
| } | |
| else { | |
| Write-Warning "No $SequenceType sequences found for $($item.Name) ($($item.FQID.ObjectId))" | |
| } | |
| } finally { | |
| if ($sds) { | |
| $sds.Close() | |
| } | |
| } | |
| } | |
| } | |
| Register-ArgumentCompleter -CommandName Get-PlaybackInfo2 -ParameterName SequenceType -ScriptBlock { | |
| param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) | |
| [VideoOS.Platform.Data.DataType+SequenceTypeGuids] | Get-Member -Static -MemberType Property | Select-Object -ExpandProperty Name | Where-Object { | |
| $_ -like "$wordToComplete*" | |
| } | ForEach-Object { | |
| "'$_'" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment