/// <summary> /// Process the Get-IshDocumentObjData 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) { WriteVerbose("IshObject is empty, so nothing to retrieve"); } else { WriteDebug("Retrieving"); IshFeatures productDefinitionFeatures = new IshFeatures(IshFeature); 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]); long[] lngRefsArray = new long[1] { lngRef }; var dataObjectResponse = IshSession.DocumentObj25.RetrieveObjectsByIshLngRefs(lngRefsArray, productDefinitionFeatures.ToXml(), ""); XmlDocument xmlIshDataObject = new XmlDocument(); xmlIshDataObject.LoadXml(dataObjectResponse); XmlElement ishDataObjectElement = (XmlElement)xmlIshDataObject.SelectSingleNode("ishobjects/ishobject/ishdata"); IshData ishData = new IshData(ishDataObjectElement); if (FolderPath != null) { string tempLocation = Directory.CreateDirectory(FolderPath).FullName; WriteDebug($"Writing lngRef[{lngRef}] to [{tempLocation}] {++current}/{ishObjects.Length}"); //Create the file. string tempFilePath = FileNameHelper.GetDefaultObjectFileName(tempLocation, ishObject, ishData.FileExtension); using (FileStream fs = File.Create(tempFilePath)) { fs.Write(ishData.ByteArray, 0, ishData.Size()); } // Append file info list fileInfo.Add(new FileInfo(tempFilePath)); WriteObject(fileInfo, true); } else { WriteDebug($"Enriching ishObject[{ishObject.ObjectRef[Enumerations.ReferenceType.Lng]}] with IshData {++current}/{IshObject.Length}"); ishObject.IshData = ishData; WriteObject(ishObject, true); } } WriteVerbose("returned file count[" + current + "]"); } } 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)); } }
/// <summary> /// Process the Get-IshDocumentObjData 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) { WriteVerbose("IshObject is empty, so nothing to retrieve"); } else { WriteDebug("Retrieving"); IshFeatures productDefinitionFeatures = new IshFeatures(IshFeature); 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]); long[] lngRefsArray = new long[1] { lngRef }; using (var stringReader = new StringReader(IshSession.DocumentObj25.RetrieveObjectsByIshLngRefs(lngRefsArray, productDefinitionFeatures.ToXml(), ""))) { byte[] bytearray = null; string edt = ""; string fileExtension = ""; using (XmlTextReader xmlTextReader = new XmlTextReader(stringReader)) { while (xmlTextReader.Read()) { if (xmlTextReader.NodeType == XmlNodeType.Element && xmlTextReader.Name == "ishdata") { edt = xmlTextReader.GetAttribute("edt"); fileExtension = xmlTextReader.GetAttribute("fileextension"); } if (xmlTextReader.NodeType == XmlNodeType.CDATA) { bytearray = System.Convert.FromBase64String(xmlTextReader.Value); } } } IshData ishData = new IshData(edt, fileExtension, bytearray); if (FolderPath != null) { string tempLocation = Directory.CreateDirectory(FolderPath).FullName; WriteDebug($"Writing lngRef[{lngRef}] to [{tempLocation}] {++current}/{ishObjects.Length}"); //Create the file. string tempFilePath = FileNameHelper.GetDefaultObjectFileName(tempLocation, ishObject, ishData.FileExtension); using (FileStream fs = File.Create(tempFilePath)) { fs.Write(ishData.ByteArray, 0, ishData.Size()); } // Append file info list fileInfo.Add(new FileInfo(tempFilePath)); WriteObject(fileInfo, true); } else { WriteDebug($"Enriching ishObject[{ishObject.ObjectRef[Enumerations.ReferenceType.Lng]}] with IshData {++current}/{IshObject.Length}"); ishObject.IshData = ishData; WriteObject(ishObject, true); } } } WriteVerbose("returned file count[" + current + "]"); } } 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)); } }