Xafari Reports. IDataMiner Implementation

To implement Xafari.Reports.IDataMinerOperation interface, it is required to define ReportData property and CollectData() method. ReportData property refers to the XafariReportDataBase object, named Report Data object. This object can exposes one or more IList<T> properties, where T is persistent, and CollectData() method should to populate this properties with data.

Xafari.Reports namespace contains Xafari.Reports.DataMinerOperationBase and Xafari.Reports.DataMinerOperationBase<TReportData, TParameters> base classes that supports IDataMinerOperation interface by default. These base classes initialise ReportData property automatically, obtain objects and add them to the Report Data.

To implement a specific scenario for retrieving data, the developer can override the CollectData() method, but might be sufficient to substitute only part of the base implementation that are listed below:

  • the initialization of the ReportData property;
  • the selection criteria and sorting direction for the collection properties;
  • the method to populate collection properties.

Such techniques is demonstrated in the Northwind DC demo.

ReportData initialization

Virtual CreateReportDataCore method creates a XafariReportDataBase object:

  • c#
  • VB

protected virtual XafariReportDataBase CreateReportDataCore()
{
}

Protected Overridable Function CreateReportDataCore() As XafariReportDataBase
End Function

This uses the default constructor(no arguments). Override CreateReportDataCore method, to implement custom constructor or any specific operations.

Selection criteria and sorting

There are GetCriteria and GetSorting virtual methods to provide selection and sorting of the data in collection properties:

  • c#
  • VB

protected CriteriaOperator GetCriteria(string propertyName)
{
}
protected IList<SortProperty> GetSorting(string propertyName)
{
}

Protected Function GetCriteria(ByVal propertyName As String) As CriteriaOperator
End Function
Protected Function GetSorting(ByVal propertyName As String) As IList(Of SortProperty)
End Function

Methods receive propertyName parameter that specifies the collection property name. The criterion and sorting will be applied to the specified property. Default implementation of this methods uses CollectDataSpecificationAttribute to describe selection criteria and sorting in the report data source directly:

  • c#
  • VB

public CollectDataSpecificationAttribute(string criteria, string criteriaParameters, string sortingProperties)
{
}

Public Sub New(ByVal criteria As String, ByVal criteriaParameters As String, ByVal sortingProperties As String)
End Sub

where:

  • criteria is a selection criteria represented by a string, parameters are replaced to the «?» character;
  • criteriaParameters is a string that lists the criteria parameters separated by the «;» character; the order of the parameters is important, it must match the criteria entry; parameters can be a properties of the ReportData or DataMinerOperation objects.
  • sortingProperties is a string that specifies sorting direction (Ascending or Descending) for the fields; use the following form of notation: «field1:sort1;field2:sort2».

The code snippet below demonstrates the use CollectDataSpecificationAttribute in the Northwind DC demo:

  • c#
  • VB

[XafDisplayName("Orders list data source")]
public class OrderXafReportData : XafariReportDataBase
{
  [DisplayName("Parameters")]
  public IOrderXafParameters Parameters { get; set; }
  [XafDisplayName("Data table")]
  [CollectDataSpecification("DocDate >= ? && DocDate <= ?", "Parameters.DateBegin;Parameters.DateEnd", "DocDate:Ascending")]
  public IEnumerable<Order> DataObjects { get; set; }
}

<XafDisplayName("Orders list data source")> _
Public Class OrderXafReportData
  Inherits XafariReportDataBase
  <DisplayName("Parameters")> _
Public Property Parameters As IOrderXafParameters
  <XafDisplayName("Data table")> _
<CollectDataSpecification("DocDate >= ? && DocDate <= ?", "Parameters.DateBegin;Parameters.DateEnd", "DocDate:Ascending")> _
Public Property DataObjects As IEnumerable(Of Order)
End Class

The method to populate collection properties.

There are SetCollectionPropertyValue virtual method. The method receives propertyName parameter that specifies the collection property name and return bool value.              

  • c#
  • VB

protected virtual bool SetCollectionPropertyValue(string propertyName)
{
}

Protected Overridable Function SetCollectionPropertyValue(ByVal propertyName As String) As Boolean
End Function

If the property must be populated using the default algorithm, the method returns False. If the default algorithm is not required, the method will return True.