Let us create a data processor that starts data exchange.
- In the configuration object tree, add a DataProcessor configuration object named DataExchange.
- On the Forms tab, create a default data processor form.
- In the form editor, on the Commands tab, create a form command named StartDataExchange.
- In the command property palette, in the Action field, click the Open button.
- In the dialog box that prompts you to select handler type, click Create on client and a procedure on server (no context).
This creates two procedures in the form module: a client StartDataExchange() procedure and a server out-of-context StartDataExchangeAtServer procedure, which is called from the client procedure.
The StartDataExchange() procedure has the following text (listing 24.9).
Listing 24.9. StartDataExchange() command handler
&AtClient Procedure StartDataExchange(Command) StartDataExchangeAtServer(); EndProcedure
- Add the following script to the StartDataExchangeAtServer procedure (listing 24.10).
Listing 24.10. Creating the StartDataExchangeAtServer procedure
&AtServerNoContext Procedure StartDataExchangeAtServer() Export NodeSelection = ExchangePlans.Branches.Select(); While NodeSelection.Next() Do // Exchanging data with all nodes, except for the current node (ThisNode) If NodeSelection.Ref <> ExchangePlans.Branches.ThisNode() Then NodeObject = NodeSelection.GetObject(); // Receiving message NodeObject.ReadMessageWithChanges(); // Generating message NodeObject.WriteMessageWithChanges(); EndIf; EndDo; EndProcedureThe procedure has the following algorithm: in the loop it iterates through the nodes of the Branches exchange plan, and for all the nodes except the local node it first reads the messages received from other exchange nodes (you will create the ReadMessagesWithChanges procedure later).
Next it generates the messages to be sent that contain the modified data for this node (you will create the WriteMessagesWithChanges procedure later).
- Drag the StartDataExchange command from the Commands tab to the form controls pane.
The resulting data processor form should look as follows (fig. 24.6).
Fig. 24.6. Data processor form