Get Free Trial
  1. API reference
Connecting to Data Source
  1. Supported data sources
  2. Connecting to other data sources
Configuring the component
  • Documentation for older versions
  • Table of contents

    Configurations reference

    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:

    Available configurations

    The Data Server supports the following configuration properties:

    • "DataSources" – Array of objects. Options for configuring the data sources. Each object has the following properties:
      • "Type" – String. The type of the data source: "json", "csv", "database", or your custom type (for the custom parser).
      • "DatabaseType" optional – String. The type of the database: "mysql", "mssql", "postgresql", or "oracle". Only for the "database" data source type.
      • "ConnectionString" optional – String. 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, and "value" is an object. The "value" can either be null (only for the custom data source type) or have the following properties:
        • "Path" optional – String. The path to the file with data. Only for "json" and "csv" data source types.
        • "Query" optional – String. The query to execute (e.g., "SELECT * FROM tablename"). It can contain a stored procedure. Only for the "database" data source type.
        • "Delimiter" optional – String. 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" optional – String. 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" optional – String. 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" optional — String. 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" optional — Number. 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.
    • "DataStorageOptions" optional – Object. Allows configuring options for data storage. It has the following properties:
      • "DataRefreshTime" optional – Number. Defines how often the data is reloaded from a file or a database. The refresh time is set in minutes. If "DataRefreshTime" is not specified, the data will not be reloaded.
      • "CacheSizeLimit" optional – Number. 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" optional — Boolean. 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" optional – Number. 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.

    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 ConfigureServices method of the Startup.cs file:

    public void ConfigureServices(IServiceCollection services)
    {
    	// other configurations
    	services.ConfigureFlexmonsterOptions(Configuration);
    	// other configurations
    }

    Code

    To configure the Data Server through code, you can use the ConfigureServices method of the Startup.cs class. See how to:

    Create indexes

    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:

    • 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 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:

    • 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. 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.

    Both code and the file

    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
    }

    What’s next?

    You may be interested in the following articles: