Connection Framework

Overview

The Connection Framework allows to connect MatchPoint page components with each other. Through the Connection Framework values and information of other Web Parts and Controls can be accessed. For instance a Data Grid Web Part could consume its filter values from a text input control or a Form Web Part. Or a Choice +Field could provide choices, depending on another field's value (e.g. cascading choice fields).

The Connection Framework notifies controls via JavaScript about value changes. A control then updates its content using an AJAX method call. This has the effect that controls can be updated without a re-load of the entire page. This concept allows you to build rich and responsive user interfaces with MatchPoint.

Connections between controls are established using the Expression Engine. Controls consuming values will reference the data source via the expression ConnectionData.<DataSourceName>. The Connection Framework automatically determines dependencies by analyzing the use of the ConnectionData variable.

There are two samples referenced at the end of this chapter, demonstrating how to implement a connectable Web Part.

Connection Data Sources

The following table lists controls and their connection value type, that can be used as connection data sources.

Control Type Empty Value
Text Field String null
Boolean Field Boolean null
Date Field DateTime null
Link Field LinkValue Class null
Person Field AccountChoiceItem Class / AccountChoiceItem[] null / Empty array
Choice Field IChoiceItem Interface / IChoiceItem[] null / Empty array
Term Choice Field IChoiceItem Interface / IChoiceItem[] null / Empty array
Tag Choice Field TagChoiceItem class / TagChoiceItem[] Empty array
Rich Text Field String null
Attachments Field AttachmentInfoCollection class Empty collection
Template Field TemplateChoiceItem class null
Expression Field n/a n/a
Composite Field CompsoiteConnectionData Class Cannot be empty
Composite Web Part CompsoiteConnectionData Class Cannot be empty
Data Grid Web Part DataGridConnectionData Class Cannot be empty
Refinement Web Part AndGroupCondition Class null
Search Definition Web Part AndGroupCondition Class null
Chart Web Part SeriesPoint Class null
Image Tag Web Part TagChoiceItem class / TagChoiceItem[] Empty array
Connection data types of controls

Producer / Consumer Principle

A scenario, where a consumer is depending on the product of a producer can be modeled in various ways; e.g. with a polling mechanism. However, the polling model involves a high communication overhead and a risk of losing information. Hence, MatchPoint's implementation is following the so called Hollywood principle: "Don't call us, we'll call you!".

This implies, that all consumers register with their producers and that the producers notify them, if and only if there is new information.

This introductory example is oversimplified: first, a consumer might appear as a producer itself and second, there is a many to many relation between the set of consumers and the set of producers. This implies of course, that it is possible to configure an example, which produces an infinite notification loop. Technically it would be trivial to determine loops, but they might also be required to model specific behavior (e.g. data grid with a refiner).

Connection Data Consumers

You can consume connection data in configurations where an ExpressionString or a PatternString is allowed. However, not every component will refresh itself, when the data source changes. The following table shows configuration elements and some of their components which will be refreshed on data source changes:

Control Configuration Element
Data Grid Web Part
  • DataProvider.Conditions
  • Web Part Ribbon Buttons
  • Chrome
Composite Web Part / Composite Field
  • DataProvider.Conditions
  • PatternTransformer
  • Web Part Ribbon Buttons
  • Chrome
Form Web Part / Composite Web Part
  • Field.ReadOnlyExpression
  • Field.VisibilityCondition
  • ChoiceField.DataSource
  • ExpressionField
  • CompositeField
  • TagChoiceField (ControlType.ListBox only)
  • Web Part Ribbon Buttons
  • Chrome
Chart Web Part
  • DataProvider.Conditions
  • Chrome
Search Definition Web Part / Refinement Web Part / User Control Web Part
  • Chrome
Components that are refreshed on data source changes

Consumer Registration

All consumers have to register with their producers. This is done server-sided, using the ConnectionManager class within the OnInit() or OnLoad() method (see ASP.NET Life Cycle); the this keyword is pointing to the control in this context.

DependencyCollection dependencies = new DependencyCollection();
ConnectionManager.RegisterConsumer(this, dependencies);

The DependencyCollection object should hold all the required information about this dependency to a consumer. This means, the name of the producer and the fields required by the consumer.

string endPoint = "ConnectionData.ProducerWebPartName.SelectedRow";
string[] columnNames;
dependencies.Add(endPoint);
foreach (string colName in columnNames)
{
  dependencies[0].Add(colName);
}
// or short, without an additional iteration:
dependencies.Add(endPoint, columnNames);

There is also another way, to achieve the above, if endPoint is provided as an ExpressionString. But note, that this has a special behavior! It adds a dependency collection holding the end point and if and only if the end point is SelectedRow, it adds all columns implicitly!

dependencies.AddFromExpression(expression);

Producer Registration

Similar to consumers, producers have to register with the ConnectionManager as well; this is required to determine the type of an expression evaluation. The registration is done server-sided, using the ConnectionManager class within the OnInit() or OnLoad() method; the this keyword is pointing to the control in this context and MyClass describes the value, that is provided.

ConnectionManager.RegisterDataSource(this, "ProducerWebPartName", typeof(MyClass));

Notification

Since polling the producers would not scale, a notification approach is used in the MatchPoint Connection Framework. Hence, each producer has a list of consumers. This list is maintained automatically by the connection framework and updated using the consumer registrations.

When a producer changes its state (due to incoming notifications or a refresh) it writes new data to the ConnectionData, using the ConnectionManager:

ConnectionManager.SetData("ProducerWebPartName", newDataObject);

After a producer changed its state, all depending consumers are notified about the change. The consumers decide, how to handle the new information and whether they need to notify their consumers, etc.

See Also

results matching ""

    No results matching ""