This project is read-only.

Disconnected Service Agent sample with CompositeWPF

All the Offline Blocks (Disconnected Service Agent, Endpoint Catalog and Connection Monitor) shipped with SCSF - May 2007 and higher versions do not have dependencies on CAB/SCSF.
To be able to use those blocks in a Composite WPF application you can do the following:
  • Add the following configuration to the App.config file to configure the connection monitor and select the data storage that will be consumed by the DSA:
<configuration>
  <configSections>
    <section name="ConnectionMonitor"
             type="Microsoft.Practices.SmartClient.ConnectionMonitor.Configuration.ConnectionSettingsSection, Microsoft.Practices.SmartClient.ConnectionMonitor" />
    <section name="dataConfiguration"
             type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />
  </configSections>
  <connectionStrings>
    <add name="QueueDatabase" connectionString="YourConnectionString" providerName="YourProvider" />
  </connectionStrings>
  <ConnectionMonitor>
    <Networks>
      <!-- To check for internet connectivity-->
      <add Name="Internet" Address="http://www.google.com" />
    </Networks>
  </ConnectionMonitor>
  <dataConfiguration defaultDatabase="QueueDatabase">
    <providerMappings>
      <add databaseType="Microsoft.Practices.SmartClient.EnterpriseLibrary.SmartClientDatabase, Microsoft.Practices.SmartClient.EnterpriseLibrary"
           name="System.Data.SqlServerCe" />
    </providerMappings>
  </dataConfiguration>
</configuration> 
  • Set up the Request Manager by overriding the ConfigureContainer method of your application's Bootstrapper class.
protected override void ConfigureContainer()
{
    // Set up request manager.
    RequestManager requestManager = DatabaseRequestManagerIntializer.Initialize();
    requestManager.StartAutomaticDispatch();

    // Add the request queue to the Container. This queue will be used by service agents to enqueue requests.
    Container.RegisterInstance<IRequestQueue>(requestManager.RequestQueue, new ContainerControlledLifetimeManager());

    // Add the connection monitor to the Container. It will be used to determine connectivity status and provide    // feedback to the user accordingly.
    Container.RegisterInstance<IConnectionMonitor>(requestManager.ConnectionMonitor, new ContainerControlledLifetimeManager());

    base.ConfigureContainer();
} 
  • Create an Agent service class that uses the IRequestQueue to define the offline behavior of your web service (in SCSF this is performed by the Create a Disconnected Service Agent recipe).
  • Register an instance of your Agent class into your container. You can do this in your Module class.
public void Initialize()
{
    RegisterTypesAndServices();

    // Add your module views...
}

private void RegisterTypesAndServices()
{
    Container.RegisterType<Agent>(new ContainerControlledLifetimeManager());
} 

Now you are able to inject your service agent in your classes.

More information on How-to: Use the Disconnected Service Agent (DSA) with CompositeWPF (Prism)

Last edited Aug 12, 2008 at 3:25 PM by mconverti, version 2

Comments

No comments yet.