Back to Devexpress

ExtractDriverStorage Class

dashboard-devexpress-dot-dashboardcommon-a4fc6483.md

latest11.5 KB
Original Source

ExtractDriverStorage Class

A storage of drivers used to manage writing/reading operations for data extracts.

Namespace : DevExpress.DashboardCommon

Assembly : DevExpress.Dashboard.v25.2.Core.dll

NuGet Package : DevExpress.Dashboard.Core

Declaration

csharp
public static class ExtractDriverStorage
vb
Public Module ExtractDriverStorage

Remarks

By default, the DashboardExtractDataSource stores data within a file. If necessary, you add a custom logic for writing/reading extract data by implementing the ICustomExtractDriver interface. After you have implemented a custom driver, you can use it in two ways.

Example

The following example demonstrates how to create a custom driver to encrypt/decrypt extract data. It implements the ICustomExtractDriver interface:

csharp
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();
        }
    }
}
csharp
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;
        }
    }
}
vb
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
vb
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

Inheritance

Object ExtractDriverStorage

See Also

ExtractDriverStorage Members

ICustomExtractDriver

DevExpress.DashboardCommon Namespace