dashboard-devexpress-dot-dashboardcommon-2892e75c.md
When implemented, represents a custom driver used to write data to/read data from a data extract.
Namespace : DevExpress.DashboardCommon
Assembly : DevExpress.Dashboard.v25.2.Core.dll
NuGet Package : DevExpress.Dashboard.Core
public interface ICustomExtractDriver
Public Interface ICustomExtractDriver
The following members return ICustomExtractDriver objects:
ICustomExtractDriver allows you to implement a custom logic for writing/reading data extracts (DashboardExtractDataSource). To facilitate these operations, a data extract is divided into special chunks called pages. Each page within a data extract can be accessed by a unique identifier (GUID).
The ICustomExtractDriver interface exposes two methods to be implemented.
After you have implemented a custom driver, you can substitute a default extract driver using the ExtractDriverStorage.DefaultDriver property. In this case, a new driver will be used for all data extracts. As an alternative, you can use a new driver for the specific data extract. To do this, register a custom driver within the ExtractDriverStorage by calling the ExtractDriverStorage.RegisterCustomDriver method. Then, assign the name of this driver to the DashboardExtractDataSource.DriverName property.
The following example demonstrates how to create a custom driver to encrypt/decrypt extract data. It implements the ICustomExtractDriver interface:
The ICustomExtractDriver.CreateWriteSession method creates a write session that is used to encrypt extract pages.
The ICustomExtractDriver.CreateReadSession method creates a read session that provides logic for reading encrypted pages.
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using DevExpress.DashboardCommon;
namespace Dashboard_CustomExtractDriver {
public class ExtractEncryptionDriver : ICustomExtractDriver {
public IDriverReadSession CreateReadSession(string resourceName) {
return new EncryptionReadSession(FileExtractDriver.Instance.CreateReadSession(resourceName));
}
public IDriverWriteSession CreateWriteSession(string resourceName) {
return new EncryptionWriteSession(FileExtractDriver.Instance.CreateWriteSession(resourceName));
}
}
public class EncryptionWriteSession : IDriverWriteSession {
IDriverWriteSession writeSession;
public EncryptionWriteSession(IDriverWriteSession writeSession) {
this.writeSession = writeSession;
}
public void Dispose() {
writeSession.Dispose();
}
public void SetPage(Guid pageID, byte[] data) {
writeSession.SetPage(pageID, Encrypt(data));
}
byte[] Encrypt(byte[] page) {
byte[] entropy = { 1, 2, 3 };
byte[] encryptedPage = ProtectedData.Protect(page, entropy, DataProtectionScope.CurrentUser);
return encryptedPage;
}
}
public class EncryptionReadSession : IDriverReadSession {
IDriverReadSession readSession;
public EncryptionReadSession(IDriverReadSession readSession) {
this.readSession = readSession;
}
public void Dispose() {
readSession.Dispose();
}
byte[] Decrypt(byte[] page) {
byte[] entropy = { 1, 2, 3 };
byte[] decryptedPage = ProtectedData.Unprotect(page, entropy, DataProtectionScope.CurrentUser);
return decryptedPage;
}
public byte[] GetPage(Guid pageID) {
return Decrypt(readSession.GetPage(pageID));
}
public IEnumerable<Guid> GetPageIDs() {
return readSession.GetPageIDs();
}
}
}
using DevExpress.DashboardCommon;
using DevExpress.DataAccess.Excel;
using DevExpress.XtraEditors;
using System;
namespace Dashboard_CustomExtractDriver
{
public partial class Form1 : XtraForm {
const string extractFileNamePattern = "\"Extract_\"yyyyMMddHHmmssfff\".dat\"";
public Form1()
{
InitializeComponent();
ExtractDriverStorage.DefaultDriver = new ExtractEncryptionDriver();
DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource();
extractDataSource.ExtractSourceOptions.DataSource = CreateExcelDataSource();
extractDataSource.FileName = DateTime.Now.ToString(extractFileNamePattern);
extractDataSource.UpdateExtractFile();
dashboardViewer1.Dashboard = CreateDashboard(extractDataSource);
}
private static Dashboard CreateDashboard(DashboardExtractDataSource extractDataSource)
{
Dashboard dashboard = new Dashboard();
dashboard.DataSources.Add(extractDataSource);
PivotDashboardItem pivot = new PivotDashboardItem();
pivot.DataSource = extractDataSource;
pivot.Values.AddRange(new Measure("Extended Price"), new Measure("Quantity"));
pivot.Columns.Add(new Dimension("OrderDate", DateTimeGroupInterval.Year));
pivot.Rows.Add(new Dimension("ProductName"));
dashboard.Items.Add(pivot);
return dashboard;
}
private static DashboardExcelDataSource CreateExcelDataSource()
{
DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource()
{
FileName = @"Data\SalesPerson.xlsx",
SourceOptions = new ExcelSourceOptions()
{
ImportSettings = new ExcelWorksheetSettings("Data")
}
};
excelDataSource.Fill();
return excelDataSource;
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Security.Cryptography
Imports DevExpress.DashboardCommon
Namespace Dashboard_CustomExtractDriver
Public Class ExtractEncryptionDriver
Implements ICustomExtractDriver
Public Function CreateReadSession(ByVal resourceName As String) As IDriverReadSession Implements ICustomExtractDriver.CreateReadSession
Return New EncryptionReadSession(FileExtractDriver.Instance.CreateReadSession(resourceName))
End Function
Public Function CreateWriteSession(ByVal resourceName As String) As IDriverWriteSession Implements ICustomExtractDriver.CreateWriteSession
Return New EncryptionWriteSession(FileExtractDriver.Instance.CreateWriteSession(resourceName))
End Function
End Class
Public Class EncryptionWriteSession
Implements IDriverWriteSession
Private writeSession As IDriverWriteSession
Public Sub New(ByVal writeSession As IDriverWriteSession)
Me.writeSession = writeSession
End Sub
Public Sub Dispose() Implements System.IDisposable.Dispose
writeSession.Dispose()
End Sub
Public Sub SetPage(ByVal pageID As Guid, ByVal data() As Byte) Implements IDriverWriteSession.SetPage
writeSession.SetPage(pageID, Encrypt(data))
End Sub
Private Function Encrypt(ByVal page() As Byte) As Byte()
Dim entropy() As Byte = { 1, 2, 3 }
Dim encryptedPage() As Byte = ProtectedData.Protect(page, entropy, DataProtectionScope.CurrentUser)
Return encryptedPage
End Function
End Class
Public Class EncryptionReadSession
Implements IDriverReadSession
Private readSession As IDriverReadSession
Public Sub New(ByVal readSession As IDriverReadSession)
Me.readSession = readSession
End Sub
Public Sub Dispose() Implements System.IDisposable.Dispose
readSession.Dispose()
End Sub
Private Function Decrypt(ByVal page() As Byte) As Byte()
Dim entropy() As Byte = { 1, 2, 3 }
Dim decryptedPage() As Byte = ProtectedData.Unprotect(page, entropy, DataProtectionScope.CurrentUser)
Return decryptedPage
End Function
Public Function GetPage(ByVal pageID As Guid) As Byte() Implements IDriverReadSession.GetPage
Return Decrypt(readSession.GetPage(pageID))
End Function
Public Function GetPageIDs() As IEnumerable(Of Guid) Implements IDriverReadSession.GetPageIDs
Return readSession.GetPageIDs()
End Function
End Class
End Namespace
Imports DevExpress.DashboardCommon
Imports DevExpress.DataAccess.Excel
Imports DevExpress.XtraEditors
Imports System
Namespace Dashboard_CustomExtractDriver
Partial Public Class Form1
Inherits XtraForm
Private Const extractFileNamePattern As String = """Extract_""yyyyMMddHHmmssfff"".dat"""
Public Sub New()
InitializeComponent()
ExtractDriverStorage.DefaultDriver = New ExtractEncryptionDriver()
Dim extractDataSource As New DashboardExtractDataSource()
extractDataSource.ExtractSourceOptions.DataSource = CreateExcelDataSource()
extractDataSource.FileName = Date.Now.ToString(extractFileNamePattern)
extractDataSource.UpdateExtractFile()
dashboardViewer1.Dashboard = CreateDashboard(extractDataSource)
End Sub
Private Shared Function CreateDashboard(ByVal extractDataSource As DashboardExtractDataSource) As Dashboard
Dim dashboard As New Dashboard()
dashboard.DataSources.Add(extractDataSource)
Dim pivot As New PivotDashboardItem()
pivot.DataSource = extractDataSource
pivot.Values.AddRange(New Measure("Extended Price"), New Measure("Quantity"))
pivot.Columns.Add(New Dimension("OrderDate", DateTimeGroupInterval.Year))
pivot.Rows.Add(New Dimension("ProductName"))
dashboard.Items.Add(pivot)
Return dashboard
End Function
Private Shared Function CreateExcelDataSource() As DashboardExcelDataSource
Dim excelDataSource As New DashboardExcelDataSource() With {
.FileName = "Data\SalesPerson.xlsx", .SourceOptions = New ExcelSourceOptions() With {.ImportSettings = New ExcelWorksheetSettings("Data")}
}
excelDataSource.Fill()
Return excelDataSource
End Function
End Class
End Namespace
See Also