Esempio n. 1
0
        protected override void ProcessRecord()
        {
            try
            {
                // Work with piped IshFeatures object or create a new one.
                IshFeatures ishFeatures = new IshFeatures(IshFeature);
                string      name        = Name ?? "";
                string      value       = Value ?? "";

                WriteVerbose("name[" + name + "] value[" + value + "]");

                if (Name != "")
                {
                    IshFeature ishFeature = new IshFeature(name, value);
                    ishFeatures.AddFeature(ishFeature);
                }

                WriteObject(ishFeatures.Features, 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
                        };
                        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));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Process the Get-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> returnIshObjects = 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(IshSession.DefaultRequestedMetadata, 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();
                        if (!_includeData)
                        {
                            //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 <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(ISHType, 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
                        {
                            //RetrieveObjects
                            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 <List <long> > devidedlngCardIdsList = DevideListInBatches <long>(lngCardIds, IshSession.BlobBatchSize);
                            int currentLngCardIdCount = 0;
                            foreach (List <long> lngCardIdBatch in devidedlngCardIdsList)
                            {
                                // Process language card ids in batches
                                string xmlIshObjects = IshSession.DocumentObj25.RetrieveObjectsByIshLngRefs(
                                    lngCardIdBatch.ToArray(),
                                    productDefinitionFeatures.ToXml(),
                                    requestedMetadata.ToXml());
                                IshObjects retrievedObjects = new IshObjects(ISHType, 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
                    {
                        // 2b. Retrieve using LogicalId
                        IshFields metadataFilter = new IshFields(MetadataFilter);
                        var       statusFilter   = EnumConverter.ToStatusFilter <DocumentObj25ServiceReference.StatusFilter>(StatusFilter);
                        if (!_includeData)
                        {
                            //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 <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(),
                                    statusFilter,
                                    metadataFilter.ToXml(),
                                    requestedMetadata.ToXml());
                                IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
                                returnIshObjects.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}");
                            }
                        }
                        else
                        {
                            //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 <List <string> > devidedlogicalIdsList = DevideListInBatches <string>(LogicalId.ToList(), IshSession.BlobBatchSize);
                            int currentLogicalIdCount = 0;
                            foreach (List <string> logicalIdBatch in devidedlogicalIdsList)
                            {
                                // Process language card ids in batches
                                string xmlIshObjects = IshSession.DocumentObj25.RetrieveObjects(
                                    logicalIdBatch.ToArray(),
                                    statusFilter,
                                    metadataFilter.ToXml(),
                                    productDefinitionFeatures.ToXml(),
                                    requestedMetadata.ToXml());
                                IshObjects retrievedObjects = new IshObjects(ISHType, xmlIshObjects);
                                returnIshObjects.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[" + 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));
            }
        }
Esempio n. 4
0
        /// <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));
            }
        }