diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Annotation/GetIshAnnotation.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Annotation/GetIshAnnotation.cs index 18ff0298..c943c3bd 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Annotation/GetIshAnnotation.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Annotation/GetIshAnnotation.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2014 All Rights Reserved by the SDL Group. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -239,10 +239,10 @@ protected override void EndProcessing() // remove duplicates from annotationIds list annotationIds = annotationIds.Distinct().ToList(); WriteDebug($"Retrieving AnnotationId.length[{annotationIds.Count}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}]"); - // Devides the list of Annotation Ids in different lists that all have maximally MetadataBatchSize elements - List> devidedAnnotationIdsList = DevideListInBatches(annotationIds, IshSession.MetadataBatchSize); + // Divides the list of Annotation Ids in different lists that all have maximally MetadataBatchSize elements + List> dividedAnnotationIdsList = DivideListInBatches(annotationIds, IshSession.MetadataBatchSize); int currentAnnotationIdCount = 0; - foreach (List annotationIdBatch in devidedAnnotationIdsList) + foreach (List annotationIdBatch in dividedAnnotationIdsList) { string xmlIshObjectsRetrieved = IshSession.Annotation25.RetrieveMetadata(annotationIdBatch.ToArray(), metadataFilter.ToXml(), requestedMetadata.ToXml()); IshObjects ishObjectsRetrieved = new IshObjects(ISHType, xmlIshObjectsRetrieved); diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Annotation/SetIshAnnotation.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Annotation/SetIshAnnotation.cs index 3a9edd91..8b1ad9fa 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Annotation/SetIshAnnotation.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Annotation/SetIshAnnotation.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2014 All Rights Reserved by the SDL Group. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -189,11 +189,11 @@ protected override void EndProcessing() //2. Retrieve set annotations WriteDebug($"Retrieving AnnotationId.length[{annotationIdsToRetrieve.Count}]"); - // Devides the list of Annotation Ids in different lists that all have maximally MetadataBatchSize elements - List> devidedAnnotationIdsList = DevideListInBatches(annotationIdsToRetrieve, IshSession.MetadataBatchSize); + // Divides the list of Annotation Ids in different lists that all have maximally MetadataBatchSize elements + List> dividedAnnotationIdsList = DivideListInBatches(annotationIdsToRetrieve, IshSession.MetadataBatchSize); IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, returnFields, Enumerations.ActionMode.Read); int currentAnnotationIdCount = 0; - foreach (List annotationIdBatch in devidedAnnotationIdsList) + foreach (List annotationIdBatch in dividedAnnotationIdsList) { string xmlIshObjectsRetrieved = IshSession.Annotation25.RetrieveMetadata(annotationIdBatch.ToArray(), "", requestedMetadata.ToXml()); IshObjects ishObjectsRetrieved = new IshObjects(ISHType, xmlIshObjectsRetrieved); diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.Tests.ps1 index 9d9dd31f..1817345f 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.Tests.ps1 +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.Tests.ps1 @@ -96,27 +96,6 @@ Describe "Add-IshBackgroundTask" -Tags "Create" { $ishBackgroundTaskIshObjectsPipeline.userid | Should -BeExactly $ishSession.UserName } } - It "Pipeline IshObject MetadataBatchSize[2] with LogicalId grouping" { - if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) { - $ishSession.MetadataBatchSize = 2 - $ishBackgroundTasks = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge - $ishBackgroundTasks.Count | Should -BeExactly 3 - } - } - It "Pipeline IshObject MetadataBatchSize[4] with LogicalId grouping" { - if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) { - $ishSession.MetadataBatchSize = 4 - $ishBackgroundTasks = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge - $ishBackgroundTasks.Count | Should -BeExactly 3 - } - } - It "Pipeline IshObject MetadataBatchSize[6] with LogicalId grouping" { - if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) { - $ishSession.MetadataBatchSize = 6 - $ishBackgroundTasks = $ishObjects | Add-IshBackgroundTask -IshSession $ishSession -EventType $ishEventTypeToPurge - $ishBackgroundTasks.Count | Should -BeExactly 2 - } - } It "Pipeline IshObject MetadataBatchSize[10] with LogicalId grouping" { if (([Version]$ishSession.ServerVersion).Major -ge 15 -or (([Version]$ishSession.ServerVersion).Major -ge 14 -and ([Version]$ishSession.ServerVersion).Revision -ge 4)) { $ishSession.MetadataBatchSize = 10 @@ -128,7 +107,79 @@ Describe "Add-IshBackgroundTask" -Tags "Create" { $ishSession.MetadataBatchSize = $savedMetadataBatchSize } } - + + Context "Add-IshBackgroundTask IshObjectsGroup Pipeline IshObject with InputDataTemplate" { + BeforeAll { + $requestedMetadata = Set-IshRequestedMetadataField -IshSession $ishSession -Level Task -Name INPUTDATAID + } + It "Pipeline IshObject with LogicalId 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 | + Get-IshBackgroundTask -IshSession $ishSession -RequestedMetadata $requestedMetadata + + $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.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 + $ishObjectsFromInputData.ishObjects.ishObject[0].ishlogicalref -ne $null | Should -Be $true + $ishObjectsFromInputData.ishObjects.ishObject[0].ishversionref -ne $null | Should -Be $true + $ishObjectsFromInputData.ishObjects.ishObject[0].ishlngref -ne $null | Should -Be $true + } + } + + It "Pipeline IshObject with LogicalId 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 | + Get-IshBackgroundTask -IshSession $ishSession -RequestedMetadata $requestedMetadata + + $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 + $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" { + 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 | + Get-IshBackgroundTask -IshSession $ishSession -RequestedMetadata $requestedMetadata + + $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.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 + $ishObjectsFromInputData.ishObjects.ishObject[0].ishlogicalref -eq $null | Should -Be $true + $ishObjectsFromInputData.ishObjects.ishObject[0].ishversionref -eq $null | Should -Be $true + $ishObjectsFromInputData.ishObjects.ishObject[0].ishlngref -eq $null | Should -Be $true + } + } + } Context "Add-IshBackgroundTask ParameterGroup" { BeforeAll { # If you get the below error, it means you configured default purge operation $ishEventTypetoPurge (defaults to PUSHTRANSLATIONS in ISHRemote.PesterSetup.ps1) away diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.cs index 54b5bb82..7da1dc5b 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/BackgroundTask/AddIshBackgroundTask.cs @@ -22,37 +22,58 @@ using Trisoft.ISHRemote.Exceptions; using Trisoft.ISHRemote.HelperClasses; using System.Linq; +using System.Security.Cryptography; using Trisoft.ISHRemote.BackgroundTask25ServiceReference; using Trisoft.ISHRemote.EventMonitor25ServiceReference; using System.Text; +using System.Xml.Linq; +using Microsoft.IdentityModel.Tokens; +using static Trisoft.ISHRemote.Objects.Enumerations; namespace Trisoft.ISHRemote.Cmdlets.BackgroundTask { /// /// The Add-IshBackgroundTask cmdlet add fire-and-forget asynchronous processing events to the CMS generic queuing system. /// Add-IshBackgroundTask ParameterGroup variation uses BackgroundTask25.CreateBackgroundTask(WithStartAfter) that allows you to submit generic messages. Note that this requires a generic BackgroundTask service message handler. - /// Add-IshBackgroundTask IshObjectsGroup requires content object(s) which are transformed as message inputdata and passed to DocumentObj25.RaiseEventByIshLngRefs. This function will server-side validate the incoming objects and trigger an internal BackgroundTask25.CreateBackgroundTask. + /// Add-IshBackgroundTask IshObjectsGroup requires content object(s) which are transformed as message inputdata and passed to the Background Task. /// /// /// - /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin" + /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" /// $ishBackgroundTask = Get-IshFolderContent -FolderPath "General\MyFolder\Topics" -VersionFilter Latest -LanguagesFilter en | /// Add-IshBackgroundTask -EventType "SMARTTAG" /// - /// Add BackgroundTask with event type "SMARTTAG" for the objects located under the "General\MyFolder\Topics" path + /// Add BackgroundTask with event type "SMARTTAG" for the objects located under the "General\MyFolder\Topics" path. Trigger a legacy correction event of SMARTTAG across many folders. Note that the default value for the -InputDataTemplate is IshObjectsWithLngRef. /// /// /// - /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin" + /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" /// $ishBackgroundTask = Get-IshFolder -FolderPath "General\Myfolder" -FolderTypeFilter @("ISHModule", "ISHMasterDoc", "ISHLibrary") -Recurse | /// Get-IshFolderContent -VersionFilter Latest -LanguagesFilter en | /// Add-IshBackgroundTask -EventType "SMARTTAG" /// - /// Add BackgroundTask with event type "SMARTTAG" for the latest-version en(glish) content objects of type topic, map and topic library; located under the "General\MyFolder" path. Trigger a legacy correction event of SMARTTAG across many folders. Note that Get-IshFolder gives you a progress bar for follow-up. Note that it is possible to configure the BackgroundTask-handler with a variation of the SMARTTAG event to do more-or-less fields for automatic concept suggestions. + /// Add BackgroundTask with event type "SMARTTAG" for the latest-version en(glish) content objects of type topic, map and topic library; located under the "General\MyFolder" path. Trigger a legacy correction event of SMARTTAG across many folders.Note that the default value for the -InputDataTemplate is IshObjectsWithLngRef. Note that Get-IshFolder gives you a progress bar for follow-up. Note that it is possible to configure the BackgroundTask-handler with a variation of the SMARTTAG event to do more-or-less fields for automatic concept suggestions. /// /// /// - /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin" + /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" + /// $ishBackgroundTask = Get-IshFolder -BaseFolder Data -FolderTypeFilter @("ISHIllustration") -Recurse | + /// Get-IshFolderContent -VersionFilter Latest | + /// Add-IshBackgroundTask -EventType "SYNCHRONIZEMETRICS" -InputDataTemplate IshObjectsWithIshRef + /// + /// Add BackgroundTask with event type "SYNCHRONIZEMETRICS" for the latest-version content objects of type image; located under the "General" path. Trigger an event of synchronizing all images from CM to the metrics. Note that Get-IshFolder gives you a progress bar for follow-up. + /// + /// + /// + /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" + /// $ishBackgroundTask = Get-IshDocumentObj -LogicalId "GUID-ABCD-1234" | + /// Add-IshBackgroundTask -EventType "SYNCHRONIZEMETRICS" -InputDataTemplate IshObjectWithIshRef + /// + /// Add BackgroundTask with event type "SYNCHRONIZEMETRICS" for the latest-version of a single content object of type topic; Trigger an event of synchronizing a topic from CM to the metrics. + /// + /// + /// + /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" /// $rawData = "<data><export-document-type>ISHPublication</export-document-type><export-document-level>lng</export-document-level><export-ishlngref>549482</export-ishlngref><creationdate>20210303070257182</creationdate></data>" /// $ishBackgroundTask = Add-IshBackgroundTask -EventType "PUBLISH" -EventDescription "Custom publish event description" -RawInputData $rawData /// @@ -60,7 +81,7 @@ namespace Trisoft.ISHRemote.Cmdlets.BackgroundTask /// /// /// - /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" -PSCredential "Admin" + /// New-IshSession -WsBaseUrl "https://example.com/ISHWS/" /// $rawData = "<data><export-document-type>ISHPublication</export-document-type><export-document-level>lng</export-document-level><export-ishlngref>549482</export-ishlngref><creationdate>20210303070257182</creationdate></data>" /// $date = (Get-Date).AddDays(1) /// $ishBackgroundTask = Add-IshBackgroundTask -EventType "PUBLISH" -EventDescription "Custom publish event description" -RawInputData $rawData -StartAfter $date @@ -99,6 +120,7 @@ public sealed class AddIshBackgroundTask : BackgroundTaskCmdlet /// Description of the event /// [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")] + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")] [ValidateNotNullOrEmpty] public string EventDescription { get; set; } @@ -106,6 +128,7 @@ public sealed class AddIshBackgroundTask : BackgroundTaskCmdlet /// Date time indicating that the background task should not be picked up and executed before it. /// [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")] + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")] public DateTime? StartAfter { get; set; } /// @@ -115,10 +138,24 @@ public sealed class AddIshBackgroundTask : BackgroundTaskCmdlet [AllowEmptyCollection] public IshObject[] IshObject { get; set; } + /// + /// The InputDataTemplate (e.g. IshObjectWithLngRef) indicates whether a list of ishObjects or one ishObject is submitted as input data to the background task. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")] + public InputDataTemplate InputDataTemplate { get; set; } = InputDataTemplate.IshObjectsWithLngRef; + + /// + /// The hash id of the background task. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "ParameterGroup")] + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, ParameterSetName = "IshObjectsGroup")] + [ValidateLength(0, 80)] + public string HashId { get; set; } + #region Private fields private readonly List _retrievedIshObjects = new List(); private readonly DateTime _modifiedSince = DateTime.Today.AddDays(-1); - private readonly BackgroundTask25ServiceReference.eUserFilter _userFilter = EnumConverter.ToUserFilter(Enumerations.UserFilter.Current); + private readonly eUserFilter _userFilter = EnumConverter.ToUserFilter(Enumerations.UserFilter.Current); private readonly int _startEventMaxProgress = 100; #endregion @@ -127,7 +164,7 @@ protected override void BeginProcessing() if (IshSession == null) { IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession); } if (IshSession == null) { throw new ArgumentException(ISHRemoteSessionStateIshSessionException); } WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}"); - + switch (ParameterSetName) { case "ParameterGroup": @@ -181,86 +218,146 @@ protected override void EndProcessing() { try { - IshFields metadataFilter = new IshFields(); - IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, new IshFields(), Enumerations.ActionMode.Find); - var startEventResponse = new StartEventResponse(); - var progressIds = new List(); - if (ParameterSetName == "IshObjectsGroup") + var metadataFilter = new IshFields(); + var requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, new IshFields(), ActionMode.Find); + long progressId = 0; + var ishObjectsCount = 0; + var inputData = ""; + + switch (InputDataTemplate) { - var ishObjectsDividedInBatches = DevideListInBatchesByLogicalId(_retrievedIshObjects, IshSession.MetadataBatchSize); + case InputDataTemplate.IshObjectWithLngRef: + { + if (_retrievedIshObjects.Count > 1) + { + WriteWarning("More than one IshObject was provided. Only the first will be passed, the others will be ignored."); + } + var ishObject = _retrievedIshObjects.First(); + if (ishObject.IshType == Enumerations.ISHType.ISHBaseline) + { + var ishObjectElement = new XElement("ishobject", + new XAttribute("ishtype", ishObject.IshType), + new XAttribute("ishref", ishObject.IshRef), + new XAttribute("ishbaselineref", ishObject.ObjectRef[ReferenceType.Baseline]) + ); + inputData = ishObjectElement.ToString(); + } + else + { + var ishObjectElement = new XElement("ishobject", + new XAttribute("ishtype", ishObject.IshType), + new XAttribute("ishref", ishObject.IshRef), + new XAttribute("ishlogicalref", ishObject.ObjectRef[ReferenceType.Logical]), + new XAttribute("ishversionref", ishObject.ObjectRef[ReferenceType.Version]), + new XAttribute("ishlngref", ishObject.ObjectRef[ReferenceType.Lng]) + ); + inputData = ishObjectElement.ToString(); + } - int currentIshObjectsCount = 0; - foreach (var ishObjectsGroup in ishObjectsDividedInBatches) - { - // Create BackgroundTask - var lngCardIds = ishObjectsGroup.Select(ishObject => Convert.ToInt64(ishObject.ObjectRef[Enumerations.ReferenceType.Lng])).ToList(); - var progressId = IshSession.DocumentObj25.RaiseEventByIshLngRefs(lngCardIds.ToArray(), EventType); - progressIds.Add(progressId); - currentIshObjectsCount += ishObjectsGroup.Count; - WriteDebug($"RaiseEventByIshLngRefs.length[{lngCardIds.Count}] {currentIshObjectsCount}/{_retrievedIshObjects.Count}"); - } + ishObjectsCount = 1; + break; + } + case InputDataTemplate.IshObjectsWithLngRef: + { + var ishObjects = new XElement("ishobjects"); + foreach (var ishObjectElement in _retrievedIshObjects.Select(retrievedIshObject => new XElement("ishobject", + new XAttribute("ishtype", retrievedIshObject.IshType), + new XAttribute("ishref", retrievedIshObject.IshRef), + new XAttribute("ishlogicalref", retrievedIshObject.ObjectRef[ReferenceType.Logical]), + new XAttribute("ishversionref", retrievedIshObject.ObjectRef[ReferenceType.Version]), + new XAttribute("ishlngref", retrievedIshObject.ObjectRef[ReferenceType.Lng])))) + { + ishObjects.Add(ishObjectElement); + + ishObjectsCount++; + } + + inputData = ishObjects.ToString(); + + break; + } + case InputDataTemplate.IshObjectsWithIshRef: + { + var ishObjectsGroupedByIshRef = _retrievedIshObjects.GroupBy(ishObject => ishObject.IshRef); + var ishObjects = new XElement("ishobjects"); + foreach (var ishObjectsIshRefGroup in ishObjectsGroupedByIshRef) + { + var ishObjectElement = new XElement("ishobject", + new XAttribute("ishtype", ishObjectsIshRefGroup.First().IshType), + new XAttribute("ishref", ishObjectsIshRefGroup.First().IshRef)); + ishObjects.Add(ishObjectElement); + + ishObjectsCount++; + } + + inputData = ishObjects.ToString(); + + break; + } } - - if (ParameterSetName == "ParameterGroup") + + if (EventDescription.IsNullOrEmpty()) { - // Start event - WriteDebug($"Create StartEvent EventType[{EventType}] EventDescription[{EventDescription}]"); - var startEventRequest = new StartEventRequest - { - description = EventDescription, - eventType = EventType, - maximumProgress = _startEventMaxProgress - }; - startEventResponse = IshSession.EventMonitor25.StartEvent(startEventRequest); + EventDescription = $"Executing {EventType} for {ishObjectsCount} ishObjects"; + } + + // Start event + WriteDebug($"Create StartEvent EventType[{EventType}] EventDescription[{EventDescription}]"); + var startEventRequest = new StartEventRequest + { + description = EventDescription, + eventType = EventType, + maximumProgress = _startEventMaxProgress + }; + + var startEventResponse = IshSession.EventMonitor25.StartEvent(startEventRequest); + var backgroundTaskInputData = Encoding.Unicode.GetBytes(ParameterSetName == "IshObjectsGroup" ? inputData : RawInputData); + + if (HashId == null) + { + HashId = CalculateHashId(backgroundTaskInputData); } - if (ParameterSetName == "ParameterGroup" && StartAfter.HasValue) - { + if (StartAfter.HasValue) + { // Create BackgroundTask - WriteDebug($"Create BackgroundTask EventType[{EventType}] RawInputData.length[{RawInputData.Length}] StartAfter[{StartAfter}]"); + WriteDebug(ParameterSetName == "IshObjectsGroup" ? + $"Create BackgroundTask EventType[{EventType}] InputData.length[{inputData.Length}] StartAfter[{StartAfter}]" : + $"Create BackgroundTask EventType[{EventType}] RawInputData.length[{RawInputData.Length}] StartAfter[{StartAfter}]"); + var newBackgroundTaskWithStartAfterRequest = new CreateBackgroundTaskWithStartAfterRequest { eventType = EventType, - hashId = "", - inputData = Encoding.Unicode.GetBytes(RawInputData), + hashId = HashId, + inputData = backgroundTaskInputData, startAfter = StartAfter.Value, progressId = startEventResponse.progressId }; var createBackgroundTaskStartAfterResponse = IshSession.BackgroundTask25.CreateBackgroundTaskWithStartAfter(newBackgroundTaskWithStartAfterRequest); - var progressId = createBackgroundTaskStartAfterResponse.progressId; - progressIds.Add(progressId); + progressId = createBackgroundTaskStartAfterResponse.progressId; } - if (ParameterSetName == "ParameterGroup" && !StartAfter.HasValue) + if (!StartAfter.HasValue) { - // Create BackgroundTask - WriteDebug($"Create BackgroundTask EventType[{EventType}] RawInputData.length[{RawInputData.Length}]"); + // Create BackgroundTask + WriteDebug(ParameterSetName == "IshObjectsGroup" ? + $"Create BackgroundTask EventType[{EventType}] InputData.length[{inputData.Length}]" : + $"Create BackgroundTask EventType[{EventType}] RawInputData.length[{RawInputData.Length}]"); var newBackgroundTaskRequest = new CreateBackgroundTaskRequest { eventType = EventType, - hashId = "", - inputData = Encoding.Unicode.GetBytes(RawInputData), + hashId = HashId, + inputData = backgroundTaskInputData, progressId = startEventResponse.progressId }; - var createBackgroundTaskResponse = IshSession.BackgroundTask25.CreateBackgroundTask(newBackgroundTaskRequest); - var progressId = createBackgroundTaskResponse.progressId; - progressIds.Add(progressId); + var createBackgroundTaskStartAfterResponse = IshSession.BackgroundTask25.CreateBackgroundTask(newBackgroundTaskRequest); + progressId = createBackgroundTaskStartAfterResponse.progressId; } // Find and return IshBackgroundTask object - if (progressIds.Count > 1) - { - var progressIdsAsString = string.Join(IshSession.Separator, progressIds.ToArray()); - metadataFilter.AddField(new IshMetadataFilterField(FieldElements.BackgroundTaskProgressId, - Enumerations.Level.Task, Enumerations.FilterOperator.In, progressIdsAsString, - Enumerations.ValueType.Element)); - } - else - { - metadataFilter.AddField(new IshMetadataFilterField(FieldElements.BackgroundTaskProgressId, - Enumerations.Level.Task, Enumerations.FilterOperator.In, progressIds.First().ToString(), - Enumerations.ValueType.Element)); - } + metadataFilter.AddField(new IshMetadataFilterField(FieldElements.BackgroundTaskProgressId, + Level.Task, FilterOperator.In, progressId.ToString(), + Enumerations.ValueType.Value)); WriteDebug($"Finding BackgroundTask UserFilter[{_userFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}]"); var xmlIshBackgroundTasks = IshSession.BackgroundTask25.Find( @@ -268,7 +365,7 @@ protected override void EndProcessing() _userFilter, metadataFilter.ToXml(), requestedMetadata.ToXml()); - List returnIshBackgroundTasks = new IshBackgroundTasks(xmlIshBackgroundTasks).BackgroundTasks; + var returnIshBackgroundTasks = new IshBackgroundTasks(xmlIshBackgroundTasks).BackgroundTasks; WriteVerbose("returned object count[" + returnIshBackgroundTasks.Count + "]"); WriteObject(IshSession, ISHType, returnIshBackgroundTasks.ConvertAll(x => (IshBaseObject)x), true); @@ -282,6 +379,22 @@ protected override void EndProcessing() ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null)); } } + + private static string CalculateHashId(byte[] inputData) + { + using (var sha256Hash = SHA256.Create()) + { + var bytes = sha256Hash.ComputeHash(inputData); + var builder = new StringBuilder(); + + foreach (var b in bytes) + { + builder.Append(b.ToString("x2")); + } + + return builder.ToString(); + } + } } } diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObj.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObj.cs index ccc354c3..3f172a33 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObj.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/GetIshDocumentObj.cs @@ -170,10 +170,10 @@ protected override void ProcessRecord() { //RetrieveMetadata WriteDebug("Retrieving CardIds.length[{lngCardIds.Count}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] 0/{lngCardIds.Count}"); - // Devides the list of language card ids in different lists that all have maximally MetadataBatchSize elements - List> devidedlngCardIdsList = DevideListInBatches(lngCardIds, IshSession.MetadataBatchSize); + // Divides the list of language card ids in different lists that all have maximally MetadataBatchSize elements + List> dividedLngCardIdsList = DivideListInBatches(lngCardIds, IshSession.MetadataBatchSize); int currentLngCardIdCount = 0; - foreach (List lngCardIdBatch in devidedlngCardIdsList) + foreach (List lngCardIdBatch in dividedLngCardIdsList) { // Process language card ids in batches string xmlIshObjects = IshSession.DocumentObj25.RetrieveMetadataByIshLngRefs( @@ -191,9 +191,9 @@ protected override void ProcessRecord() WriteDebug($"Retrieving CardIds.length[{lngCardIds.Count}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] including data 0/{lngCardIds.Count}"); IshFeatures productDefinitionFeatures = new IshFeatures(IshFeature); // Devides the list of language card ids in different lists that all have maximally BlobBatchSize elements - List> devidedlngCardIdsList = DevideListInBatches(lngCardIds, IshSession.BlobBatchSize); + List> dividedLngCardIdsList = DivideListInBatches(lngCardIds, IshSession.BlobBatchSize); int currentLngCardIdCount = 0; - foreach (List lngCardIdBatch in devidedlngCardIdsList) + foreach (List lngCardIdBatch in dividedLngCardIdsList) { // Process language card ids in batches string xmlIshObjects = IshSession.DocumentObj25.RetrieveObjectsByIshLngRefs( @@ -216,10 +216,10 @@ protected override void ProcessRecord() { //RetrieveMetadata WriteDebug($"Retrieving LogicalId.length[{LogicalId.Length}] StatusFilter[{statusFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] 0/{LogicalId.Length}"); - // Devides the list of language card ids in different lists that all have maximally MetadataBatchSize elements - List> devidedlogicalIdsList = DevideListInBatches(LogicalId.ToList(), IshSession.MetadataBatchSize); + // Divides the list of language card ids in different lists that all have maximally MetadataBatchSize elements + List> dividedLogicalIdsList = DivideListInBatches(LogicalId.ToList(), IshSession.MetadataBatchSize); int currentLogicalIdCount = 0; - foreach (List logicalIdBatch in devidedlogicalIdsList) + foreach (List logicalIdBatch in dividedLogicalIdsList) { // Process language card ids in batches string xmlIshObjects = IshSession.DocumentObj25.RetrieveMetadata( @@ -238,10 +238,10 @@ protected override void ProcessRecord() //RetrieveObjects WriteDebug($"Retrieving LogicalId.length[{LogicalId.Length}] StatusFilter[{statusFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] 0/{LogicalId.Length}"); IshFeatures productDefinitionFeatures = new IshFeatures(IshFeature); - // Devides the list of language card ids in different lists that all have maximally BlobBatchSize elements - List> devidedlogicalIdsList = DevideListInBatches(LogicalId.ToList(), IshSession.BlobBatchSize); + // Divides the list of language card ids in different lists that all have maximally BlobBatchSize elements + List> dividedLogicalIdsList = DivideListInBatches(LogicalId.ToList(), IshSession.BlobBatchSize); int currentLogicalIdCount = 0; - foreach (List logicalIdBatch in devidedlogicalIdsList) + foreach (List logicalIdBatch in dividedLogicalIdsList) { // Process language card ids in batches string xmlIshObjects = IshSession.DocumentObj25.RetrieveObjects( diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/MoveIshDocumentObj.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/MoveIshDocumentObj.cs index 0a0331e9..b229ebf4 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/MoveIshDocumentObj.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/MoveIshDocumentObj.cs @@ -165,8 +165,8 @@ protected override void ProcessRecord() /// protected override void EndProcessing() { - try - { + try + { // Validating the input where piped objects overrules explicit LogicalId parameter WriteDebug("Validating"); string[] logicalIds; @@ -180,19 +180,19 @@ protected override void EndProcessing() } WriteDebug("Moving"); - if (ShouldProcess(String.Join(", ",logicalIds))) + if (ShouldProcess(String.Join(", ", logicalIds))) { WriteDebug($"Moving logicalIds.length[{logicalIds.Length}] FromFolderId[{_fromFolderId}] ToFolderId[{_toFolderId}] 0/{logicalIds.Length}"); - // Devides the list of language card ids in different lists that all have maximally MetadataBatchSize elements - List> devidedlogicalIdsList = DevideListInBatches(logicalIds.ToList(), IshSession.MetadataBatchSize); + // Divides the list of language card ids in different lists that all have maximally MetadataBatchSize elements + List> dividedLogicalIdsList = DivideListInBatches(logicalIds.ToList(), IshSession.MetadataBatchSize); int currentLogicalIdCount = 0; - foreach (List logicalIdBatch in devidedlogicalIdsList) + foreach (List logicalIdBatch in dividedLogicalIdsList) { // Process language card ids in batches string errorReport = IshSession.Folder25.MoveObjects(_toFolderId, logicalIdBatch.ToArray(), _fromFolderId); ReportErrors(errorReport); currentLogicalIdCount += logicalIdBatch.Count; - WriteDebug($"Moving logicalIds.length[{logicalIds.Length}] FromFolderId[{_fromFolderId}] ToFolderId[{ _toFolderId}] {currentLogicalIdCount}/{logicalIds.Length}"); + WriteDebug($"Moving logicalIds.length[{logicalIds.Length}] FromFolderId[{_fromFolderId}] ToFolderId[{_toFolderId}] {currentLogicalIdCount}/{logicalIds.Length}"); } } @@ -203,12 +203,12 @@ protected override void EndProcessing() IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, new IshFields(), Enumerations.ActionMode.Read); if (_retrievedIshObjects.Count > 0) { - var lngCardIds =_retrievedIshObjects.Select(ishObject => Convert.ToInt64(ishObject.ObjectRef[Enumerations.ReferenceType.Lng])).ToList(); + var lngCardIds = _retrievedIshObjects.Select(ishObject => Convert.ToInt64(ishObject.ObjectRef[Enumerations.ReferenceType.Lng])).ToList(); WriteDebug($"Retrieving CardIds.length[{lngCardIds.Count}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] 0/{lngCardIds.Count}"); - // Devides the list of language card ids in different lists that all have maximally MetadataBatchSize elements - List> devidedlngCardIdsList = DevideListInBatches(lngCardIds, IshSession.MetadataBatchSize); + // Divides the list of language card ids in different lists that all have maximally MetadataBatchSize elements + List> dividedLngCardIdsList = DivideListInBatches(lngCardIds, IshSession.MetadataBatchSize); int currentLngCardIdCount = 0; - foreach (List lngCardIdBatch in devidedlngCardIdsList) + foreach (List lngCardIdBatch in dividedLngCardIdsList) { // Process language card ids in batches string xmlIshObjects = IshSession.DocumentObj25.RetrieveMetadataByIshLngRefs( @@ -224,10 +224,10 @@ protected override void EndProcessing() { // IshObject from pipeline is null. Retrieve using only provided LogicalId array WriteDebug($"Retrieving LogicalId.length[{LogicalId.Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] 0/{LogicalId.Length}"); - // Devides the list of language card ids in different lists that all have maximally MetadataBatchSize elements - List> devidedlogicalIdsList = DevideListInBatches(LogicalId.ToList(), IshSession.MetadataBatchSize); + // Divides the list of language card ids in different lists that all have maximally MetadataBatchSize elements + List> dividedLogicalIdsList = DivideListInBatches(LogicalId.ToList(), IshSession.MetadataBatchSize); int currentLogicalIdCount = 0; - foreach (List logicalIdBatch in devidedlogicalIdsList) + foreach (List logicalIdBatch in dividedLogicalIdsList) { // Process language card ids in batches string xmlIshObjects = IshSession.DocumentObj25.RetrieveMetadata(logicalIdBatch.ToArray(), DocumentObj25ServiceReference.StatusFilter.ISHNoStatusFilter, "", requestedMetadata.ToXml()); diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/SearchIshDocumentObj.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/SearchIshDocumentObj.cs index 2f677ce3..569568dd 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/SearchIshDocumentObj.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/DocumentObj/SearchIshDocumentObj.cs @@ -320,11 +320,11 @@ protected override void ProcessRecord() //RetrieveMetadata WriteDebug("Retrieving CardIds.length[" + lngCardIds.Count + "] RequestedMetadata.length[" + requestedMetadata.ToXml().Length + "] 0/" + lngCardIds.Count); - // Devides the list of language card ids in different lists that all have maximally MetadataBatchSize elements - List> devidedlngCardIdsList = DevideListInBatches(lngCardIds, IshSession.MetadataBatchSize); + // Divides the list of language card ids in different lists that all have maximally MetadataBatchSize elements + List> dividedLngCardIdsList = DivideListInBatches(lngCardIds, IshSession.MetadataBatchSize); int currentLngCardIdCount = 0; WriteParentProgress("Retrieving metadata for search results...", currentLngCardIdCount, lngCardIds.Count); - foreach (List lngCardIdBatch in devidedlngCardIdsList) + foreach (List lngCardIdBatch in dividedLngCardIdsList) { // Process language card ids in batches string xmlIshObjects = IshSession.DocumentObj25.RetrieveMetadataByIshLngRefs( diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/GetIshEvent.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/GetIshEvent.Tests.ps1 index a4f5263f..8b548e6b 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/GetIshEvent.Tests.ps1 +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/EventMonitor/GetIshEvent.Tests.ps1 @@ -149,7 +149,7 @@ Describe "Get-IshEvent" -Tags "Create" { $ishEvent = (Get-IshEvent -IshSession $ishSession -ModifiedSince ((Get-Date).AddMinutes(-10)) -UserFilter All -RequestedMetadata $allProgressMetadata)[0] $ishEvent.ProgressRef -gt 0 | Should -Be $true #$ishEvent.DetailRef -gt 0 | Should -Be $true - if((([Version]$ishSession.ServerVersion).Major -eq 15 -and ([Version]$ishSession.ServerVersion).Minor -ge 1) -or ([Version]$ishSession.ServerVersion).Major -ge 16) { + if((([Version]$ishSession.ServerVersion).Major -eq 15 -and ([Version]$ishSession.ServerVersion).Minor -ge 1) -or ([Version]$ishSession.ServerVersion).Major -ge 16) { $ishEvent.IshField.Count | Should -Be 12 } else { $ishEvent.IshField.Count | Should -Be 10 diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolder.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolder.cs index fb6c93aa..8e75475a 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolder.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolder.cs @@ -248,10 +248,10 @@ protected override void EndProcessing() { var folderCardIds = _retrievedIshFolders.Select(ishFolder => Convert.ToInt64(ishFolder.IshFolderRef)).ToList(); WriteDebug($"Retrieving CardIds.length[{folderCardIds.Count}] RequestedMetadata.length[{_requestedMetadata.ToXml().Length}] 0/{folderCardIds.Count}"); - // Devides the list of folder card ids in different lists that all have maximally MetadataBatchSize elements - List> devidedFolderCardIdsList = DevideListInBatches(folderCardIds, IshSession.MetadataBatchSize); + // Divides the list of folder card ids in different lists that all have maximally MetadataBatchSize elements + List> dividedFolderCardIdsList = DivideListInBatches(folderCardIds, IshSession.MetadataBatchSize); int currentFolderCardIdCount = 0; - foreach (List folderCardIdBatch in devidedFolderCardIdsList) + foreach (List folderCardIdBatch in dividedFolderCardIdsList) { // Process card ids in batches switch (IshSession.Protocol) @@ -272,10 +272,10 @@ protected override void EndProcessing() else if (ParameterSetName == "FolderIdGroup" && _retrievedFolderIds.Count > 0) { WriteDebug($"Retrieving CardIds.length[{ _retrievedFolderIds.Count}] RequestedMetadata.length[{_requestedMetadata.ToXml().Length}] 0/{_retrievedFolderIds.Count}"); - // Devides the list of folder card ids in different lists that all have maximally MetadataBatchSize elements - List> devidedFolderCardIdsList = DevideListInBatches(_retrievedFolderIds, IshSession.MetadataBatchSize); + // Divides the list of folder card ids in different lists that all have maximally MetadataBatchSize elements + List> dividedFolderCardIdsList = DivideListInBatches(_retrievedFolderIds, IshSession.MetadataBatchSize); int currentFolderCardIdCount = 0; - foreach (List folderCardIdBatch in devidedFolderCardIdsList) + foreach (List folderCardIdBatch in dividedFolderCardIdsList) { // Process card ids in batches IshFolders retrievedFolders = null; diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderContent.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderContent.cs index 5e0d80e8..50e2237e 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderContent.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Folder/GetIshFolderContent.cs @@ -294,10 +294,10 @@ protected override void ProcessRecord() Enumerations.ISHType[] ISHType = { Enumerations.ISHType.ISHIllustration, Enumerations.ISHType.ISHLibrary, Enumerations.ISHType.ISHMasterDoc, Enumerations.ISHType.ISHModule, Enumerations.ISHType.ISHTemplate }; IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, new IshFields(RequestedMetadata), Enumerations.ActionMode.Read); - // Devides the list of LogicalIds in different lists that all have maximally MetadataBatchSize elements - List> devidedDocumentLogicalIdsList = DevideListInBatches(documentLogicalIds, IshSession.MetadataBatchSize); + // Divides the list of LogicalIds in different lists that all have maximally MetadataBatchSize elements + List> dividedDocumentLogicalIdsList = DivideListInBatches(documentLogicalIds, IshSession.MetadataBatchSize); int currentLogicalIdCount = 0; - foreach (List logicalIdBatch in devidedDocumentLogicalIdsList) + foreach (List logicalIdBatch in dividedDocumentLogicalIdsList) { currentLogicalIdCount += logicalIdBatch.Count; WriteDebug($"Retrieving DocumentObj.length[{logicalIdBatch.Count}] MetadataFilter.length[{metadataFilterFields.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] {currentLogicalIdCount}/{documentLogicalIds.Count}"); @@ -345,10 +345,10 @@ protected override void ProcessRecord() Enumerations.ISHType[] ISHType = { Enumerations.ISHType.ISHPublication }; IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, new IshFields(RequestedMetadata), Enumerations.ActionMode.Read); - // Devides the list of LogicalIds in different lists that all have maximally MetadataBatchSize elements - List> devidedPublicationLogicalIdsList = DevideListInBatches(publicationLogicalIds, IshSession.MetadataBatchSize); + // Divides the list of LogicalIds in different lists that all have maximally MetadataBatchSize elements + List> dividedPublicationLogicalIdsList = DivideListInBatches(publicationLogicalIds, IshSession.MetadataBatchSize); int currentLogicalIdCount = 0; - foreach (List logicalIdBatch in devidedPublicationLogicalIdsList) + foreach (List logicalIdBatch in dividedPublicationLogicalIdsList) { currentLogicalIdCount += logicalIdBatch.Count; WriteDebug($"Retrieving PublicationOutput.length[{logicalIdBatch.Count}] MetadataFilter.length[{metadataFilterFields.ToXml().Length}] {currentLogicalIdCount}/{publicationLogicalIds.Count}"); diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/GetIshPublicationOutput.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/GetIshPublicationOutput.cs index 23502518..23d2ba1d 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/GetIshPublicationOutput.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/PublicationOutput/GetIshPublicationOutput.cs @@ -158,10 +158,10 @@ protected override void ProcessRecord() ishObject => Convert.ToInt64(ishObject.ObjectRef[Enumerations.ReferenceType.Lng])) .ToList(); WriteDebug($"Retrieving CardIds.length[{lngCardIds}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] 0/{lngCardIds.Count}"); - // Devides the list of language card ids in different lists that all have maximally MetadataBatchSize elements - List> devidedlngCardIdsList = DevideListInBatches(lngCardIds, IshSession.MetadataBatchSize); + // Divides the list of language card ids in different lists that all have maximally MetadataBatchSize elements + List> dividedLngCardIdsList = DivideListInBatches(lngCardIds, IshSession.MetadataBatchSize); int currentLngCardIdCount = 0; - foreach (List lngCardIdBatch in devidedlngCardIdsList) + foreach (List lngCardIdBatch in dividedLngCardIdsList) { // Process language card ids in batches string xmlIshObjects = IshSession.PublicationOutput25.RetrieveMetadataByIshLngRefs( @@ -180,10 +180,10 @@ protected override void ProcessRecord() EnumConverter.ToStatusFilter(StatusFilter); IshFields metadataFilter = new IshFields(MetadataFilter); WriteDebug($"Retrieving LogicalId.length[{LogicalId.Length}] StatusFilter[{statusFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] 0/{LogicalId.Length}"); - // Devides the list of language card ids in different lists that all have maximally MetadataBatchSize elements - List> devidedlogicalIdsList = DevideListInBatches(LogicalId.ToList(), IshSession.MetadataBatchSize); + // Divides the list of language card ids in different lists that all have maximally MetadataBatchSize elements + List> dividedLogicalIdsList = DivideListInBatches(LogicalId.ToList(), IshSession.MetadataBatchSize); int currentLogicalIdCount = 0; - foreach (List logicalIdBatch in devidedlogicalIdsList) + foreach (List logicalIdBatch in dividedLogicalIdsList) { // Process language card ids in batches string xmlIshObjects = IshSession.PublicationOutput25.RetrieveMetadata( diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Settings/CompareIshTypeFieldDefinition.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Settings/CompareIshTypeFieldDefinition.Tests.ps1 index 9507af0d..204503e0 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Settings/CompareIshTypeFieldDefinition.Tests.ps1 +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Settings/CompareIshTypeFieldDefinition.Tests.ps1 @@ -128,13 +128,13 @@ Describe "Compare-IshTypeFieldDefinition" -Tags "Read" { else { It "Parameter Left is TriDKXmlSetupFilePath and Right is IshSession using ExcludeRightUnique" { - (Compare-IshTypeFieldDefinition -LeftIshTypeFieldDefinition $referenceIshTypeFieldDefinitions -RightIshSession $ishSession -ExcludeRightUnique).Count | Should -Be 11 + (Compare-IshTypeFieldDefinition -LeftIshTypeFieldDefinition $referenceIshTypeFieldDefinitions -RightIshSession $ishSession -ExcludeRightUnique).Count | Should -Be 9 } It "Parameter Left is TriDKXmlSetupFilePath and Right is IshSession using ExcludeLeftUnique/ExcludeRightUnique" { - (Compare-IshTypeFieldDefinition -LeftIshTypeFieldDefinition $referenceIshTypeFieldDefinitions -RightIshSession $ishSession -ExcludeLeftUnique -ExcludeRightUnique).Count | Should -Be 10 + (Compare-IshTypeFieldDefinition -LeftIshTypeFieldDefinition $referenceIshTypeFieldDefinitions -RightIshSession $ishSession -ExcludeLeftUnique -ExcludeRightUnique).Count | Should -Be 8 } It "Parameter Left is TriDKXmlSetupFilePath and Right is IshSession using ExcludeDifferent/ExcludeLeftUnique/ExcludeRightUnique" { - (Compare-IshTypeFieldDefinition -LeftIshTypeFieldDefinition $referenceIshTypeFieldDefinitions -RightIshSession $ishSession -IncludeIdentical -ExcludeDifferent -ExcludeLeftUnique -ExcludeRightUnique).Count | Should -Be 0 + (Compare-IshTypeFieldDefinition -LeftIshTypeFieldDefinition $referenceIshTypeFieldDefinitions -RightIshSession $ishSession -IncludeIdentical -ExcludeDifferent -ExcludeLeftUnique -ExcludeRightUnique).Count | Should -Be 1 } } It "Parameter Left is TriDKXmlSetupFilePath and Right is IshSession using ExcludeDifferent/ExcludeLeftUnique/ExcludeRightUnique" { diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Settings/GetIshTypeFieldDefinition.Tests.ps1 b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Settings/GetIshTypeFieldDefinition.Tests.ps1 index df46bfac..a6ec064a 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Settings/GetIshTypeFieldDefinition.Tests.ps1 +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/Settings/GetIshTypeFieldDefinition.Tests.ps1 @@ -73,12 +73,12 @@ Describe "Get-IshTypeFieldDefinition" -Tags "Read" { It "Table ISHEvent" { if((([Version]$ishSession.ServerVersion).Major -eq 15 -and ([Version]$ishSession.ServerVersion).Minor -ge 1) -or ([Version]$ishSession.ServerVersion).Major -ge 16) { - (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property Level -EQ 'Progress').Count | Should -Be 12 - (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property Level -EQ 'Detail').Count | Should -Be 13 - (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property AllowOnRead -EQ $true).Count | Should -Be 25 # all columns are allowed to be read - (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property AllowOnCreate -EQ $false).Count | Should -Be 13 # all columns are explicit api parameters and cannot be set over metadata - (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property IsMultiValue -EQ $false).Count | Should -Be 25 # all columns are single value - (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property IsSystem -EQ $true).Count | Should -Be 25 # all columns are system columns + (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property Level -EQ 'Progress').Count | Should -Be 11 + (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property Level -EQ 'Detail').Count | Should -Be 12 + (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property AllowOnRead -EQ $true).Count | Should -Be 23 # all columns are allowed to be read + (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property AllowOnCreate -EQ $false).Count | Should -Be 11 # all columns are explicit api parameters and cannot be set over metadata + (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property IsMultiValue -EQ $false).Count | Should -Be 23 # all columns are single value + (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property IsSystem -EQ $true).Count | Should -Be 23 # all columns are system columns (Get-IshTypeFieldDefinition -IshSession $ishSession | Where-Object -Property ISHType -EQ 'ISHEvent' | Where-Object -Property Name -EQ 'USERID').DataSource | Should -Be 'ISHUser' } else diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/TrisoftCmdlet.cs b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/TrisoftCmdlet.cs index fc7fbdf4..0750367c 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/TrisoftCmdlet.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Cmdlets/TrisoftCmdlet.cs @@ -18,14 +18,12 @@ using System.Collections.Generic; using System.Linq; using System.Management.Automation; -using Trisoft.ISHRemote.Objects; -using Trisoft.ISHRemote.Objects.Public; -using Trisoft.ISHRemote.Exceptions; using System.Threading; using System.Xml; -using Trisoft.ISHRemote.Interfaces; using Trisoft.ISHRemote.Folder25ServiceReference; -using System.Runtime.InteropServices; +using Trisoft.ISHRemote.Interfaces; +using Trisoft.ISHRemote.Objects; +using Trisoft.ISHRemote.Objects.Public; namespace Trisoft.ISHRemote.Cmdlets { @@ -257,13 +255,13 @@ internal virtual string BaseFolderEnumToLabel(IshSession ishSession, Folder25Ser /// - /// Devides one list to multiple lists by batchsize + /// Divides one list to multiple lists by batchsize /// /// Type /// List to devide /// /// Multiple lists, all having maximally batchsize elements - internal List> DevideListInBatches(List list, int batchSize) + internal List> DivideListInBatches(List list, int batchSize) { var outList = new List>(); if (list != null) @@ -275,37 +273,5 @@ internal List> DevideListInBatches(List list, int batchSize) } return outList; } - - /// - /// Groups IshObjects list by LogicalIds and divides into multiple lists by batchsize so that objects with the same LogicalIds are never split between batches. - /// - /// List to devide - /// - /// Multiple lists grouped by LogicalIds and having maximally batchsize elements, but the same LogicalId is never split between batches - internal List>DevideListInBatchesByLogicalId(List list, int batchSize) - { - var outList = new List>(); - - if (list != null) - { - var ishObjectsGroupedByIshRef = list.GroupBy(ishObject => ishObject.IshRef); - var tempList = new List(ishObjectsGroupedByIshRef.First().ToList()); - foreach (var ishObjectsIshRefGroup in ishObjectsGroupedByIshRef.Skip(1)) - { - if (tempList.Count + ishObjectsIshRefGroup.Count() <= batchSize) - { - tempList.AddRange(ishObjectsIshRefGroup.ToList()); - } - else - { - outList.Add(tempList); - tempList = ishObjectsIshRefGroup.ToList(); - } - } - outList.Add(tempList); - } - - return outList; - } } } diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Objects/Enumerations.cs b/Source/ISHRemote/Trisoft.ISHRemote/Objects/Enumerations.cs index 4357a6d1..5b52a344 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Objects/Enumerations.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Objects/Enumerations.cs @@ -633,6 +633,16 @@ public enum BaselineSourceEnumeration ExpandFirstVersion, } + /// + /// The InputDataTemplate (e.g. IshObjectWithLngRef) indicates whether a list of ishObjects or one ishObject is submitted as input data to the background task. + /// + public enum InputDataTemplate + { + IshObjectsWithLngRef, + IshObjectWithLngRef, + IshObjectsWithIshRef + } + /// /// Unique descriptive identifier of an IshTypeFieldDefinition concatenating type, level (respecting log/version/lng), and field name ///