Compartilhar via


Determining where code is running

As you are developing a Visual Studio Tools integration that will be used with the Microsoft Dynamics GP web client, you will encounter cases where you will want one block of code to run on the desktop client and a different block of code to run on the web client. Use the DexRuntimeGetClientType() helper function to do this.

Hint: If you will be calling DexRuntimeGetClientType() frequently, consider calling it one time in the Initialize method for your add-in, and then storing the result in a variable. This is more efficient, and simplifies the code in your add-in.

As an example, the technique to display online help is different on the desktop client and the web client. On the desktop client, an integrating application can make a direct call to the HTML Help engine in Windows. But HTML Help isn't available on the web client, so a different technique must be used. The following C# example shows the code that runs when the user clicks the Help button in the form for the Estimate Freight sample. The client type is determined, and the appropriate help processing code is run.

private void buttonHelp_Click(object sender, EventArgs e)
{
    // Help is processed differently, depending on whether it is being
    // accessed from the desktop client or the web client.

    if (Dynamics.Forms.SyVisualStudioHelper.Functions.
    DexRuntimeGetClientType.Invoke() == 1)
    {
        // Desktop client
        // Display a help file for this window
        Help.ShowHelp(this, "EstimateFreight.chm");
    }

    if (Dynamics.Forms.SyVisualStudioHelper.Functions.
    DexRuntimeGetClientType.Invoke() == 2)
    {
        // Web client
        // Is a different web client help server being used?
        string server = Dynamics.Forms.SyVisualStudioHelper.Functions.
        DexDefaultsRead.Invoke("WebClientHelpServer",2);

        // Help folder
        string helpFolder = "Help";

        // File to access
        string helpFile = "EstimateFreight.htm";

        // Full URL to access
        string url = server + "/" + helpFolder + "/" + helpFile;

        // Launch the help
        Dynamics.Forms.SyVisualStudioHelper.Functions.DexWinHelpLaunchUrl.
        Invoke(url);
    }
}