从 ReleaseData.Values 获取值

Get Values from ReleaseData.Values

执行发布脚本的OpenScript 方法时,我想将索引字段、批处理字段和变量存储到列表中。我为此创建了一个片段

Dictionary<string, string> indexFields = new Dictionary<string, string>();
Dictionary<string, string> batchFields = new Dictionary<string, string>();
Dictionary<string, string> kofaxValues = new Dictionary<string, string>();

foreach (Value val in documentData.Values)
{
    if (val.TableName.IsEmpty())
    {
        string sourceName = val.SourceName;
        string sourceValue = val.Value;

        switch (val.SourceType)
        {
            case KfxLinkSourceType.KFX_REL_INDEXFIELD:
                indexFields.Add(sourceName, sourceValue);
                break;

            case KfxLinkSourceType.KFX_REL_VARIABLE:
                kofaxValues.Add(sourceName, sourceValue);
                break;

            case KfxLinkSourceType.KFX_REL_BATCHFIELD:
                batchFields.Add(sourceName, sourceValue);
                break;
        }
    }
}

我想这样做是因为我需要字段值。每个字段名称都是唯一的,因此我可以将其用作键。

将我的自定义属性存储到 ReleaseSetupData 时,我可以从 ReleaseData 中读取它们。假设两个自定义属性 return 字段名称和字段类型,所以我知道该字段是 IndexField 并且它的名称是 "MyIndexField".

我可以使用这些信息访问 Dictionary<string, string> indexFields 并从中获取值 Indexfield

目前我使用此代码

设置我的ReleaseSetupData
releaseSetupData.CustomProperties.RemoveAll();

// Save all custom properties here

releaseSetupData.CustomProperties.Add("myCustomProperty", "fooBar");

releaseSetupData.Links.RemoveAll();

foreach (IndexField indexField in releaseSetupData.IndexFields) // Save all IndexFields
{
    releaseSetupData.Links.Add(indexField.Name, KfxLinkSourceType.KFX_REL_INDEXFIELD, indexField.Name);
}

foreach (BatchField batchField in releaseSetupData.BatchFields) // Save all BatchFields
{
    releaseSetupData.Links.Add(batchField.Name, KfxLinkSourceType.KFX_REL_BATCHFIELD, batchField.Name);
}

foreach (dynamic batchVariable in releaseSetupData.BatchVariableNames) // Save all Variables
{
    releaseSetupData.Links.Add(batchVariable, KfxLinkSourceType.KFX_REL_VARIABLE, batchVariable);
}

当我的发布脚本的 OpenScript 方法被执行时,字典(如第一个片段所示)保持为空。这是因为 documentData.Values 是空的。

如何填写documentData.Values

你不能。事件顺序如下:

  1. OpenScript() 被调用 - 每批一次。
  2. ReleaseDoc() 被调用 - 每个文档一次
  3. CloseScript() 被调用 - 每批一次。

Values 集合包含特定于单个文档的信息,因此在 OpenScript() 期间将为空。有时这不是您想要的 - 您可能想要访问另一个文档的值,或者一次导出它们 - 例如在单个 Web 服务调用中。

以下是我的推荐:

为 Kofax 的 Document 对象创建包装器 class。这是我的方法(仅显示属性)。这个 class 有一个接受 ReleaseData 对象作为单个参数的构造函数,并且所有相应的属性都填充在所述构造函数中。

public class Document
  {
      public Dictionary<string, string> BatchFields { get; private set; }
      public Dictionary<string, string> IndexFields { get; private set; }
      public Dictionary<string,string> KofaxValues { get; set; }
      public Dictionary<string, string> TextConstants { get; set; }
      public Dictionary<string, string> CustomProperties { get; private set; }
      public Dictionary<string,string> ConfigurationSettings { get; set; }
      public List<Table> Tables { get; private set; }
      private List<Column> Columns;
      public List<string> ImageFileNames { get; private set; }
      public string KofaxPDFFileName { get; private set; }
      public string XdcFilePath { get; private set; }
      public XDocument XDocument { get; private set; }
      public string ImageFilePath { get; private set; }
      public string KofaxPDFPath { get; private set; }
      public string TextFilePath { get; private set; }
      public byte[] BinaryImage { get; private set; }
      public char CellSeparator { get; set; }
}

然后,在 ReleaseDoc() 期间,我会将我所有的 Documents 添加到一个集合中。请注意,连接 documents 在您的 ReleaseScript:

中定义为私有
public KfxReturnValue ReleaseDoc()
{
  documents.Add(new Document(DocumentData));
}

然后您可以决定何时何地导出数据。它也可能在 CloseScript() 事件期间发生,但请记住,必须在 ReleaseDoc() 期间抛出完整性检查和与文档数据相关的潜在异常(无效的索引字段值等)。使用自定义包装器 class 和集合为您的导出连接器增加了许多 .NET 原生的灵活性和功能,例如 LINQ - 这是一个示例(这对于 Kofax 的 COM 对象是不可能的):

var noPdfs = documents.Where(x => x.KofaxPDFPath.Length == 0);