Skip to main content

IDataSourceStorage Interface

When implemented by a class, represents a storage of the dashboard data sources.

Namespace: DevExpress.DashboardWeb

Assembly: DevExpress.Dashboard.v24.1.Web.dll

NuGet Package: DevExpress.Web.Dashboard.Common

Declaration

public interface IDataSourceStorage

Remarks

To create storage of the dashboard data sources available in the Web Dashboard’s UI, call the ASPxDashboard.SetDataSourceStorage / DashboardConfigurator.SetDataSourceStorage method. You can use the in-memory storage (DataSourceInMemoryStorage) or you can implement the IDataSourceStorage interface to create a custom data source storage. Review the following topic for more information: Manage Multi-Tenancy.

Note

Note that data sources created by end-users do not fall into IDataSourceStorage.

The following example illustrates how to configure the Dashboard control for a multi-user environment:

View Example

using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using DevExpress.DataAccess.Json;
using DevExpress.DataAccess.Sql;
using System.Web;

public class CustomDataSourceStorage : IDataSourceStorage {
    private Dictionary<string, XDocument> documents = new Dictionary<string, XDocument>();

    private const string sqlDataSourceId1 = "SQL Data Source (Northwind)";
    private const string sqlDataSourceId2 = "SQL Data Source (CarsXtraScheduling)";
    private const string jsonDataSourceId = "JSON Data Source";

    public CustomDataSourceStorage() {
        DashboardSqlDataSource sqlDataSource1 = new DashboardSqlDataSource(sqlDataSourceId1, "NorthwindConnectionString");
        SelectQuery query1 = SelectQueryFluentBuilder
            .AddTable("Categories")
            .SelectAllColumnsFromTable()
            .Build("Categories");
        sqlDataSource1.Queries.Add(query1);
        SelectQuery query2 = SelectQueryFluentBuilder
            .AddTable("Products")
            .SelectAllColumnsFromTable()
            .Build("Products");
        sqlDataSource1.Queries.Add(query2);

        DashboardSqlDataSource sqlDataSource2 = new DashboardSqlDataSource(sqlDataSourceId2, "CarsXtraSchedulingConnectionString");
        SelectQuery query = SelectQueryFluentBuilder
            .AddTable("Cars")
            .SelectAllColumnsFromTable()
            .Build("Cars");
        sqlDataSource2.Queries.Add(query);

        DashboardJsonDataSource jsonDataSource = new DashboardJsonDataSource(jsonDataSourceId);
        jsonDataSource.JsonSource = new UriJsonSource(new Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"));
        jsonDataSource.RootElement = "Customers";

        documents[sqlDataSourceId1] = new XDocument(sqlDataSource1.SaveToXml());
        documents[sqlDataSourceId2] = new XDocument(sqlDataSource2.SaveToXml());
        documents[jsonDataSourceId] = new XDocument(jsonDataSource.SaveToXml());
    }

    public XDocument GetDataSource(string dataSourceID) {
        if (GetDataSourcesID().Contains(dataSourceID)) {
            return documents[dataSourceID];
        }
        else {
            throw new ApplicationException("You are not authorized to use this datasource.");
        }
    }

    public IEnumerable<string> GetDataSourcesID() {
        var userName = (string)HttpContext.Current.Session["CurrentUser"];

        if (userName == "Admin") {
            return documents.Keys;
        }
        else if (userName == "User") {
            return new string[] { sqlDataSourceId2 };
        }
        else {
            return new string[0];
        }
    }
}
See Also