Skip to content

Commit

Permalink
#193 Add-IShBackgroundTask had rewrite from DocumentObj25.RaiseEventB…
Browse files Browse the repository at this point in the history
…yIshLngRefs to generic BackgroundTask25.CreateBackgroundTaskWithStartAfter so removing that platform check; using $ishEventTypeToPurge instead of hardcoded TESTBACKGROUNDTASK; -ne $null tests should test logicalids [PublishToPSGalleryAsPreview]
  • Loading branch information
ddemeyer committed Jul 3, 2024
1 parent 0822e9c commit f9378cd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,23 @@ Describe "Add-IshBackgroundTask" -Tags "Create" {
BeforeAll {
$requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name INPUTDATAID
}
It "Pipeline IshObject with LogicalId IshObjectsWithLngRef" {
It "Pipeline IshObject with InputDataTemplate IshObjectsWithLngRef" {
if(([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) {
# Get-IshBackgroundTask is called to get the system field 'INPUTDATAID'
$backgroundTask = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType "TESTBACKGROUNDTASK" -InputDataTemplate IshObjectsWithLngRef |
$backgroundTask = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge -InputDataTemplate IshObjectsWithLngRef |
Get-IshBackgroundTask -IshSession $ishSession -RequestedMetadata $requestedMetadata
$backgroundTask.INPUTDATAID -ge 0 | Should -Be $true

$inputData = $ishSession.BackgroundTask25.RetrieveDataObjectByIshDataRefs($backgroundTask.INPUTDATAID)
# inputData looks like <ishobjects><ishobject ishtype='ISHMasterDoc' ishref='GUID-X' ishlngref='45679'>...
$inputData = $ishSession.BackgroundTask25.RetrieveDataObjectByIshDataRefs($backgroundTask.INPUTDATAID)
$xml = [xml]$inputData
$cdataNode = $xml.ishbackgroundtaskdataobjects.ishbackgroundtaskdataobject.'#cdata-section'
$rawCdataContent = $cdataNode
$decodedContent = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($rawCdataContent))
$ishObjectsFromInputData = [xml]$decodedContent

$ishObjectsFromInputData.ishObjects -ne $null | Should -Be $true
$ishObjectsFromInputData.ishobjects.ChildNodes.Count | Should -Be $ishObjects.LngRef.Count # all language cards are passed
$ishObjectsFromInputData.ishObjects.ishObject.Count -ge 0 | Should -Be $true
$ishObjectsFromInputData.ishObjects.ishObject[0].ishtype -ne $null | Should -Be $true
$ishObjectsFromInputData.ishObjects.ishObject[0].ishref -ne $null | Should -Be $true
Expand All @@ -134,43 +137,47 @@ Describe "Add-IshBackgroundTask" -Tags "Create" {
$ishObjectsFromInputData.ishObjects.ishObject[0].ishlngref -ne $null | Should -Be $true
}
}

It "Pipeline IshObject with LogicalId IshObjectWithLngRef" {
It "Pipeline IshObject with InputDataTemplate IshObjectWithLngRef" {
if(([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) {
# Get-IshBackgroundTask is called to get the system field 'INPUTDATAID'
$backgroundTask = Add-IshBackgroundTask -IshSession $ishSession -EventType "TESTBACKGROUNDTASK" -InputDataTemplate IshObjectWithLngRef -IshObject $ishObjectTopic1_1 |
$backgroundTask = Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge -InputDataTemplate IshObjectWithLngRef -IshObject $ishObjectTopic1_1 |
Get-IshBackgroundTask -IshSession $ishSession -RequestedMetadata $requestedMetadata
$backgroundTask.INPUTDATAID -ge 0 | Should -Be $true

$inputData = $ishSession.BackgroundTask25.RetrieveDataObjectByIshDataRefs($backgroundTask.INPUTDATAID)
# inputData looks like <ishobject ishtype='ISHMasterDoc' ishref='GUID-X' ishlogicalref='45677' ishversionref='45678' ishlngref='45679'> or <ishobject ishtype='ISHBaseline' ishref='GUID-X' ishbaselineref='45798'>
$inputData = $ishSession.BackgroundTask25.RetrieveDataObjectByIshDataRefs($backgroundTask.INPUTDATAID)
$xml = [xml]$inputData
$cdataNode = $xml.ishbackgroundtaskdataobjects.ishbackgroundtaskdataobject.'#cdata-section'
$rawCdataContent = $cdataNode
$decodedContent = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($rawCdataContent))
$ishObjectFromInputData = [xml]$decodedContent

$ishObjectFromInputData.ishObject -ne $null | Should -Be $true
$ishObjectFromInputData.ishObject.ishtype -ne $null | Should -Be $true
$ishObjectFromInputData.ishObject.ishref -ne $null | Should -Be $true
$ishObjectsFromInputData.ChildNodes.Count | Should -Be 1 # first-and-only IshObject will be passed
$ishObjectFromInputData.ishObject -ne $null | Should -Be $true
$ishObjectFromInputData.ishObject.ishtype | Should -Be "ISHModule"
$ishObjectFromInputData.ishObject.ishref | Should -Be "ISHREMOTE-LOGICALID-TOPIC-FORADDBT1"
$ishObjectFromInputData.ishObject.ishlogicalref -ne $null | Should -Be $true
$ishObjectFromInputData.ishObject.ishversionref -ne $null | Should -Be $true
$ishObjectFromInputData.ishObject.ishlngref -ne $null | Should -Be $true
}
}

It "Pipeline IshObject with LogicalId IshObjectsWithIshRef" {
It "Pipeline IshObject with InputDataTemplate IshObjectsWithIshRef" {
if(([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) {
# Get-IshBackgroundTask is called to get the system field 'INPUTDATAID'
$backgroundTask = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType "TESTBACKGROUNDTASK" -InputDataTemplate IshObjectsWithIshRef |
$backgroundTask = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge -InputDataTemplate IshObjectsWithIshRef |
Get-IshBackgroundTask -IshSession $ishSession -RequestedMetadata $requestedMetadata
$backgroundTask.INPUTDATAID -ge 0 | Should -Be $true

$inputData = $ishSession.BackgroundTask25.RetrieveDataObjectByIshDataRefs($backgroundTask.INPUTDATAID)
# inputData looks like <ishobjects><ishobject ishtype='ISHMasterDoc' ishref='GUID-X'>...
$inputData = $ishSession.BackgroundTask25.RetrieveDataObjectByIshDataRefs($backgroundTask.INPUTDATAID)
$xml = [xml]$inputData
$cdataNode = $xml.ishbackgroundtaskdataobjects.ishbackgroundtaskdataobject.'#cdata-section'
$rawCdataContent = $cdataNode
$decodedContent = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($rawCdataContent))
$ishObjectsFromInputData = [xml]$decodedContent

$ishObjectsFromInputData.ishObjects -ne $null | Should -Be $true
$ishObjectsFromInputData.ishobjects.ChildNodes.Count | Should -Be ($ishObjects.IshRef | Select-Object -Unique).Count # all unique LogicalIds are passed
$ishObjectsFromInputData.ishObjects.ishObject.Count -ge 0 | Should -Be $true
$ishObjectsFromInputData.ishObjects.ishObject[0].ishtype -ne $null | Should -Be $true
$ishObjectsFromInputData.ishObjects.ishObject[0].ishref -ne $null | Should -Be $true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,9 @@ protected override void BeginProcessing()
if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); }
WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");

switch (ParameterSetName)
if ((IshSession.ServerIshVersion.MajorVersion < 13) || ((IshSession.ServerIshVersion.MajorVersion == 13) && (IshSession.ServerIshVersion.RevisionVersion < 2)))
{
case "ParameterGroup":
if ((IshSession.ServerIshVersion.MajorVersion < 13) || ((IshSession.ServerIshVersion.MajorVersion == 13) && (IshSession.ServerIshVersion.RevisionVersion < 2)))
{
throw new PlatformNotSupportedException($"Add-IshBackgroundTask with the current parameter set requires server-side BackgroundTask API which is only available starting from 13SP2/13.0.2 and up. ServerIshVersion[{IshSession.ServerVersion}]");
}
break;
case "IshObjectsGroup":
if ((IshSession.ServerIshVersion.MajorVersion < 14) || ((IshSession.ServerIshVersion.MajorVersion == 14) && (IshSession.ServerIshVersion.RevisionVersion < 4)))
{
throw new PlatformNotSupportedException($"Add-IshBackgroundTask with the current parameter set requires server-side DocumentObj API which is only available starting from 14SP4/14.0.4 and up. ServerIshVersion[{IshSession.ServerVersion}]");
}
break;
throw new PlatformNotSupportedException($"Add-IshBackgroundTask with the current parameter set requires server-side BackgroundTask API which is only available starting from 13SP2/13.0.2 and up. ServerIshVersion[{IshSession.ServerVersion}]");
}
base.BeginProcessing();
}
Expand Down Expand Up @@ -290,7 +279,7 @@ protected override void EndProcessing()

if (EventDescription.IsNullOrEmpty())
{
EventDescription = $"Executing {EventType} for {ishObjectsCount} ishObjects";
EventDescription = $"Executing {EventType} for {ishObjectsCount} IShObjects";
}

// Start event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public string TaskRef
/// </summary>
public string HistoryRef
{
get { return _backgroundTaskRef[Enumerations.ReferenceType.BackgroundTaskHistory]; }
get { return (_backgroundTaskRef.ContainsKey(Enumerations.ReferenceType.BackgroundTaskHistory)) ? _backgroundTaskRef[Enumerations.ReferenceType.BackgroundTaskHistory] : string.Empty; }
}
}
}

0 comments on commit f9378cd

Please sign in to comment.