Kanzi Connect data source

Use the Kanzi Connect data source to get data from the Kanzi Connect services and distributed content system to a Kanzi application. You can access the data model of the Kanzi Connect data source in Kanzi Studio in the Data Sources window, where you can see the data you can use in your application.

../_images/data-sources.png

The Kanzi Connect data source connects to the distributed content system in the Kanzi Connect server and retrieves the data from the database and Kanzi Connect services according to given configuration. Once the data is available in the internal data object tree of the Kanzi Connect data source, you can bind it to the application UI using bindings.

The Kanzi Studio projects that you create with the Kanzi Connect Client Application template include the Kanzi Connect data source.

../_images/create_new_kanzi_studio_project.png

The data model of the Kanzi Connect data source is automatically configured for the Kanzi Connect services that you import to your Kanzi Studio project. To learn how to use the Kanzi Connect data sources, complete the tutorial Tutorial: Create a Kanzi Connect application.

Getting data from Kanzi Connect to your application in Kanzi Studio

You can use the Kanzi Connect data model of the data source in bindings. This way you get data from the Kanzi Connect services and the content system to your application.

To get data from Kanzi Connect to your application in Kanzi Studio:

  1. Drag the data source from the Data Sources window to the Project to the node where you want to use the data source, or to one of its parent nodes.

    Kanzi adds and sets the Data Context property of that node to the data source that you dragged. The Data Context property tells the node from which data source it receives data. When you set the Data Context property for a node, all its child nodes inherit the value of the Data Context property.

    ../_images/cluster-in-data-sources.png ../_images/drag-data-source-to-rootpage.png ../_images/data-context-data-source.png
  2. Drag a data object from the Data Sources window to the Properties to the property the value of which you want to get from that data object.

    Kanzi creates a binding that binds the value of the property to the data object from the data source set by the Data Context property. The binding expression format is {DataContext.path.to.data}.

    ../_images/textblock-2d-in-the-project.png ../_images/data-sources-rpm.png ../_images/drag-car-rpm-to-textblock-2d-text.png

To learn more about data sources and bindings, in the Kanzi framework documentation see:

Configuring the data model in a configuration XML file

The primary way to define and bind data from a Kanzi Connect data source is Kanzi Studio, but you need to define the data model of the data source in a configuration XML file when you want to:

At application runtime the implementation first reads the data source descriptions from Kanzi Studio. It merges the values in the configuration XML file on top of the content in Kanzi Studio. This means that during prototyping phase you can use a text editor to replace the data object fields in Kanzi Studio.

The data source configuration XML file defines the internal structure of the data object tree of the data source. It also defines the origin of the data for a particular data object in the tree.

To configure the data object, in Kanzi Studio in the Data Sources window hover over the data source, click image4, and set Data Source XML File to the path to the XML file that defines the data model of your data source.

The data source is now ready and you can see the available data in the Data Sources window.

To update the view to the data model of the data source, click image5.

The configuration XML file syntax is described below.

<root>
    <!-- Access the distributed content database in a table-like manner. -->
    <source URI="content://com.rightware.service_name/content_path" name="data_object_name">
        <field column="column_name" type="int/string/float" name="data_object_name"/>
    </source>

    <!-- Access service-specific table type of data. -->
    <source URI="service://com.rightware.service_name" name="service_name">
        <field column="current_track_id" type="int" name="current_track"/>
    </source>

    <!-- Access the structure runtime-time data values of a running Cluster service -->
  <source uri="servicedata://cluster">
    <engine name="car">
        <speed type="float" />
        <rpm type="int" />
        <gear type="int" />
    </engine>
  </source>
</root>

The data source content can have these schemes in the URI:

  • content:// refers to distributed table format content where result is combined result of multiple individual content providers results

  • service:// refers to a service specific table format content where result comes from a service specific content provider

  • servicedata:// refers to a service specific structured runtime data. See Using service runtime data.

Defining a placeholder image

To define a placeholder image that is used until the application downloads from the server the content referenced by the target attribute, set the preload_url property:

<source uri="content://com.rightware.content/contacts" name="contacts" type="list" block_size="200">
  <field column="name" type="string" name="name"/>
  <field column="phonenumber" type="string" name="phonenumber"/>
  <field column="image" type="string" name="image" preload_url=" uri="kzb://ivi/Textures/Icon_Avatar"/>
</source>

or

<root>
   ...
   <preload_url target="contacts.image" uri="kzb://ivi/Textures/Icon_Avatar"/>

Optimizing the behavior of virtualized lists

To optimize the behavior of virtualized lists by setting a limit to the amount of data downloaded from the targeted source at once, set the block_size property:

<source uri="content://com.rightware.content/contacts" name="contacts" type="list" block_size="200">
  <field column="name" type="string" name="name"/>
  <field column="phonenumber" type="string" name="phonenumber"/>
  <field column="image" type="string" name="image" preload_url=" uri="kzb://ivi/Textures/Icon_Avatar"/>
</source>

or

<block_size target="contacts" size="100"/>

Referring to database tables within tables with conditions

To reference other database tables within tables with conditions, see the dynamic_source property:

<source uri="content://com.rightware.content/playlists" name="playlists" type="list">
  <field column="name" type="string" name="name"/>
  <field column="id" type="integer" name="id"/>
  <field column="source" type="string" name="sourceimage"/>
  <field type="list" column="tracks" name="tracks" dynamic_source="content_songs" lookup_column="id"/>
</source>

<dynamic_source uri="content://com.rightware.content/songs" name="content_songs" type="list">
  <field column="name" type="string" name="name"/>
  <field column="id" type="integer" name="id"/>
  <field column="artist" type="string" name="artist"/>
  <field column="album_id" type="integer" name="album_id"/>
  <field column="albumimage" type="string" name="albumimage" preload_url="http://<server>:8080/albumart/empty_music.png"/>
</dynamic_source>

or

<dynamic_source uri="content://com.rightware.content/songs" name="songs" type="list"/>
<data-source uri="content://com.rightware.content/playlists" name="playlists" type="list">
    <field type="list" column="tracks" name="tracks"/>
</data-source>
<dynamic_source target="playlists.tracks" dynamic_source="songs" lookup_column="id"/>