예제 #1
0
        private XmlNodeList GetRowsFromXml(CurrentDocumentData document)
        {
            logger.Indent();
            logger.Log($"Fetching attachment from field id '{this.Configuration.SourceConfiguration.AttachmentPickerFieldId}'");
            var pickerFieldId = int.Parse(this.Configuration.SourceConfiguration.AttachmentPickerFieldId);
            var field         = document.ChooseFields.GetByID(pickerFieldId);

            if (!int.TryParse(field.Value.ID, out int attachmentId))
            {
                throw new ApplicationException($"Could not parse Id to int of field value {field.Value}");
            }

            var attachment = document.Attachments.GetByID(attachmentId);

            logger.Log($"Creating XmlDocument from attachment '{attachmentId}'");
            XmlDocument xml = new XmlDocument();
            string      attachmentContent = Encoding.UTF8.GetString(attachment.Content);

            xml.LoadXml(attachmentContent);
            logger.Log($"Selecting nodes using XPath '{this.Configuration.SourceConfiguration.XPath}'");
            var nodes = xml.SelectNodes(this.Configuration.SourceConfiguration.XPath);

            if (nodes.Count == 0)
            {
                throw new ApplicationException($"No rows were returned for attachment with id '{attachmentId}'");
            }
            else
            {
                logger.Log($"XPath returned {nodes.Count} nodes");
            }
            logger.Outdent();
            return(nodes);
        }
예제 #2
0
        private void PopulateItemList(CurrentDocumentData document, XmlNodeList rows, WebCon.WorkFlow.SDK.Documents.Model.ItemsLists.ItemsList list)
        {
            logger.Indent();
            for (int i = 0; i < rows.Count; i++)
            {
                logger.Log($"Creating a new row in item list for xml row number '{i}'");

                XmlNode row    = rows[i];
                var     newRow = list.Rows.AddNewRow();
                foreach (var mapping in Configuration.TargetConfiguration.Mapping)
                {
                    try
                    {
                        var    column      = list.Columns.GetByDbColumnName(mapping.TargetColumnName);
                        var    node        = row[mapping.NodeName];
                        object targetValue = null;
                        if (!string.IsNullOrEmpty(node.InnerText))
                        {
                            var type = (TargetValueType)int.Parse(mapping.Type);
                            switch (type)
                            {
                            case TargetValueType.Boolean:
                                targetValue = bool.Parse(node.InnerText);
                                break;

                            case TargetValueType.Choose:
                                targetValue = new ChooseValue(node.InnerText, string.Empty);
                                break;

                            case TargetValueType.DateTime:
                                targetValue = DateTime.Parse(node.InnerText);
                                break;

                            case TargetValueType.Decimal:
                                targetValue = decimal.Parse(node.InnerText);
                                break;

                            case TargetValueType.Text:
                                targetValue = node.InnerText;
                                break;

                            case TargetValueType.Picker:
                                targetValue = new ChooseValue(node.InnerText, string.Empty);
                                break;

                            default:
                                throw new ApplicationException($"An unknown '{nameof(TargetValueType)}' with id '{mapping.Type}' has been defined.");
                            }
                        }

                        newRow.Cells.GetByDbColumnName(mapping.TargetColumnName).SetValue(targetValue);
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException($"There was a problem parsing/setting value of node '{mapping.NodeName}' for xml row '{i}' to type '{mapping.Type}' for column '{mapping.TargetColumnName}' ", ex);
                    }
                }
            }
            logger.Outdent();
        }
        private void SaveAtt(CurrentDocumentData currentDocument, byte[] newAttContent)
        {
            var sourceAttData = currentDocument.GetFieldValue(Configuration.AttConfig.AttTechnicalFieldID).ToString();
            var sourceAtt     = currentDocument.Attachments.GetByID(Convert.ToInt32(sourceAttData));

            sourceAtt.Content  = newAttContent;
            sourceAtt.FileName = $"{Path.GetFileNameWithoutExtension(sourceAtt.FileName)}{Configuration.AttConfig.AttSufix}{sourceAtt.FileExtension}";

            if (!string.IsNullOrEmpty(Configuration.AttConfig.SaveCategory))
            {
                sourceAtt.FileGroup = new AttachmentsGroup(Configuration.AttConfig.SaveCategory, null);
            }

            DocumentAttachmentsManager.UpdateAttachment(new UpdateAttachmentParams()
            {
                Attachment = sourceAtt
            });
        }
예제 #4
0
        private void SaveAtt(CurrentDocumentData currentDocument, byte[] newAttContent)
        {
            if (newAttContent == null)
            {
                throw new Exception("API returned empty document content!");
            }

            int sourceAttData = Convert.ToInt32(currentDocument.GetFieldValue(Configuration.AttConfig.AttTechnicalFieldID));

            var sourceAtt = currentDocument.Attachments.GetByID(sourceAttData);

            sourceAtt.Content  = newAttContent;
            sourceAtt.FileName = $"{Path.GetFileNameWithoutExtension(sourceAtt.FileName)}{Configuration.AttConfig.AttSufix}{sourceAtt.FileExtension}";

            if (!string.IsNullOrEmpty(Configuration.AttConfig.SaveCategory))
            {
                sourceAtt.FileGroup = new WorkFlow.SDK.Documents.Model.Attachments.AttachmentsGroup(Configuration.AttConfig.SaveCategory, null);
            }

            DocumentAttachmentsManager.UpdateAttachment(new WorkFlow.SDK.Documents.Model.Attachments.UpdateAttachmentParams()
            {
                Attachment = sourceAtt
            });
        }