☝️Small business or a startup? See if you qualify for our special offer.
+
All documentation
Connecting to data source
  1. Supported data sources
  2. Connecting to other data sources

Configurations reference

This guide describes the available configurations for Flexmonster.DataServer.Core.dll. For the Data Server DLL, it is possible to set up indexes with data, configure data refresh time and cache size, and define report-sharing settings.

Available configurations

The Data Server supports the following configuration properties:

{
DataSources: DataSourceConfigObject[],
DataStorageOptions: DataStorageOptionsObject,
ReportSharingOptions: ReportSharingOptionsObject
}
Property/TypeDescription
DataSources
DataSourceConfigObject[]
Configures the data sources.
DataStorageOptions
DataStorageOptionsObject
optional Configures options for data storage.
ReportSharingOptions
ReportSharingOptionsObject
optional Configures the report-sharing functionality.

DataSourceConfigObject

This object allows configuring a data source. It has the following properties:

{
Type: string,
DatabaseType: string,
ConnectionString: string,
Indexes: object
}
Property/TypeDescription
Type
String
The type of the data source: "json""csv""database", or your custom type (for the custom parser).
DatabaseType
String
optional The type of the database: "mysql""mariadb", "mssql""postgresql", or "oracle". Only for the "database" data source type.
ConnectionString
String
optional A connection string for the database. Only for the "database" data source type.

