/// <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 Add-IshDocumentObj commandlet. /// </summary> /// <exception cref="TrisoftAutomationException"></exception> /// <exception cref="Exception"></exception> /// <remarks>Writes an <see cref="IshObject"/> array to the pipeline.</remarks> protected override void ProcessRecord() { try { // 1. Validating the input WriteDebug("Validating"); // Parameters to retrieve added document List <IshObject> returnIshObjects = new List <IshObject>(); WriteDebug("Adding"); if (IshObject != null) { int current = 0; foreach (IshObject ishObject in IshObject) { WriteDebug($"lngRef[{ishObject.ObjectRef[Enumerations.ReferenceType.Lng]}] {++current}/{IshObject.Length}"); // 2b. Add using IshObject pipeline // Initialize from the object string logicalId = ishObject.IshRef; string ishObjectVersion = ishObject.IshFields.GetFieldValue("VERSION", Enumerations.Level.Version, Enumerations.ValueType.Value); //TODO: [Should] Respect LanguageApplicability, which means take the first entry from the ishfield DOC-LANGUAGE value string ishObjectLanguage = ishObject.IshFields.GetFieldValue("DOC-LANGUAGE", Enumerations.Level.Lng, Enumerations.ValueType.Value); string ishObjectResolution = ishObject.IshFields.GetFieldValue("FRESOLUTION", Enumerations.Level.Lng, Enumerations.ValueType.Value); var metadata = IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, ishObject.IshFields, Enumerations.ActionMode.Create); // Add WriteDebug($"LogicalId[{logicalId}] Version[{ishObjectVersion}] Lng[{ishObjectLanguage}] Resolution[{ishObjectResolution}] Metadata.length[{metadata.ToXml().Length}] dataSize[{ishObject.IshData.Size()}]"); DocumentObj25ServiceReference.CreateResponse response = null; if (ShouldProcess(logicalId + "=" + ishObjectVersion + "=" + ishObjectLanguage + "=" + ishObjectResolution)) { response = IshSession.DocumentObj25.Create(new DocumentObj25ServiceReference.CreateRequest( _folderId, ishObject.IshType.ToString(), logicalId, ishObjectVersion, ishObjectLanguage, ishObjectResolution, metadata.ToXml(), ishObject.IshData.Edt, ishObject.IshData.ByteArray)); } IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, metadata, Enumerations.ActionMode.Read); var response2 = IshSession.DocumentObj25.GetMetadata(new DocumentObj25ServiceReference.GetMetadataRequest( response.logicalId, response.version, ishObjectLanguage, ishObjectResolution, requestedMetadata.ToXml())); string xmlIshObjects = response2.xmlObjectList; IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects); returnIshObjects.AddRange(retrievedObjects.Objects); } } // 2a. LogicalId is provided else { string resolution = Resolution ?? ""; if ((FileContent != null) && (FilePath == null)) { if (!_edt.Equals("EDTXML", StringComparison.Ordinal)) { throw new NotImplementedException("FileContent parameter is only supported with Edt='EDTXML'"); } var doc = XDocument.Parse(FileContent, LoadOptions.PreserveWhitespace); var ms = new MemoryStream(); doc.Save(ms, SaveOptions.DisableFormatting); _ishData = new IshData(_edt, ms.ToArray()); } if ((FileContent == null) && (FilePath != null)) { _ishData = new IshData(_edt, FilePath); } var metadata = IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, new IshFields(Metadata), Enumerations.ActionMode.Create); WriteDebug($"LogicalId[{LogicalId}] Version[{Version}] Lng[{Lng}] Resolution[{resolution}] Metadata.length[{metadata.ToXml().Length}] byteArray[{_ishData.Size()}]"); DocumentObj25ServiceReference.CreateResponse response = null; if (ShouldProcess(LogicalId + "=" + Version + "=" + Lng + "=" + resolution)) { response = IshSession.DocumentObj25.Create(new DocumentObj25ServiceReference.CreateRequest( _folderId, IshType.ToString(), LogicalId, Version, Lng, resolution, metadata.ToXml(), _ishData.Edt, _ishData.ByteArray)); IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, metadata, Enumerations.ActionMode.Read); var response2 = IshSession.DocumentObj25.GetMetadata(new DocumentObj25ServiceReference.GetMetadataRequest( response.logicalId, response.version, Lng, resolution, requestedMetadata.ToXml())); string xmlIshObjects = response2.xmlObjectList; IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects); returnIshObjects.AddRange(retrievedObjects.Objects); } } WriteVerbose("returned object count[" + returnIshObjects.Count + "]"); WriteObject(IshSession, ISHType, returnIshObjects.ConvertAll(x => (IshBaseObject)x), 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)); } }
/// <summary> /// Process the Set-IshDocumentObj commandlet. /// </summary> /// <exception cref="TrisoftAutomationException"></exception> /// <exception cref="Exception"></exception> /// <remarks>Writes an <see cref="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 update"); } else { // 2. Doing the update WriteDebug("Updating"); IshFields requiredCurrentMetadata = new IshFields(RequiredCurrentMetadata); if (IshObject != null) { int current = 0; IshObject[] ishObjects = IshObject; List <long> lngCardIds = new List <long>(); foreach (IshObject ishObject in ishObjects) { // Get language ref long lngRef = Convert.ToInt64(ishObject.ObjectRef[Enumerations.ReferenceType.Lng]); // Use incoming Metadata for update operation, or re-submit metadata of incoming IshObjects var metadata = (Metadata != null) ? IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, new IshFields(Metadata), Enumerations.ActionMode.Update) : IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, ishObject.IshFields, Enumerations.ActionMode.Update); if (ishObject.IshData != null) { WriteDebug($"lngRef[{lngRef}] Metadata.length[{metadata.ToXml().Length}] dataSize[{ishObject.IshData.Size()}] {++current}/{ishObjects.Length}"); if (ShouldProcess(Convert.ToString(lngRef))) { IshSession.DocumentObj25.UpdateByIshLngRef( lngRef, metadata.ToXml(), requiredCurrentMetadata.ToXml(), ishObject.IshData.Edt, ishObject.IshData.ByteArray); } } else { WriteDebug($"lngRef[{lngRef}] Metadata.length[{metadata.ToXml().Length}] dataSize[0] {++current}/{ishObjects.Length}"); if (ShouldProcess(Convert.ToString(lngRef))) { IshSession.DocumentObj25.SetMetadataByIshLngRef( lngRef, metadata.ToXml(), requiredCurrentMetadata.ToXml()); } } lngCardIds.Add(lngRef); } var returnFields = (IshObject[0] == null) ? new IshFields() : IshObject[0].IshFields; IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, returnFields, Enumerations.ActionMode.Read); string xmlIshObjects = IshSession.DocumentObj25.RetrieveMetadataByIshLngRefs(lngCardIds.ToArray(), requestedMetadata.ToXml()); IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects); returnedObjects.AddRange(retrievedObjects.Objects); } else { string resolution = Resolution ?? ""; var metadata = IshSession.IshTypeFieldSetup.ToIshMetadataFields(ISHType, new IshFields(Metadata), Enumerations.ActionMode.Update); string version = "-1"; if (Edt != null && FilePath != null) { IshData ishData = new IshData(Edt, FilePath); WriteDebug($"Id[{LogicalId}] Version[{Version}] Lng[{Lng}] Resolution[{resolution}] Metadata.length[{metadata.ToXml().Length}] dataSize[{ishData.Size()}]"); DocumentObj25ServiceReference.UpdateResponse response = null; if (ShouldProcess(LogicalId + "=" + Version + "=" + Lng + "=" + resolution)) { response = IshSession.DocumentObj25.Update(new UpdateRequest( LogicalId, Version, Lng, resolution, metadata.ToXml(), requiredCurrentMetadata.ToXml(), ishData.Edt, ishData.ByteArray)); version = response.version; } } else { WriteDebug($"Id[{LogicalId}] Version[{Version}] Lng[{Lng}] Resolution[{resolution}] Metadata.length[{metadata.ToXml().Length}] dataSize[0]"); DocumentObj25ServiceReference.SetMetadataResponse response = null; if (ShouldProcess(LogicalId + "=" + Version + "=" + Lng + "=" + resolution)) { response = IshSession.DocumentObj25.SetMetadata(new SetMetadataRequest( LogicalId, Version, Lng, resolution, metadata.ToXml(), requiredCurrentMetadata.ToXml())); version = response.version; } } IshFields requestedMetadata = IshSession.IshTypeFieldSetup.ToIshRequestedMetadataFields(IshSession.DefaultRequestedMetadata, ISHType, metadata, Enumerations.ActionMode.Read); var response2 = IshSession.DocumentObj25.GetMetadata(new GetMetadataRequest(LogicalId, version, Lng, resolution, requestedMetadata.ToXml())); string xmlIshObjects = response2.xmlObjectList; IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects); returnedObjects.AddRange(retrievedObjects.Objects); } } // 3. Write it WriteVerbose("returned object count[" + returnedObjects.Count + "]"); WriteObject(IshSession, ISHType, returnedObjects.ConvertAll(x => (IshBaseObject)x), 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)); } }
/// <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)); } }