手動処理の例

この例では、手動データ処理の追加段階を作成する方法を示します。例えば、御社のセキュリティ部門がこの段階を使うことができます。セキュリティ部門は、特定の条件を満たす文書を確認してさらなる処理に送ることを許し、条件を満たさない文書を拒否することができます。

すべての確認済み文書には、デジタル署名を模倣したバイトのセットが付いています。

以下よりプロジェクトと資料をダウンロードすることができます:UserStage.zip

コード例は以下のステップを実行します:

  • 接続を設定します
  • プロジェクトの作業を始めます
  • タスクのリストを取得して処理します
  • 各タスクをサービス段階で処理します
  • ファイルをサーバーにアップロードします
  • セッションを閉じます

この例で処理するには:

Visual Studio 2013以降のバージョンでUserStageExample.sln を始めます:

1. アプリケーションサーバーのURLを入力します。

2. 認証型を選択します。

3. ログインをクリックします。

接続の設定

private const string FlexiHandlerPath = "/FlexiCapture12/Server/{0}API/v1/Soap"; // FlexiCapture APIへのパス
private const string FlexiCaptureAuthPart = "FCAuth/"; // FlexiCapture認証へのパス
private const string UserStageProjectName = "UserStageExample"; // この例で使用されるプロジェクト名
private const string UserStageName = "Service"; // サービス段階名

// 新規拘束の作成
var binding = new BasicHttpBinding();

// FlexiCaptureではメッセージのサイズが小さすぎますので増大させる必要があります
binding.MaxReceivedMessageSize = MessageSize;

// プロトコルに依存する新規接続セキュリティモードの選択
binding.Security.Mode = serverUri.Scheme == Uri.UriSchemeHttps
  ? BasicHttpSecurityMode.Transport
  : BasicHttpSecurityMode.TransportCredentialOnly;

// 認証方法の選択
binding.Security.Transport.ClientCredentialType = windowsAuth
  ? HttpClientCredentialType.Windows
  : HttpClientCredentialType.Basic;

// 認証方法に依存するAPIへのパスの選択
var externalSuffix = windowsAuth ? string.Empty : FlexiCaptureAuthPart;
var remoteAddress = new EndpointAddress(new Uri(serverUri, string.Format(FlexiHandlerPath, externalSuffix)));

// SOAPクライアントの作成
_client = new FlexiCapture.FlexiCaptureWebServiceSoapClient(binding, remoteAddress);

// FlexiCaptureを認証するには、ログインとパスワードを指定します
if (_client.ClientCredentials != null && !windowsAuth)
{
  _client.ClientCredentials.UserName.UserName = login;
  _client.ClientCredentials.UserName.Password = password;
}

プロジェクトの操作の開始

// セッションを開きます
_sessionId = _client.OpenSession(RoleType, WorkstationType);
var projectGuid = string.Empty;

// 必要なプロジェクトを検索します
foreach (var project in _client.GetProjects())
{
  if (project.Name == UserStageProjectName)
  {
     projectGuid = project.Guid;
  }
}
if (string.IsNullOrEmpty(projectGuid))
{
  MessageBox.Show("この例に必要なUserStageExampleプロジェクトがサーバーに含まれていません");
}

// プロジェクトを開きます
_projectId = _client.OpenProject(_sessionId, projectGuid);

// サービス段階識別子を検索して保存します
var stages = _client.GetProcessingStages(_projectId, 0, 0, UserStageName);
if (stages.Count != 1) throw new Exception("Invalid project");
  _serviceStageId = stages[0].Id;

// 除外段階の外部IDを検索して保存します
stages = _client.GetProcessingStages(_projectId, 0, ExceptionStageType, string.Empty);
if (stages.Count != 1) throw new Exception("Invalid project");
  _exceptionsStageId = stages[0].ExternalId;

サービス段階で保留中のタスクのリストの取得と処理

// タスク一覧の取得
var tasks = _client.GetAvailableTasksByStageId(_sessionId, _projectId,
new FlexiCapture.stageIds() { _serviceStageId }, false);
var result = new Dictionary<int, Task>();
if (tasks == null || tasks.Count == 0) return result;
foreach (var task in tasks)
{
  // 各タスクにそのタスクタイプのオブジェクトが作成されます
  var item = new Task
  {
     Id = task.Id,
     BatchId = task.BatchId
  };
  // タスクのドキュメント一覧の取得
  var documents = _client.GetTaskDocuments(task.Id);
  if (documents == null || documents.Count == 0) continue;
  foreach (var document in documents)
  {
     // タスクのXMLのロード
     var file = _client.LoadDocumentResult(_sessionId, document.BatchId, document.Id, "DocumentBody"); // "DocumentBody" - the name of the file that contains recognized data
     if (file == null || file.Bytes == null) continue;
     // XMLのディスアセンブル
     var doc = new Document(document.Id, XDocument.Load(new MemoryStream(file.Bytes)));
     // ドキュメントのディスアセンブル済みリストの保存
     item.Documents.Add(document.Id, doc);
  }
  result.Add(item.Id, item);
}

さらなる処理のためのタスクの送信

var ids = new FlexiCapture.docIds();
foreach (var rejectedDocument in rejectedDocuments)
{
  ids.Add(rejectedDocument.Id);
}
if (ids.Count > 0)
{
  _client.CreateTask(_sessionId, batchId, _exceptionsStageId, 0, "Rejection reason", 0, ids, false);
}
_client.OpenBatch(_sessionId, batchId);
var hasDocuments = false;
try
{
  var uri = _client.Endpoint.Address.Uri.OriginalString.Replace("/API/v1/Soap", "/FileService/v1");
  foreach (var document in acceptedDocuments)
  {
     hasDocuments = true;
     var buffer = new byte[SignatureSize]; // 文書に追加されたデジタル署名のサイズ:1024
     _rng.GetBytes(buffer);
     //DocumentAttachment:添付タイプ(9 - 文書添付)
     _client.SaveAttachment(_sessionId, DocumentAttachment, document.Id, batchId, _projectId, new FlexiCapture.File
     {
        Bytes = buffer,
        Name = "Signature.dat"
     });
     document.CreateStamp();
     UploadTextFileToServer(new Uri(uri),
        _client.ClientCredentials.UserName.UserName,
        _client.ClientCredentials.UserName.Password,
        document.GetXml(), 0, _sessionId, _projectId,
        batchId, 0, document.Id, 0, "DocumentBody"
     ).Wait();
  }
};

ファイルをサーバーにアップロード

セッションを閉じる

  _client.CloseProject(_sessionId, _projectId);
  _client.CloseSession(_sessionId);

25.05.2023 7:55:10

Please leave your feedback about this article

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.