/// <summary> /// Process the Get-IshPublicationOutputData commandlet. /// </summary> /// <exception cref="TrisoftAutomationException"></exception> /// <exception cref="Exception"></exception> /// <remarks>Writes an <see cref="File"/> array to the pipeline.</remarks> protected override void ProcessRecord() { try { List <FileInfo> fileInfo = new List <FileInfo>(); if (IshObject != null && IshObject.Length == 0) { // Do nothing WriteVerbose("IshObject is empty, so nothing to retrieve"); } else { WriteDebug("Retrieving"); string tempLocation = Directory.CreateDirectory(FolderPath).FullName; int current = 0; var ishObjects = new IshObjects(IshObject).Objects; foreach (IshObject ishObject in ishObjects) { // Get language ref long lngRef = Convert.ToInt64(ishObject.ObjectRef[Enumerations.ReferenceType.Lng]); string xmlIshDataObject = IshSession.PublicationOutput25.GetDataObjectInfoByIshLngRef(lngRef); // Put the xml in a dataobject XmlDocument xmlIshDataObjectDocument = new XmlDocument(); xmlIshDataObjectDocument.LoadXml(xmlIshDataObject); XmlElement ishDataObjectElement = (XmlElement)xmlIshDataObjectDocument.SelectSingleNode("ishdataobjects/ishdataobject"); IshDataObject ishDataObject = new IshDataObject(ishDataObjectElement); string tempFilePath = FileNameHelper.GetDefaultPublicationOutputFileName(tempLocation, ishObject, ishDataObject.FileExtension); WriteDebug($"Writing lngRef[{lngRef}] to [{tempFilePath}] {++current}/{ishObjects.Length}"); //Create the file. using (FileStream fs = File.Create(tempFilePath)) { for (int offset = 0; offset < ishDataObject.Size; offset += IshSession.ChunkSize) { int size = IshSession.ChunkSize; long offsetCount = offset; byte[] byteArray = new byte[IshSession.ChunkSize]; var response = IshSession.PublicationOutput25.GetNextDataObjectChunkByIshLngRef( new PublicationOutput25ServiceReference.GetNextDataObjectChunkByIshLngRefRequest( lngRef, ishDataObject.Ed, offsetCount, size)); offsetCount = response.offSet; size = response.size; byteArray = response.bytes; fs.Write(byteArray, 0, size); } } // Append file info list fileInfo.Add(new FileInfo(tempFilePath)); } } WriteVerbose("returned file count[" + fileInfo.Count + "]"); WriteObject(fileInfo, 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)); } }