In Designer mode

 


Let us create a data processor that starts data exchange.

  1. In the configuration object tree, add a DataProcessor configuration object named DataExchange.
  2. On the Forms tab, create a default data processor form.
  3. In the form editor, on the Commands tab, create a form command named StartDataExchange.
  4. In the command property palette, in the Action field, click the Open  button.
  5. 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
  6. 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;
     
    EndProcedure
    The 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).
  7. 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

Comments
0
Add comment