Module Batchdd.pkg
1//************************************************************************
2//
3// Confidential Trade Secret.
4// Copyright 1987-1997 Data Access Corporation, Miami FL, USA
5// All Rights reserved
6// DataFlex is a registered trademark of Data Access Corporation.
7//
8//****************************************************************************//
9// //
10// $File name : BatchDD.pkg //
11// $File title : BusinessProcess class (batch processing) //
12// Notice : //
13// $Author(s) : John Tuohy //
14// //
15// $Rev History //
16// //
17// MG 10/2/98 Changed error_report with additional parameter //
18// JT 9/30/97 Set Focus_mode to no_activate to keep out of F-tree // //
19// JT 9/22/97 Added status_params property and support. //
20// JT 06/29/97 File created //
21//****************************************************************************//
22// //
23Use LanguageText.pkg
24Use Windows.pkg
25
26#IFNDEF IS$WebApp
27Use StatPnl.pkg // creates object Status_Panel... only if non webapp
28#ENDIF
29
30Use MsgBox.pkg
31Use GlobalFunctionsProcedures.pkg
32
33{ ClassLibrary=Common }
34{ DDOHost=True }
35{ ComponentType=BPClass }
36{ HelpTopic=BusinessProcess }
37// Do this so the metadata is correct for windows apps, which
38// means it will be wrong for WebApps.
39{ OverrideProperty = Status_Panel_State InitialValue = True }
40Class BusinessProcess is a cObject
41
42 Procedure Construct_Object
43 Forward Send Construct_Object
44
45 // Status Panel related properties
46 { Category=Behavior }
47 { PropertyType=Boolean }
48 Property Integer Status_Panel_State True
49 { Category=Behavior }
50 { PropertyType=Boolean }
51 Property Integer Allow_Cancel_State False
52 Property String Process_Caption C_$RunningProcess
53 Property String Process_Title ""
54 Property String Process_Message ""
55
56 { Visibility=Private }
57 Property Integer Status_Panel_Id 0
58 Property String Status_Params ''
59
60 #IFDEF IS$WebApp
61 // if web app, we really don't want a status panel
62 // even if you turn status_panel_state on, the status_panel_id object will be set
63 // to 0, so it will not talk to it.
64 Set Status_Panel_State to False
65 #ELSE
66 // if not web app, we want a normal status_panel object
67 Set Status_Panel_Id to (Status_Panel(Self))
68 #ENDIF
69 // Error related properties
70
71 // if set true, errors will be forwarded to the normal
72 // VDF error handler causing an error message to popup.
73 // Normally you would not want this during a batch process.
74
75 { PropertyType=Boolean }
76 Property Integer Display_Error_State False
77
78 { DesignTime=False }
79 Property Integer Error_Count 0 // number of errors
80
81 { Visibility=Private }
82 Property Integer Old_Error_Object_Id 0
83
84 { Visibility=Private }
85 Property integer Error_Processing_State False // internal use
86
87 { Visibility=Private }
88 Property Integer Error_Check_State False // internal
89
90 // Logging
91 { PropertyType=Boolean }
92 Property Integer Status_Log_State False
93
94 // If you are going to log information you must create a
95 // status log object and set this property to its ID. See
96 // Statlog.pkg for more information.
97 Property Integer Status_Log_Id 0
98
99 // This is normally not used at runtime by BPOs but it is required
100 // by the IDE to figure out how to structure and relate DDOs
101 { DesignTime=False }
102 Property handle Main_DD 0
103
104 End_Procedure
105
106 //------------------------------------------------------------------------
107 // Status Panel related Messages
108 // Send Start_Status
109 // Send Resume_Status
110 // Send End_Status
111 // Send Update_Status StatusString
112 //------------------------------------------------------------------------
113
114 Procedure Update_Status string Val
115 Integer StatPnl
116 Get Status_Panel_Id to StatPnl
117 If StatPnl ;
118 Send Update_StatusPanel to StatPnl Val
119 End_Procedure
120
121 { Visibility=Private }
122 Procedure Start_Status
123 Integer StatPnl
124 Set Error_Check_State to False
125 If (Status_Panel_State(self)) Begin
126 Get Status_Panel_Id to StatPnl
127 If StatPnl Begin
128 Send Initialize_StatusPanel to StatPnl ;
129 (Process_Caption(Self)) ;
130 (Process_Title(Self)) ;
131 (Process_Message(Self)) ;
132 (Status_Params(Self))
133 Set Allow_Cancel_State of StatPnl to (Allow_Cancel_State(Self))
134 Send Start_StatusPanel to StatPnl
135 End
136 End
137 End_Procedure
138
139 Procedure Resume_Status
140 Integer StatPnl
141 Get Status_Panel_Id to StatPnl
142 If StatPnl ;
143 Send Start_StatusPanel to StatPnl
144 End_Procedure
145
146 Procedure End_Status
147 Integer StatPnl
148 Get Status_Panel_Id to StatPnl
149 If StatPnl ;
150 Send Stop_StatusPanel to StatPnl
151 End_Procedure
152
153 //------------------------------------------------------------------------
154 // Status Logging related Messages
155 // Send Start_log
156 // Send End_Log
157 // Send Error_Log_Status Error_Info Error_Mess
158 // Send Log_Status StatusString
159 //------------------------------------------------------------------------
160
161 Procedure Start_Log
162 Send Log_Status (SFormat(C_$BeginProcess, Process_Title(self)))
163 End_Procedure
164
165 Procedure End_Log
166 Integer ErrCount
167 Get Error_Count to ErrCount
168 Send Log_Status (SFormat(C_$EndProcessNumberOfErrors, Process_Title(self), ErrCount))
169 End_Procedure
170
171 Procedure Error_Log_Status integer Errnum integer iErrLine string ErrMsg
172 Send Log_Status (SFormat(C_$ErrorNum, ErrNum, ErrMsg))
173 End_Procedure
174
175 Procedure Log_Status String Mess
176 integer StatId
177 Get Status_Log_Id to StatId
178 If StatId ;
179 Send Log_Status to StatId Mess
180 End_Procedure
181
182 //------------------------------------------------------------------------
183 // Error and process interupt related Messagss
184 // Function Process_Interrupt Returns integer
185 // Get Cancel_Check to bShouldStop
186 // Procedure Error_Report integer Error_Info String ErrorMess
187 // Procedure onError integer Error_info string ErrorMess
188 //------------------------------------------------------------------------
189
190 // This pops up a message asking if a process should
191 // be canceled. Returns non-zero if cancel. This could be
192 // augmented, should not be sent.
193
194 { MethodType=Event }
195 Function Process_Interrupt Returns Integer
196 Integer rVal
197 String Mess
198 If (Error_Check_State(Self)) ;
199 Move C_$AnErrorWasEncountered to Mess
200 Else ;
201 Move C_$DoYouWishToCancelThisProcess to Mess
202 Get YesNo_Box Mess C_$ProcessInterrupt to rVal
203 Function_Return (Rval=MBR_YES)
204 End_Function
205
206 // Public way to tell if a process should be canceled.
207 // This should be sent but probably not augmented
208 // check for report interrupt
209 // Returns True to stop report, false to continue
210
211 Function Cancel_Check Returns Integer
212 Integer StatPnl StopIt
213 Get Status_Panel_Id to StatPnl
214 If ( Error_Check_State(self) OR ;
215 ( Status_Panel_State(self) AND ;
216 StatPnl AND Check_StatusPanel(StatPnl))) Begin
217 Send End_Status
218 Get Process_Interrupt to StopIt
219 If Not StopIt ;
220 Send Resume_Status
221 Set Error_Check_State to False
222 End
223 Function_Return StopIt
224 End_Function
225
226 // All errors are directed to the main report. By Default we
227 // shut off the status panel, report the error and notify the interrupt
228 // mechanism to ask if the report should be canceled. VERY IMPORTANT!
229 // If you augment this and you plan on doing ANY windows IO you should
230 // first shut of the status panel.
231
232 { MethodType=Event Visibility=Private }
233 Procedure Error_Report integer ErrNum integer iErrLine string ErrMsg
234 Integer id
235 If (error_processing_state(self)=False) Begin
236 Set Error_processing_State to True // prevents recursion
237 Set Error_Check_State to TRUE
238 Set Error_Count to (Error_Count(self)+1)
239 If (Status_Log_State(self)) ;
240 Send Error_Log_Status ErrNum iErrLine ErrMsg
241 If (Display_Error_State(self)) Begin
242 Get Old_Error_Object_Id to ID
243 Send End_Status // YOU MUST DO THIS!!!!
244 If ID ;
245 Send Error_Report to Id ErrNum iErrLine ErrMsg
246 Else ;
247 send Error_Report of desktop ErrNum iErrLine ErrMsg
248 //Forward send Error_Report ErrNum iErrLine ErrMsg
249 End
250 Send onError ErrNum iErrLine ErrMsg
251 Set Error_processing_State to False
252 End
253 End_procedure
254
255 // Event called by Error_Report. For augmentation.
256 // If you are planning on doing any interactive IO and you are
257 // using the status panel you must first remove the panel
258 // (send End_Status).
259
260 { MethodType=Event }
261 Procedure OnError integer ErrNum integer iErrLine string ErrMsg
262 End_procedure
263
264
265 //------------------------------------------------------------------------
266 // Process related Messages
267 // Send Start_Process
268 // Send onProcess
269 // Send End_Process
270 // Send DoProcess
271 //------------------------------------------------------------------------
272
273 Procedure Start_Process
274 Set Error_Count to 0
275 Set Old_Error_Object_id to Error_Object_id
276 Move self to Error_Object_id
277 If (Status_Log_State(self)) ;
278 Send Start_Log
279 Send Start_Status
280 End_Function
281
282 Procedure End_Process
283 Send End_Status
284 If (Status_Log_State(self)) ;
285 Send End_Log
286 Get Old_Error_Object_id to Error_Object_id // restore previous error object
287 Set Old_Error_Object_id to 0
288 End_Procedure
289
290 // This runs the actual busiess process. It is expected that most
291 // if not all of the custom code to run a process will be provided
292 // here.
293
294 { MethodType=Event }
295 Procedure OnProcess
296 End_Procedure // OnProcess
297
298 // This procedure is the main public access method into this
299 // object. A process is run by sending this message. It will start
300 // the process, call a user defined Hook (event) to actually do
301 // the processing, and then end the process.
302
303 Procedure DoProcess
304 Send Start_Process // does all process init
305 Send OnProcess // must be provided by the programmer
306 Send End_Process // does all close down
307 End_Procedure // DoProcess
308
309End_Class
310