Пример #1
0
        /// <summary>
        /// Process the Get-IshPublicationOutput commandlet.
        /// </summary>
        /// <exception cref="TrisoftAutomationException"></exception>
        /// <exception cref="Exception"></exception>
        /// <remarks>Writes an <see cref="Objects.IshObject"/> array to the pipeline.</remarks>
        protected override void ProcessRecord()
        {
            try
            {
                // 1. Validating the input
                WriteDebug("Validating");

                List <IshObject> returnedObjects = new List <IshObject>();

                if (IshObject != null && IshObject.Length == 0)
                {
                    // Do nothing
                    WriteVerbose("IshObject is empty, so nothing to retrieve");
                }
                else
                {
                    WriteDebug("Retrieving");
                    IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(ISHType, new IshFields(RequestedMetadata), Enumerations.ActionMode.Read);
                    if (IshObject != null)
                    {
                        // 2a. Retrieve using LngCardIds
                        IshObjects ishObjects = new IshObjects(IshObject);
                        var        lngCardIds =
                            ishObjects.Objects.Select(
                                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 <List <long> > devidedlngCardIdsList = DevideListInBatches <long>(lngCardIds, IshSession.MetadataBatchSize);
                        int currentLngCardIdCount = 0;
                        foreach (List <long> lngCardIdBatch in devidedlngCardIdsList)
                        {
                            // Process language card ids in batches
                            string xmlIshObjects = IshSession.PublicationOutput25.RetrieveMetadataByIshLngRefs(
                                lngCardIdBatch.ToArray(),
                                requestedMetadata.ToXml());
                            IshObjects retrievedObjects = new IshObjects(xmlIshObjects);
                            returnedObjects.AddRange(retrievedObjects.Objects);
                            currentLngCardIdCount += lngCardIdBatch.Count;
                            WriteDebug($"Retrieving CardIds.length[{lngCardIdBatch.Count}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] including data {currentLngCardIdCount}/{lngCardIds.Count}");
                        }
                    }
                    else
                    {
                        // 2b. Retrieve using LogicalId
                        PublicationOutput25ServiceReference.StatusFilter statusFilter =
                            EnumConverter.ToStatusFilter <PublicationOutput25ServiceReference.StatusFilter>(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 <List <string> > devidedlogicalIdsList = DevideListInBatches <string>(LogicalId.ToList(), IshSession.MetadataBatchSize);
                        int currentLogicalIdCount = 0;
                        foreach (List <string> logicalIdBatch in devidedlogicalIdsList)
                        {
                            // Process language card ids in batches
                            string xmlIshObjects = IshSession.PublicationOutput25.RetrieveMetadata(
                                logicalIdBatch.ToArray(),
                                statusFilter,
                                metadataFilter.ToXml(),
                                requestedMetadata.ToXml());
                            IshObjects retrievedObjects = new IshObjects(xmlIshObjects);
                            returnedObjects.AddRange(retrievedObjects.Objects);
                            currentLogicalIdCount += logicalIdBatch.Count;
                            WriteDebug($"Retrieving LogicalId.length[{logicalIdBatch.Count}] StatusFilter[{statusFilter}] MetadataFilter.length[{metadataFilter.ToXml().Length}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] {currentLogicalIdCount}/{LogicalId.Length}");
                        }
                    }
                }

                WriteVerbose("returned object count[" + returnedObjects.Count + "]");
                WriteObject(returnedObjects, true);
            }
            catch (TrisoftAutomationException trisoftAutomationException)
            {
                ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
            }
            catch (Exception exception)
            {
                ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
            }
        }
Пример #2
0
        /// <summary>
        /// EndProcess the Move-IshDocumentObj commandlet.
        /// </summary>
        /// <exception cref="TrisoftAutomationException"></exception>
        /// <exception cref="Exception"></exception>
        protected override void EndProcessing()
        {
            try
            {
                // Validating the input where piped objects overrules explicit LogicalId parameter
                WriteDebug("Validating");
                string[] logicalIds;
                if (_retrievedIshObjects.Count > 0)
                {
                    logicalIds = _retrievedIshObjects.Select(ishObject => ishObject.IshRef).ToArray <string>();
                }
                else
                {
                    logicalIds = LogicalId;
                }

                WriteDebug("Moving");
                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 <List <string> > devidedlogicalIdsList = DevideListInBatches <string>(logicalIds.ToList(), IshSession.MetadataBatchSize);
                    int currentLogicalIdCount = 0;
                    foreach (List <string> logicalIdBatch in devidedlogicalIdsList)
                    {
                        // 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}");
                    }
                }

                // Retrieve moved object(s) to write to the pipeline for a potential security/usergroup change
                WriteDebug("Retrieving");
                var returnIshObjects = new List <IshObject>();
                // Add the required fields (needed for pipe operations)
                IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(ISHType, new IshFields(), Enumerations.ActionMode.Read);
                if (_retrievedIshObjects.Count > 0)
                {
                    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 <List <long> > devidedlngCardIdsList = DevideListInBatches <long>(lngCardIds, IshSession.MetadataBatchSize);
                    int currentLngCardIdCount = 0;
                    foreach (List <long> lngCardIdBatch in devidedlngCardIdsList)
                    {
                        // Process language card ids in batches
                        string xmlIshObjects = IshSession.DocumentObj25.RetrieveMetadataByIshLngRefs(
                            lngCardIdBatch.ToArray(),
                            requestedMetadata.ToXml());
                        IshObjects retrievedObjects = new IshObjects(xmlIshObjects);
                        returnIshObjects.AddRange(retrievedObjects.Objects);
                        currentLngCardIdCount += lngCardIdBatch.Count;
                        WriteDebug($"Retrieving CardIds.length[{lngCardIdBatch.Count}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] including data {currentLngCardIdCount}/{lngCardIds.Count}");
                    }
                }
                else
                {
                    // 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 <List <string> > devidedlogicalIdsList = DevideListInBatches <string>(LogicalId.ToList(), IshSession.MetadataBatchSize);
                    int currentLogicalIdCount = 0;
                    foreach (List <string> logicalIdBatch in devidedlogicalIdsList)
                    {
                        // Process language card ids in batches
                        string     xmlIshObjects    = IshSession.DocumentObj25.RetrieveMetadata(logicalIdBatch.ToArray(), DocumentObj25ServiceReference.StatusFilter.ISHNoStatusFilter, "", requestedMetadata.ToXml());
                        IshObjects retrievedObjects = new IshObjects(xmlIshObjects);
                        returnIshObjects.AddRange(retrievedObjects.Objects);
                        currentLogicalIdCount += logicalIdBatch.Count;
                        WriteDebug($"Retrieving LogicalId.length[{logicalIdBatch.Count}] RequestedMetadata.length[{requestedMetadata.ToXml().Length}] {currentLogicalIdCount}/{LogicalId.Length}");
                    }
                }

                // Write retrieved objects to pipeline
                WriteVerbose("returned object count[" + returnIshObjects.Count + "]");
                WriteObject(returnIshObjects, true);
            }
            catch (TrisoftAutomationException trisoftAutomationException)
            {
                ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
            }
            catch (Exception exception)
            {
                ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
            }
            finally
            {
                base.EndProcessing();
            }
        }