Compartilhar via


Session recovery

When a Microsoft Dynamics GP web client session is disconnected, the session remains active on the server. The user can reconnect to the session and restore the condition of the windows that were open. As part of the session restore process, the Recover() method for your Visual Studio Tools add-in on the server is called. We recommend that you implement the Recover() method so that your Visual Studio Tools integration participates in the restore action.

The code that you include in the Recover() method must send messages to the Silverlight application running on the web client to restore the application state so that it matches the condition of the add-in on the server. When restoring the application on the web client, consider things like the following:

  • Which Silverlight windows are open for your integration
  • Whether the Silverlight window are visible or hidden
  • What data values appear in the controls in each window
  • Have specific selections been made in any of the controls in each window

In most cases, you will need to implement specific messages that are used only for the Recover() method. For example, in the normal course of development, you will implement messages that send user selections and input from the Silverlight application on the web client to the Visual Studio Tools add-in on the server. This seems logical, because the user is providing input on the web client that needs to be transferred to the server. When a restore action is performed, these same values must be sent from the Visual Studio Tools add-in on the server to the Silverlight application on the web client. That's why additional messages are required.

The following C# example is the Recover() method for the Salesperson Analysis sample add-in that runs on the server. Four messages are used to restore the state of the Silverlight application on the web client. The first message opens the Salesperson Analysis form. The second message reloads the data for the window. The third message sets the selection in the data grid. The fourth message displays the window if it had previously been visible.

public void Recover()
{
    // Code for recovering a session

    // Is the Salesperson Maintenance form open?
    if (SalespersonMaintenanceForm.IsOpen == true)
    {
        // Open the Salesperson Analysis form
        proxy.SendMessage(new WCVstCustomMessage(this.GetType().FullName,
        "SalespersonAnalysisSL.GPWCAddIn", "OpenSalespersonAnalysisForm",
        new byte[0]));

        // Load the data
        SalespersonId_Change(null, null);

        // Set the selection, if there is one.
        if(GPAddIn.SalespersonAnalysisForm.customerListView.
        SelectedIndices.Count != 0)
        {
            // Get the first item in the list, since this is a single-select
            // list view
            int selection = GPAddIn.SalespersonAnalysisForm.customerListView.
            SelectedIndices[0];

            // Convert the string value to encoded bytes to send
            byte[] bytedata;
            System.Text.UTF8Encoding val = new UTF8Encoding();
            bytedata = val.GetBytes(selection.ToString());

            // Send the selection
            proxy.SendMessage(new WCVstCustomMessage(this.GetType().FullName,
            "SalespersonAnalysisSL.GPWCAddIn", "SetCustomerSelection",
            bytedata));
        }

        // Show the form?
        if (GPAddIn.SalespersonAnalysisForm.Visible == true)
        {
            proxy.SendMessage(new WCVstCustomMessage("SalespersonAnalysis.
            GPAddIn","SalespersonAnalysisSL.GPWCAddIn",
            "ShowSalespersonAnalysisForm", new byte[0]));
        }
    }
}