This guide describes the available configurations for Flexmonster.DataServer.Core.dll
. For the Data Server DLL, it is possible to configure data sources and set the data refresh time.
Table of contents:
The Data Server supports the following configuration properties:
{ "DataSources": DataSourceConfigObject[], "DataStorageOptions": DataStorageOptionsObject }
Property/Type | Description |
---|---|
DataSources DataSourceConfigObject[] |
Options for configuring the data sources. |
DataStorageOptions DataStorageOptionsObject |
optional Allows configuring options for data storage. |
This object allows configuring a data source. It has the following properties:
{ "Type": string, "DatabaseType": string, "ConnectionString": string, "Indexes": object }
Property/Type | Description |
---|---|
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:
|
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 null (only for the custom data source type) or be an IndexObject. |
This object describes a specific dataset. It has the following properties:
{ "Path": string, "Query": string, "Mapping": ServerSideMappingObject, "Delimiter": string, "DecimalSeparator": string, "ThousandsSeparator": string, "Status": string, "RefreshTime": number }
Property/Type | Description |
---|---|
Path String |
optional The path to the file with data. Only for "json" and "csv" data source types. |
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. |
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 Defines the specific fields separator to split each CSV row. There is no need to define it if the CSV fields are separated by , . This property is required only if another character separates fields.Default value: "," . |
DecimalSeparator String |
optional Defines the specific character used to separate decimal parts of numbers. For example, to import CSV data with commas used to separate decimal parts of numbers (e.g., 3,14 ), set the "DecimalSeparator" property to "," .Default value: "." . |
ThousandsSeparator String |
optional Defines the specific character used to separate groups of digits in numbers. For example, to import CSV data with periods used to separate groups of digits in numbers (e.g., 1.000 for one thousand), set the "ThousandsSeparator" property to "." .Default value: "," . |
Status String |
optional The index status. It can be either "enabled" or "disabled" . Disabled indexes are not available from the client.The "Status" property is 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 is specified in minutes. If it is 0 , the Data Server will not reload the data."RefreshTime" will override a value set in DataStorageOptions.DataRefreshTime.If "RefreshTime" is not specified, the Data Server will use the DataStorageOptions.DataRefreshTime property.If both properties are not specified, the data will not be reloaded. The "RefreshTime" property is available starting from version 2.9 of the Data Server. |
This object defines how the Data Server should process fields from the dataset. It has the following properties:
"Mapping": { "(uniqueName)": { "Type": string } }
This object allows configuring options for data storage. It has the following properties:
"DataStorageOptions": { "DataRefreshTime": number, "CacheSizeLimit": number, "KeepDataOnRefresh": boolean, "CommandTimeout": number }
Property/Type | Description |
---|---|
DataRefreshTime Number |
optional Defines how often the data is reloaded from a file or a database. The refresh time is set in minutes. If the "DataRefreshTime" is not specified, the data will not be reloaded. |
CacheSizeLimit Number |
optional The maximum number of cached server responses for every index. When set to 0 , the Data Server does not cache the responses.Default value: 100 . |
KeepDataOnRefresh Boolean |
optional When set to true , the Data Server keeps a copy of index data while the index is being refreshed. As a result, 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. |
You can configure the Data Server through:
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:
{ "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 ConfigureServices
method of the Startup.cs
file:
public void ConfigureServices(IServiceCollection services) { // other configurations services.ConfigureFlexmonsterOptions(Configuration); // other configurations }
To configure the Data Server through code, you can use the ConfigureServices
method of the Startup.cs
class. See how to:
Step 1. Open the Startup.cs
file and find the ConfigureServices
method.
Step 2. In ConfigureServices
, call the services.Configure<DatasourceOptions>
method:
public void ConfigureServices(IServiceCollection services) { // other configurations services.Configure<DatasourceOptions>((options) => { }); // other configurations }
Step 3. Inside of services.Configure<DatasourceOptions>
, create a dictionary to store your indexes:
public void ConfigureServices(IServiceCollection services) { // other configurations services.Configure<DatasourceOptions>((options) => { options.Indexes = new Dictionary<string, IndexOptions>(); }); // other configurations }
As you can see, each index consists of two fields:
IndexOptions
field, which contains configurations needed to load the index’s data. IndexOptions
is an abstract class.Step 4. Add your index to the Indexes
dictionary. For example, let’s create a new JSON index:
public void ConfigureServices(IServiceCollection services) { // other configurations 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. See a list of these classes and their constructors:
public JsonIndexOptions(string path)
public CsvIndexOptions(string path)
public CsvIndexOptions(string path, char delimiter, char decimalSeparator, char thousandsSeparator)
public DatabaseIndexOptions(databaseType, connectionString, query)
See the full list of configurations for indexes.
Step 1. Open the Startup.cs
file and find the ConfigureServices
method.
Step 2. In ConfigureServices
, call the services.Configure<DataStorageOptions>
method:
public void ConfigureServices(IServiceCollection services) { // other configurations services.Configure<DataStorageOptions>((options) => { }); // other configurations }
Step 3. Set the needed data storage options through the options
object:
public void ConfigureServices(IServiceCollection services) { // other configurations services.Configure<DataStorageOptions>((options) => { options.CacheSizeLimit = 100; options.DataRefreshTime = 60; }); // other configurations }
See the full list of available data storage options.
If needed, you can load configs from appsettings.json
and then continue configuring the Data Server through code. It can be done by importing configs from appsettings.json
before adding configs through code:
public void ConfigureServices(IServiceCollection services) { // other configurations services.ConfigureFlexmonsterOptions(Configuration); /* Note: importing configs from the file overrides configs set through code. That’s why you should always add your configs after the services.ConfigureFlexmonsterOptions(Configuration) line */ services.Configure<DatasourceOptions>((options) => { options.Indexes = new Dictionary<string, IndexOptions>(); options.Indexes.Add("json-index", new JsonIndexOptions(“path-to-your-file.json”)); }); // other configurations }
You may be interested in the following articles: