Data providers are created from classes that inherit the ITfDataProviderAddon
interface. Tefter.bg scans for these classes during startup and makes them available to users.
Data providers also require typed components for their lifecycle.
The typical process for creating and distributing a data provider for Tefter.bg involves developing a Razor library project and then distributing the result as a NuGet package. For practical examples, you can review the projects of existing providers created by us, such as:
Seed Project | GitHub |
CSV Data Provider | GitHub |
MSSQL Data Provider | GitHub |
The usual structure of the projects is as follows:
This is they usual structure of a аata Provider method and its properties and callback methods.
using CsvHelper;
using CsvHelper.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using WebVella.Tefter.Exceptions;
using WebVella.Tefter.Models;
using WebVella.Tefter.Services;
using WebVella.Tefter.Web.Utils;
namespace WebVella.Tefter.DataProviders.Csv;
public class CsvDataProvider : ITfDataProviderAddon
{
public const string ID = "82883b60-197f-4f5a-8c6a-2bec16508816";
public const string NAME = "Csv Data Provider";
public const string DESCRIPTION = "Provide data from CSV formated file";
public const string FLUENT_ICON_NAME = "DocumentTable";
public Guid Id { get; init;} = new Guid(ID);
public string Name { get; init;} = NAME;
public string Description { get; init;} = DESCRIPTION;
public string FluentIconName { get; init;} = FLUENT_ICON_NAME;
/// <summary>
/// Return what types of data types it can process from the data source
/// </summary>
public ReadOnlyCollection<string> GetSupportedSourceDataTypes()
{
//sample only
return new List<string> {
"TEXT", //Keep text on first place as the first place is used as default type
}.AsReadOnly();
}
/// <summary>
/// Returns mapping between source data types and Tefter.bg data types
/// </summary>
public ReadOnlyCollection<TfDatabaseColumnType> GetDatabaseColumnTypesForSourceDataType(
string dataType)
{
return new List<TfDatabaseColumnType>().AsReadOnly();
}
/// <summary>
/// Gets data from the data source
/// </summary>
public ReadOnlyCollection<TfDataProviderDataRow> GetRows(
TfDataProvider provider,
ITfDataProviderSychronizationLog synchLog)
{
return (new List<TfDataProviderDataRow>()).AsReadOnly()
}
/// <summary>
/// Gets the data source schema
/// </summary>
public TfDataProviderSourceSchemaInfo GetDataProviderSourceSchema(TfDataProvider provider)
{
return new TfDataProviderSourceSchemaInfo();
}
/// <summary>
/// Validates its custom settings on user submit
/// </summary>
public List<ValidationError> Validate(string settingsJson)
{
return new List<ValidationError>();
}
}
This is a component that is used in the manage settings modal to enable provider custom settings management.
It needs to inherit the ITfRegionComponent<TfDataProviderManageSettingsComponentContext>
interface.
This is a component that is used to display the custom settings of the data provider.
It needs to inherit the ITfRegionComponent<TfDataProviderDisplaySettingsComponentContext>
interface.