home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / BTF521-3.ZIP / NETWARE.LZH / TESTQUE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-02-08  |  5.1 KB  |  161 lines

  1. {
  2.   TESTQUE - Program to test NetWare QMS functions
  3.             by Richard S. Sadowsky
  4.  
  5.   This program creates a queue called RICH_Q. It then deletes the Q_USERS
  6.   property which means any logged user may use the queue. Then it adds the
  7.   name of the user logged into the calling workstation as a Q_SERVER (means
  8.   that user can service the queue). Then a queue job and file are created, and
  9.   some dummy data written to the file. The queue job and file are close. The
  10.   user is then prompted, if Esc is pressed, the queue is destroyed, otherwise
  11.   it remains in place. If the queue is left in place, then TESTQUE2 and
  12.   TESTQUE3 can be run.
  13.  
  14.   Note: this program uses drive J for the server, if this isn't right, you'll
  15.   need to change the constant ServerDrive to the appropriate letter.
  16. }
  17. {$S-,R-,I-}
  18. program TestQue;
  19.  
  20. uses
  21.   OpString,
  22.   OpCrt,
  23.   NetWare,
  24.   NetBind,
  25.   NetQue;
  26.  
  27. procedure Abort(S : String);
  28. begin
  29.   WriteLn(S);
  30.   Halt;
  31. end;
  32.  
  33. type
  34.   StringPtr = ^String;
  35.  
  36. const
  37.   ServerDrive = 'J';   {****change to appropriate drive letter}
  38.   AnyServer : LongInt = -1;
  39.   TextJobStr : String[15] = 'to satisfy Rich';
  40.   ClientRecStr : String[30] = 'this is the client record area';
  41.   FileStr : String[27]      = 'text added to the job queue';
  42.   OurQueName = 'RICH_Q';
  43.   QueCreated : Boolean = False;
  44.  
  45. var
  46.   QueueID : LongInt;
  47.   DirHandle, Result, Flags : Byte;
  48.   JobEntry, ReplyEntry : JobEntryType;
  49.   ConnInfo : ConnInfoType;
  50.   ListOfJobs : QueueJobList;
  51.   I : Word;
  52.   S : String;
  53.   F : File;
  54.   SaveExitProc : Pointer;
  55.  
  56.   {$F+}
  57.   procedure OurExitProc;
  58.   begin
  59.     ExitProc := SaveExitProc;
  60.     if QueCreated then begin
  61.       {destroy the queue in the event of abnormal termination}
  62.       Result := DestroyQueue(QueueID);
  63.       if Result <> 0 then
  64.         WriteLn('Error ' + HexB(Result) + ' on DestroyQueue');
  65.     end;
  66.   end;
  67.  
  68.   procedure DumpJob(JobNo : Word);
  69.   begin
  70.     FillChar(ReplyEntry, SizeOf(ReplyEntry), 0);
  71.  
  72.     {read the queue job}
  73.     Result := ReadJobEntry(QueueID, JobNo, ReplyEntry);
  74.     if Result = 0 then begin
  75.       {display info from this job}
  76.       Move(ReplyEntry.TextJobDesc,S[1], SizeOf(TextJobField));
  77.       S[0] := Char(SizeOf(TextJobField));
  78.       WriteLn(S);
  79.       WriteLn(StringPtr(@ReplyEntry.ClientRecord)^);
  80.     end
  81.     else
  82.       WriteLn('Error ' + HexB(Result) + ' on ReadJobEntry for job ', JobNo);
  83.   end;
  84.  
  85. begin
  86.   SaveExitProc := ExitProc;
  87.   ExitProc := @OurExitProc;
  88.   {get directory handle of server}
  89.   DirHandle := GetDirHandle(ServerDrive, Flags);
  90.   if DirHandle = 0 then Abort('Error getting Directory handle');
  91.  
  92.   {create the queue}
  93.   Result := CreateQueue(bindJobQueue, OurQueName, DirHandle, '', QueueID);
  94.   if Result <> 0 then Abort('Error ' + HexB(Result) + ' creating queue');
  95.   QueCreated := True;
  96.  
  97.   {delete the Q_USERS property so anyone can use the queue}
  98.   Result := DeleteProperty(bindJobQueue, OurQueName, 'Q_USERS');
  99.   if Result <> 0 then Abort('Error ' + HexB(Result) + ' deleting propery');
  100.  
  101.   {get name of use logged onto this workstation}
  102.   GetConnInfo(GetConnNo, ConnInfo);
  103.  
  104.   {add user at this station to list of Q_SERVERS}
  105.   Result := AddObjectToSet(bindJobQueue, 'RICH_Q', 'Q_SERVERS',
  106.                            bindUser, ConnInfo.ObjectName);
  107.   if Result <> 0 then Abort('Error ' + HexB(Result) + ' adding to Q_SERVERS');
  108.  
  109.   {initialize the JobEntry record}
  110.   FillChar(JobEntry, SizeOf(JobEntry), 0);
  111.   with JobEntry do begin
  112.     TargetServerID   := AnyServer;
  113.     TargetExecTime   := FirstOpportunity;
  114.     JobType          := 1;
  115.     JobControlFlags  := 0;
  116.     Move(TextJobStr[1], TextJobDesc, Length(TextJobStr));
  117.     Move(ClientRecStr, ClientRecord, Length(ClientRecStr) + 1);
  118.   end;
  119.  
  120.   {create a queue job}
  121.   Result := CreateQueueJobAndFile(QueueID, JobEntry, ReplyEntry);
  122.   if Result <> 0 then
  123.     Abort('Error ' + HexB(Result) + ' on CreateQueueJobAndHandle');
  124.  
  125.   {now write to the newly created queue job file}
  126.   Assign(F, 'NETQ');
  127.   Reset(F, 1);
  128.   if IoResult <> 0 then Abort('Error opening NETQ');
  129.   BlockWrite(F, FileStr, SizeOf(FileStr));
  130.   if IoResult <> 0 then Abort('Error writing NETQ');
  131.  
  132.   {get list of jobs in queue}
  133.   Result := GetQueueJobList(QueueID, ListOfJobs);
  134.   {if successful, dump each job}
  135.   if Result = 0 then
  136.     for I := 1 to ListOfJobs.NumJobs do
  137.       DumpJob(ListOfJobs.JobList[I])
  138.   else
  139.     WriteLn('Error ' + HexB(Result) + ' on GetQueueJobList');
  140.  
  141.   {close the DOS handle associated with job file}
  142.   Close(F);
  143.   if IoResult <> 0 then Abort('Error closing NETQ');
  144.  
  145.   {close the NetWare job file and submit the job to the queue for processing}
  146.   Result := CloseFileAndStartJob(QueueID, ListOfJobs.JobList[1]);
  147.   if Result <> 0 then Abort('Error ' + HexB(Result) + ' closing job');
  148.  
  149.   {ask user to press ESC to destroy queue, or exit with queue in place}
  150.   WriteLn('Press escape to destroy queue or any other key to leave queue in place');
  151.   if ReadKey <> ^[ then begin
  152.     QueCreated := False;
  153.     Halt;
  154.   end;
  155.  
  156.   {destroy the queue}
  157.   Result := DestroyQueue(QueueID);
  158.   if Result <> 0 then
  159.     Abort('Error ' + HexB(Result) + ' on DestroyQueue');
  160. end.
  161.