ICustomExtractDriver Interface
When implemented, represents a custom driver used to write data to/read data from a data extract.
Namespace: DevExpress.DashboardCommon
Assembly: DevExpress.Dashboard.v24.2.Core.dll
Declaration
Remarks
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.
- ICustomExtractDriver.CreateWriteSession - creates a session used to write data to an extract. This method returns an object implementing a IDriverWriteSession, which allows you to access and change extract pages.
- ICustomExtractDriver.CreateReadSession - creates a session used to read data from the data extract. This method returns a IDriverReadSession, which allows you to obtain extract page identifiers and corresponding pages. Thus, use a IDriverReadSession to implement a custom logic for reading data extracts created using FileExtractDriver.CreateWriteSession.
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.
Example
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();
}
}
}