Setting passwords with special characters in the connection string. The Data Server parses passwords with special characters correctly unless the password contains ; or ". These symbols are treated as delimiters, so they should be escaped:
  • If your password contains a semicolon (;), enclose the password in single quotes (e.g., Pwd='123;45').
  • If your password contains a double quote ("), escape this symbol with a backslash (e.g., Pwd=123\"45).
Indexes
Object
Contains a list of datasets. Each dataset is represented by a "key": "value" pair, where "key" is a dataset name. The "value" can either be an IndexObject or null (only for the custom data source type).

IndexObject

This object describes a specific dataset. It has the following properties:

{
Path: string,
Mapping: ServerSideMappingObject,
Delimiter: string,
DecimalSeparator: string,
ThousandsSeparator: string,
Query: string,
Status: string,
RefreshTime: number
}
Property/TypeDescription
Path
String
optional The path to the file with data. Only for "json" and "csv" data source types.
Mapping
ServerSideMappingObject
optional Defines how the Data Server should process fields from the dataset. Only for "json" and "csv" data source types.
Delimiter
String
optional Specifies a character that separates fields in the CSV file.
Default value: ",".
DecimalSeparator
String
optional Specifies a character that separates the decimal part of a number in the CSV file (e.g., for 3,14, set the DecimalSeparator property to ",").
Default value: ".".
ThousandsSeparator
String
optional Specifies a character that separates groups of digits in a number in the CSV file (e.g., for 1.000, set the ThousandsSeparator property to ".").
Default value: ",".
Query
String
optional The query to execute (e.g., "SELECT * FROM tablename"). It can contain a stored procedure. Only for the "database" data source type.
Status
String
optional The index status. It can be either "enabled" or "disabled". Disabled indexes are not available on the client side.
Available starting from version 2.9 of the Data Server.
Default value: "enabled".
RefreshTime
Number
optional Defines how often the Data Server reloads the data for the index.
The refresh time must be specified in minutes and is measured from the moment the Data Server starts up.
When the RefreshTime is set to 0, the Data Server will not reload the data.
If the RefreshTime is specified, it overrides the DataStorageOptions.DataRefreshTime property.
If the RefreshTime is not specified, the Data Server will use the value set in the DataStorageOptions.DataRefreshTime property.
Available starting from version 2.9 of the Data Server.

ServerSideMappingObject

This object defines how the Data Server should process fields from the dataset. It has the following properties:

Mapping: {
<uniqueName>: {
Type: string
}
}
Property/TypeDescription
<uniqueName>
Object
Sets the mapping for a specific field from the dataset. "<uniqueName>" is the field’s unique name.
<uniqueName>.Type
String
optional The field’s data type. The Type can be:
  • "string" — the field stores string data.
  • "number" — the field stores numerical data.
  • "date" — the field stores a date.
If this property is not specified, the Data Server resolves the data type automatically based on the field’s values in the dataset.

DataStorageOptionsObject

This object allows configuring options for data storage. It has the following properties:

DataStorageOptions: {
DataRefreshTime: number,
CacheSizeLimit: number,
KeepDataOnRefresh: boolean,
CommandTimeout: number
}
Property/TypeDescription
DataRefreshTime
Number
optional Defines how often the Data Server reloads the data from the data source. The refresh time must be specified in minutes and is measured from the moment the Data Server starts up.
To set the refresh time for a specific index, use the Indexes.<indexName>.RefreshTime property.
By default, the DataRefreshTime is 0, which means the Data Server will not reload the data.
CacheSizeLimit
Number
optional The maximum number of cached server responses for every index defined in the DataSources property. When set to 0, the Data Server does not cache the responses.
Default value: 100.
KeepDataOnRefresh
Boolean
optional Defines whether the Data Server keeps a copy of index data while the index is being refreshed.
When set to true, the index is available to Flexmonster Pivot even during index reload. Note that this feature requires more RAM. As soon as the index is refreshed, the Data Server deletes its copy.
If KeepDataOnRefresh is set to false, the index will be unavailable while refreshing.
Default value: true.
CommandTimeout
Number
optional Defines the wait time before canceling the attempt to execute the Query and generating an error. The wait time is set in seconds. When set to 0, the wait time is unlimited.
If CommandTimeout is not specified, the Data Server will use the timeout value from the SQL driver.
Only for the "database" data source type.

ReportSharingOptionsObject

This object allows configuring the report-sharing functionality. It contains the following properties:

ReportSharingOptions: {
PathToFolder: string
}
Property/TypeDescription
PathToFolder
String
optional Defines the folder to which the Data Server saves reports. This property overrides the default folder set in the AddReportSharing service configuration.

Setting configs

You can configure the Data Server through:

  • Configuration file
  • Code
  • Both code and the file

Configuration file

Flexmonster.DataServer.Core.dll can be configured via the ASP.NET configuration file (e.g., appsettings.json). In addition to the Data Server's configuration, this file can contain any other settings needed for the project, as long as they do not conflict with each other.

To configure the Data Server via appsettings.json, follow the steps below:

Step 1. Define the needed configurations in appsettings.json. Here is an example of a configured appsettings.json file with the custom parser:

Expand the example
{
  "DataSources": [
    {
      "Type": "custom-parser",
      "Indexes": {
        "custom-index": null
      }
    },
    {
      "Type": "json",
      "Indexes": {
        "first-json-index": {
          "Path": "data/data.json" 
        },
        "second-json-index": {
          "Path": "data/another-data.json"
        }
      }
    },
    {
      "Type": "csv",
      "Indexes": {
        "csv-index": {
          "Path": "data/data.csv",
          "Delimiter": ";",
          "DecimalSeparator": "."
        }
      }
    }
  ],
  "DataStorageOptions": {
    "DataRefreshTime": 60,
    "CacheSizeLimit": 150
  }
}

Step 2. To apply configs from appsettings.json, add the following line of code to the Program.cs file:

using Flexmonster.DataServer.Core;

var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureFlexmonsterOptions(builder.Configuration);
// Other configurations

Code

You can configure the Data Server through code using the Program.cs file. See how to:

Create indexes

Step 1. In the Program.cs file, call the builder.Services.Configure<DatasourceOptions>() method:

var builder = WebApplication.CreateBuilder(args);
// Other configurations

builder.Services.Configure<DatasourceOptions>((options) => {
});
// Other configurations

Step 2. In builder.Services.Configure<DatasourceOptions>(), create a dictionary to store your indexes:

// Other configurations

builder.Services.Configure<DatasourceOptions>((options) => {
options.Indexes = new Dictionary<string, IndexOptions>();
});
// Other configurations

As you can see, each index consists of two fields:

  • A string field, which is the index’s name.
  • An IndexOptions field, which contains configurations needed to load the index’s data. IndexOptions is an abstract class.

Step 3. Add your index to the Indexes dictionary. For example, let’s create a new JSON index:

// Other configurations

builder.Services.Configure<DatasourceOptions>((options) => {
options.Indexes = new Dictionary<string, IndexOptions>();
options.Indexes.Add("json-index",
new JsonIndexOptions("path-to-your-file.json"));
});
// Other configurations

JsonIndexOptions is a class that allows configuring JSON indexes. It is based on the IndexOptions class.

CSV and database indexes are configured through similar classes:

  • JSON:
    • public JsonIndexOptions(string path)
  • CSV:
    • public CsvIndexOptions(string path)
    • public CsvIndexOptions(string path, char delimiter, char decimalSeparator, char thousandsSeparator)
  • Databases:
    • public DatabaseIndexOptions(databaseType, connectionString, query)

See the full list of configurations for indexes.

Set data storage options

Step 1. In the Program.cs file, add the following lines of code:

using Flexmonster.DataServer.Core.DataStorages;

var builder = WebApplication.CreateBuilder(args);
// Other configurations

builder.Services.Configure<DataStorageOptions>((options) => {
});
// Other configurations

Step 2. Set the needed data storage options using the options object:

// Other configurations

builder.Services.Configure<DataStorageOptions>((options) =>
{
options.CacheSizeLimit = 100;
options.DataRefreshTime = 60;
});
// Other configurations

See the full list of available data storage options.

Both code and the file

If needed, you can load configs from appsettings.json and then continue configuring the Data Server through code:

using Flexmonster.DataServer.Core;

var builder = WebApplication.CreateBuilder(args);
// Apply configs from appsettings.json:
builder.Services.ConfigureFlexmonsterOptions(builder.Configuration);

/* Note: importing configs from the file overrides configs
set through code. That’s why you should always
add your configs after the
builder.Services.ConfigureFlexmonsterOptions(builder.Configuration)
line
*/
builder.Services.Configure<DatasourceOptions>((options) => {
options.Indexes = new Dictionary<string, IndexOptions>();
options.Indexes.Add("json-index",
new JsonIndexOptions("path-to-your-file.json"));
});
// Other configurations

See also