Configuring the Connection Monitor Application Block

Configuring the Connection Monitor Application Block

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
To create client business applications using current Microsoft technologies, see patterns & practices' Prism.

To use the Connection Manager Application Block, you must add configuration information to the application configuration file. This configuration information defines the logical networks and physical network adapters that you want to monitor. With the following configuration section example, the application block will monitor connection to two logical networks and one physical network adapter.

<ConnectionMonitor>
  <Networks>
    <add Name="Intranet" Address="http://contoso"/>
    <add Name="Internet" Address="http://www.microsoft.com"/>
  </Networks>
<Connections>
    <add Type="WiredConnection" Price="1"/>
  </Connections>
</ConnectionMonitor> 

The application block defines the following values that you can use for the Type attribute of the physical network adapter configuration information:

  • NicConnection. The application block uses the NicConnection class to monitor any network interface connection: for example, an Ethernet card or wireless adapter. This class provides the capability to detect if the application has a connection to a network.
  • WiredConnection. The application block uses the WiredConnection class to monitor connectivity to Ethernet adapters.
  • WirelessConnection. The application block uses the WirelessConnection class to monitor connectivity to wireless network adapters.
  • DesktopConnection. The application block uses the DesktopConnection class to monitor connectivity to local services (you can manually set the connection state of this class).

In addition, you can specify a fully-qualified type name as the value for the Type attribute. This means you can use your own implementation to determine connection status for an adapter.

If the connection price is not relevant to your application, you can set the connection price to 0.

The following procedure describes how to configure the Connection Monitor Application Block for use in a smart client application.

To configure the Connection Monitor Application Block

  1. Define a configuration section for the application block in the application configuration file. To do this, add a <section> node to the <configSections> node of your App.config file, as shown in the following XML.
    <configSections>
      <section name="ConnectionMonitor" type="Microsoft.Practices.SmartClient.ConnectionMonitor.Configuration.ConnectionSettingsSection, Microsoft.Practices.SmartClient.ConnectionMonitor" />
    </configSections>
    
    Ff699226.note(en-us,PandP.10).gifNote:
    You can specify any name for the configuration section. However, if you use a name other than "ConnectionMonitor," you must specify that section name when you instantiate the connection monitor service in your application code.

  2. Create the application block configuration section and define your logical networks. Configure each logical network inside a <Networks> node using an <add> element, as shown in the following XML. If you do not specify a connection type the ConnectionMonitorFactory will use a NicConnection (this type monitors any type of connection).
    <ConnectionMonitor>
      <Networks>
        <add Name="Intranet" Address="http://intranet"/>
        <add Name="Internet" Address="http://www.microsoft.com"/>
      </Networks>
    </ConnectionMonitor> 
    
  3. If you want to monitor physical network adapters, add the configuration information for the network adapters inside a <Connections> element, as shown in the following XML.
    <ConnectionMonitor>
      <Connections>
        <add Type="WiredConnection" Price="1"/>
        <add Type="WirelessConnection" Price="2"/>
      </Connections>
    </ConnectionMonitor> 
    
  4. Optionally, specify the type name of the network status strategy to use to monitor the connection status of the logical network. To do this, add the StrategyType attribute to the <Networks> node. A network status strategy is a concrete implementation of the INetworkStatusStrategy interface. If you do not add the StrategyType attribute, the application block will use the type HttpPingStatusStrategy.
    <ConnectionMonitor>
      <Networks StrategyType="ConnectionModule.CustomNetworkStatusStrategy, ConnectionModule">
        <add Name="Intranet" Address="http://intranet"/>
        <add Name="Internet" Address="http://www.microsoft.com"/>
      </Networks>
    </ConnectionMonitor>
    

Show:
© 2016 Microsoft