batchinterface.pas
来自「详细说明:毕业论文中关于小型宾馆管理系统的详细设计毕 业论文中关于小型宾馆...」· PAS 代码 · 共 331 行
PAS
331 行
//
// This unit contains the functions to allow the Framework and Fax Server to
// use the Application Servers batch interface. Think of it as accessing the
// batch functions of the Application Server as if they were the Cache Servers.
//
// (c) Chicony Software 2001
//
// When Who Why
// --------- --- ------------------------------------------------------------
// 2001.6.7 century Initial version
//
unit BatchInterface;
interface
uses classes, sysutils,
// Prexim modules
PreximV2Constants_TLB, PreximV2ApplicationServer_TLB, utils;
// Batch definition
type
PAppSvrBatch = ^AppSvrBatch;
AppSvrBatch = record
folder_id: String; // Folder ID
user_folder_id: String; // User folder ID
folder_owner: String; // Folder owner
folder_type: Integer; // Folder type
folder_priority: Integer; // Folder priority
transaction_id: String; // Transaction ID
transaction_owner: String; // Owner of transaction
transaction_type: Integer; // Transaction type
creator: String; // Batch creator
documents: TList; // Documents in the batch
end;
// Documents within batch definition
type
PBatchDoc = ^BatchDoc;
BatchDoc = record
document_id: String; // Document ID
document_type: Integer; // Document type
pages: TStringList; // Pages in the document
end;
TBatchIntf = class
private
// Properties
t_Batch: PAppSvrBatch;
public
function CreateBatch(const creator, folder_id, user_folder_id: String;
folder_type: Integer; const folder_owner: String; folder_priority: Integer;
const transaction_id: String; transaction_type: Integer; transaction_owner: String): Integer;
function AddDocument(const document_id: String; document_type: Integer): Integer;
function AddPage(filename: String): Integer;
function CommitBatch(appsvr: IPreximApplicationServer; var folder_id, transaction_id: String;
var document_ids: OleVariant; var errmsg: String): Integer;
function DeleteBatch: Integer;
constructor Create;
destructor Destroy; override;
end;
implementation
//=============================================================================
// Ensure data is initialised on creation
constructor TBatchIntf.Create;
begin
inherited Create;
t_Batch:=nil;
end;
// Free used memory when destroying
destructor TBatchIntf.Destroy;
begin
if t_Batch<>nil then DeleteBatch;
inherited Destroy;
end;
//
// Create a batch record
//
// Args: Prexim username of user creating the batch
//
// folder_id of folder this batch belongs to (empty string means unknown)
//
// user folder ID (ignored if folder_id is supplied - pass empty string
// if unknown)
//
// folder type (ignored if folder_id is supplied - pass 0 if type unknown)
//
// folder group owner (ignored if folder_id is supplied - pass empty
// string to use default)
//
// folder priority (1=highest, 10=lowest)
//
// transaction_id of transaction this batch belongs to (empty string
// means unknown)
//
// transaction type (ignored if transaction_id is supplied - pass 0
// if type unknown)
//
// transaction group owner (ignored if transaction_id is supplied - pass
// empty string to use default)
//
// Returns: GE_OK on success
// else error
//
// Note: Only one batch can be in definition at any one time. If there is an
// existing batch then this method is called then any existing batch
// is deleted
//
function TBatchIntf.CreateBatch(const creator, folder_id, user_folder_id: String;
folder_type: Integer; const folder_owner: String; folder_priority: Integer;
const transaction_id: String; transaction_type: Integer; transaction_owner: String): Integer;
begin
// Delete any existing batch
DeleteBatch;
// Create batch
try
New(t_Batch);
t_Batch^.creator:=creator;
t_Batch^.folder_id:=folder_id;
t_Batch^.user_folder_id:=user_folder_id;
t_Batch^.folder_type:=folder_type;
t_Batch^.folder_owner:=folder_owner;
t_Batch^.folder_priority:=folder_priority;
t_Batch^.transaction_id:=transaction_id;
t_Batch^.transaction_type:=transaction_type;
t_Batch^.transaction_owner:=transaction_owner;
t_Batch^.documents:=nil;
Result:= GE_OK;
except
if t_Batch<>nil then Dispose(t_Batch);
t_Batch:=nil;
Result:= Integer(GE_EXCEPTION);
end;
end;
//
// Add a document a batch
//
// Args: if the client needs to add pages to a specific document then they
// can pass the document_id. Generally an empty string must be passed
//
// document type (ignored if document_id supplied - pass 0 if unknown)
//
// Returns: GE_OK on success
// else error
//
function TBatchIntf.AddDocument(const document_id: String; document_type: Integer): Integer;
var new_doc: PBatchDoc;
begin
// Batch exists?
if t_batch=nil then begin
Result:= Integer(FWE_NO_BATCH_EXISTS);
Exit;
end;
// Has the documents list been created yet?
if t_batch^.documents=nil then t_batch^.documents:=TList.Create;
// Create batch document record
New(new_doc);
new_doc^.document_id:=document_id;
new_doc^.document_type:=document_type;
new_doc^.pages:=nil;
// Append new document to list
t_batch^.documents.Add(new_doc);
Result:=GE_OK;
end;
//
// Add a page to the last document in a batch
//
// Args: filename of page
//
// Returns: GE_OK on success
// else error
//
function TBatchIntf.AddPage(filename: String): Integer;
var last_doc: PBatchDoc;
begin
// Batch exists?
if t_batch=nil then begin
Result:= Integer(FWE_NO_BATCH_EXISTS);
Exit;
end;
// Are there any documents?
if (t_batch^.documents=nil) or (t_batch^.documents.Count < 1) then begin
Result:= Integer(FWE_NO_BATCH_DOCUMENTS);
Exit;
end;
// Get pointer to last document in batch
last_doc:=t_batch^.documents.Items[t_batch^.documents.Count - 1];
// Any pages yet?
if last_doc^.pages=nil then last_doc^.pages:=TStringList.Create;
// Append new page to list
last_doc^.pages.Add(filename);
Result:=GE_OK;
end;
//
// Commit a batch to the Application Server
//
// Args: application server pointer [IN]
// folder ID of batch [OUT]
// transaction ID of batch [OUT]
// document ID's in batch (one-dimensional var array) [OUT]
// error message [out]
//
// Returns: GE_OK on success
// else error
//
// NOTE: The batch will not be deleted. DeleteBatch must be called manually.
//
function TBatchIntf.CommitBatch(appsvr: IPreximApplicationServer; var folder_id, transaction_id: String;
var document_ids: OleVariant; var errmsg: String): Integer;
var documents, the_file: OleVariant;
doc, page: Integer;
cur_doc: PBatchDoc;
object_id, batch_folder_id, batch_transaction_id: WideString;
file_ext: String;
last_page: WordBool;
begin
// Valid pointer?
if t_batch=nil then begin
Result:= Integer(FWE_NO_BATCH_EXISTS);
Exit;
end;
// Any documents?
if t_Batch^.documents=nil then begin
Result:= Integer(FWE_NO_BATCH_DOCUMENTS);
errmsg:='There are no documents in the batch';
Exit;
end;
// Create a list of documents
documents:=VarArrayCreate([0, 1, 0, t_batch^.documents.Count - 1], varVariant);
for doc:=0 to t_batch^.documents.Count - 1 do begin
cur_doc:=t_batch^.documents[doc];
documents[0, doc]:=cur_doc^.document_id;
documents[1, doc]:=cur_doc^.document_type;
end;
// Call the Application Server and define the batch
Result:=appsvr.AD_BatchDefine(t_Batch^.creator, t_batch^.folder_id, t_batch^.user_folder_id,
t_batch^.folder_type, t_batch^.folder_owner, t_batch^.folder_priority,
t_batch^.transaction_id, t_batch^.transaction_type, t_batch^.transaction_owner,
documents);
if Result<>GE_OK then begin
errmsg:=appsvr.AS_LastError(Result);
Exit;
end;
// For each document...
for doc:=0 to t_batch^.documents.Count - 1 do begin
cur_doc:=t_batch^.documents[doc];
// For each page in the current document...
for page:=0 to cur_doc^.pages.Count - 1 do begin
// Get the file
the_file:=FileToVariant(cur_doc^.pages[page]);
file_ext:=ExtractFileExt(cur_doc^.pages[page]);
if page=cur_doc^.pages.Count - 1 then last_page:=TRUE else last_page:=FALSE;
// Add the page
Result:=appsvr.AD_BatchAddPage(the_file, file_ext, last_page, object_id);
if Result<>GE_OK then begin
// Failed
errmsg:=appsvr.AS_LastError(Result);
Exit;
end;
end;
end;
// Commit the batch
Result:=appsvr.AD_BatchCommit(batch_folder_id, batch_transaction_id, document_ids);
folder_id:=batch_folder_id;
transaction_id:=batch_transaction_id;
if Result<>GE_OK then errmsg:=appsvr.AS_LastError(Result);
end;
//
// Delete a batch
//
// Returns: 0 on success
// else error
//
function TBatchIntf.DeleteBatch: Integer;
var cur_doc: PBatchDoc;
begin
// Valid pointer?
if t_batch=nil then begin
Result:= 0;
Exit;
end;
// Free up memory
if t_batch^.documents<>nil then begin
// Free each document
while t_batch^.documents.Count > 0 do begin
// Free pages in the document
cur_doc:=t_batch^.documents.Items[0];
if cur_doc.pages<>nil then cur_doc.pages.Free;
// Free document
t_batch^.documents.Remove(cur_doc);
Dispose(cur_doc);
end;
// Free documents list
t_batch^.documents.Free;
t_batch^.documents:=nil;
end;
// Free memory
Dispose(t_batch);
t_batch:=nil;
Result:=0;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?