Working with data sources

Data sources can be a variety of items, including layers in map widgets, selections in a map or list widget, or feature services that are not drawn on the map. The author defines the data sources available when they configure an operation view.

The sections below describe different types of data sources that can be encountered in an add-in. For more information about configuring data sources in the application, refer to the application help topic Data sources in the operation view.

Data source providers

Data sources can be provided by different widgets, the primary provider commonly being the map widget. The author chooses which layers in a map will become data sources.

Additionally, other widgets can provide data sources. The list widget provides a data source consisting of only the features that are selected in the list, and also a data source consisting of only the single feature shown at the top of the list. The query widget provides a data source consisting of the features that comprise the current query result set. These widgets provide data sources by consuming other data sources; the data source they provide is ultimately provided by a feature service.

Standalone data sources are not provided by a widget, but instead are provided directly by the application, based on the settings chosen by the author.

The different types of data source may all be queried in the same way, by using the asynchronous query methods on the DataSource class.

Custom add-ins cannot define new data source providers.

Data source consumers

Widgets often show information about a data source that is configured in the current operation view. Such widgets are known as data source consumers; most out-of-the-box widgets, such as the list, feature details, summary, and chart widgets are data source consumers. Data source consumers are notified when the data sources they consumer may be updated, and when they are removed.

Custom widgets can become data source consumers by implementing the IDataSourceConsumer interface. See the How to respond to changes in data sources topic for more information.

Examples of data source consumers

The Count Widget sample in the SDK is a data source consumer, and demonstrates querying a data source for a count statistic, and performing this query in an async method.

The default widget item template included in the ArcGIS Runtime SDK for WPF is a data source consumer, however the OnRefresh method is left unimplemented.

Dynamic and static data sources

Data sources based on feature layers in a map, or standalone data sources based directly on feature services, can be either dynamic or static. The author chooses this setting when configuring the data source.

Static data sources are those that the author decides will not change during the lifetime of the application process, and dynamic data sources are those that will change during that time. For example, a dynamic data source may be one based on a feature service that is editable, perhaps based on a live feed of vehicle location and status.

The How to respond to changes in data sources topic contains more information about when data source consumers are notified about changes.

Selection data sources

When configuring a data source in a map widget, the author can check the Selectable check box. This creates a second data source based on the same feature layer in the map, but restricted to only contain the features which are selected in the map. This second data source will return true from the IsSelectable property on the DataSource class

If an add-in provides custom selection code, in order to be consistent with the settings chosen by the author, the add-in may include code to only allow selections to occur on selectable data sources. Selections can be performed programmatically by using the ESRI.ArcGIS.Client API to select the Graphics in the feature layer in the map. See the Selecting features in a map widget topic for more information about programmatically selecting features in a map widget.

Broken data sources

Data sources may be broken when an operation view is opened, for example if the service item that the data source is based on can no longer be found. A data source may also become broken while the view is open, for example if the service is taken down temporarily. If a custom widget is a consumer of a broken data source, the application will automatically highlight this to the user in the same way as for out-of-the-box widgets; a warning icon is shown in the title bar of each widget with a broken data source.

The DataSource.IsBroken property indicates if a data source is currently considered to be broken. If a query method is called on a data source which is broken, the QueryResult object Canceled property will be set to true, and the Error property will contain exception information about the cause of the error. A data source consumer widget should always check the Canceled property of the QueryResult returned from any of the asynchronous query methods; at this point, the previous information may be left in the widget user interface, or the interface could show a message to the user, depending on what user experience is required.

If a data source that was broken is repaired, for example if a service was temporarily taken down and then reinstated, then the OnRefresh method if the IDataSourceConsumer interface will be called on any consuming widgets, giving them a chance to update their user interface at that point. This call is made whether a data source is dynamic or static.

DataSourceSelector control

The DataSourceSelector control is provided as part of this SDK to easily add the same data source selection user experience as the out-of-the-box widgets. This control can be added to a configuration dialog box for a widget and allows the author of an operation view to select a single data source from all the data sources available in the application at run time. The XAML below shows the DataSourceSelector added to a Window; note that the namespace ESRI.ArcGIS.OperationsDashboard.Controls must be defined. The SelectedDataSource property can be used to find the data source selected by the author when the dialog box is closed.

DataSourceSelector in Xaml

<Window x:Class="OperationsDashboardExamplesCS.Config.DataSourceExamplesDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:opsDash="clr-namespace:ESRI.ArcGIS.OperationsDashboard;assembly=ESRI.ArcGIS.OperationsDashboard"
        xmlns:opsDashCtl="clr-namespace:ESRI.ArcGIS.OperationsDashboard.Controls;assembly=ESRI.ArcGIS.OperationsDashboard"
        Style="{StaticResource SizableModalDialogWindowStyle}"
        WindowStartupLocation="CenterOwner" Title="Configure Widget">
  <Grid>
    <StackPanel Orientation="Vertical">
      <TextBlock Text="Data Source:" Style="{StaticResource SettingLabelStyle}" />
      <opsDashCtl:DataSourceSelector x:Name="DataSourceSelector"></opsDashCtl:DataSourceSelector>
    </StackPanel>
  </Grid>
</Window>

The default widget item template demonstrates how this control can be used.

1/27/2015