Created
July 27, 2019 09:11
-
-
Save joshooaj/bddbaf50bf47930289f447aaea376745 to your computer and use it in GitHub Desktop.
Snippet of MilestonePSTools Get-Snapshot command source code
This file contains 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
private void GetRecordedSnapshot() | |
{ | |
JPEGVideoSource src = null; | |
var cameraId = Camera == null ? CameraId : new Guid(Camera.Id); | |
try | |
{ | |
var item = Configuration.Instance.GetItem(Connection.CurrentSite.FQID.ServerId, cameraId, Kind.Camera); | |
if (item == null) | |
{ | |
WriteWarning($"Configuration not available for camera with ID {cameraId}. It might be disabled."); | |
return; | |
} | |
src = new JPEGVideoSource(item); | |
src.SetKeepAspectRatio(KeepAspectRatio, IncludeBlackBars); | |
src.Init(Width, Height); | |
src.Compression = Quality; | |
JPEGData snapshot = null; | |
switch (Behavior.ToLower()) | |
{ | |
case "getbegin": | |
{ | |
snapshot = src.GetBegin(); | |
break; | |
} | |
case "getend": | |
{ | |
snapshot = src.GetEnd(); | |
break; | |
} | |
case "getnearest": | |
{ | |
var timestamp = DateTime | |
.SpecifyKind(Timestamp, LocalTimestamp ? DateTimeKind.Local : DateTimeKind.Utc) | |
.ToUniversalTime(); | |
snapshot = src.GetNearest(timestamp) as JPEGData; | |
break; | |
} | |
} | |
if (Save) SaveSnapshot(snapshot, src.Item); | |
WriteObject(snapshot); | |
} | |
catch (CommunicationMIPException) | |
{ | |
WriteWarning($"Unable to connect to {src?.Item.Name} with ID {src?.Item.FQID.ObjectId}"); | |
} | |
catch (Exception ex) | |
{ | |
WriteError( | |
new ErrorRecord( | |
ex, | |
ex.Message, | |
ErrorCategory.ConnectionError, | |
src)); | |
} | |
finally | |
{ | |
src?.Close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment