Prepare a Dashboard Storage
- 3 minutes to read
The Web Dashboard requires creating a special storage used to keep dashboards. End-users can save new dashboards to this storage and access existing dashboards from it.
The following storage types are available:
To create a storage that contains dashboards, pass the required storage instance to the static DashboardConfigurator.SetDashboardStorage method as a parameter.
In-Memory Storage
In-memory dashboard storage is used for storing dashboards by default. The Web Dashboard uses the DashboardInMemoryStorage by default if you do not create a storage.
Use the following method overload to specify in-memory storage:
The following code snippet shows how to set in-memory storage for dashboards:
public void ConfigureServices(IServiceCollection services) {
services
.AddMvc()
.AddDefaultDashboardController((configurator, serviceProvider) => {
// ...
configurator.SetDataSourceStorage(new DataSourceInMemoryStorage());
});
// ...
}
File Storage
File dashboard storage is used to store dashboards in a file system.
Use the following method overload to specify file storage:
The following code snippet shows how to use the App_Data/Dashboards project’s folder to store dashboards in a file system:
public void ConfigureServices(IServiceCollection services) {
services
.AddMvc()
.AddDefaultDashboardController((configurator, serviceProvider) => {
// ...
configurator.SetDashboardStorage(new DashboardFileStorage(Path.Combine(Env.ContentRootPath, "App_Data", "Dashboards")));
});
// ...
}
Custom Storage
You can provide custom logic for managing dashboards by implementing the IDashboardStorage or IEditableDashboardStorage interfaces that provide an API used to manage dashboards:
- The IDashboardStorage.GetAvailableDashboardsInfo method returns information about stored dashboards.
- The IDashboardStorage.LoadDashboard/IDashboardStorage.LoadDashboard methods allows you to load/save the dashboard from/to the storage.
- The IEditableDashboardStorage.AddDashboard method allows you to add a new dashboard to the storage.
Use the following method overload to specify custom storage:
- DashboardConfigurator.SetDashboardStorage(IEditableDashboardStorage)
- DashboardConfigurator.SetDashboardStorage(IDashboardStorage)
The following example shows how to create custom dashboard storage for a Web Dashboard by implementing the IEditableDashboardStorage interface. In this example, a DataSet is used as in-memory dashboard storage. This DataSet can be used later to save dashboards in the database using DataAdapter.
static CustomDashboardStorage dashboardStorage = new CustomDashboardStorage();
public void ConfigureServices(IServiceCollection services) {
services
.AddMvc()
.AddDefaultDashboardController((configurator, serviceProvider) => {
// ...
configurator.SetDashboardStorage(dashboardStorage );
});
// ...
}