Giter Site home page Giter Site logo

devexpress-examples / web-forms-dashboard-extract-data-source Goto Github PK

View Code? Open in Web Editor NEW
0.0 57.0 2.0 862 KB

This example shows basic approaches and code snippets to bind the ASPxDashboard control to the DashboardExtractDataSource.

License: Other

C# 39.58% ASP.NET 20.42% Visual Basic .NET 40.00%
dotnet web-forms-dashboard business-intelligence analytics asp-net-web-forms web-dashboard dashboard-for-web-forms extract

web-forms-dashboard-extract-data-source's Introduction

Dashboard for Web Forms - How to Work with a Data Extract

This example demonstrates basic approaches and code snippets that can be used to bind the ASPxDashboard control to the DashboardExtractDataSource.

The Extract Data Source improves performance when a complex query or a stored procedure takes a significant amount of time to get data from a database.

The DashboardExtractDataSource class implements the Extract Data Source concept, and allows you to request data once and save it in the compressed and optimized form to a file. Subsequently, an application can retrieve data from that file or create a new file when data is updated.

The code snippet below creates the DashboardExtractDataSource and connects it to the DashboardSqlDataSource instance. The DbCommandTimeout property is set to 600 to increase the query timeout.

DashboardSqlDataSource nwindDataSource = new DashboardSqlDataSource("Northwind Invoices", "nwindConnection");
SelectQuery invoicesQuery = SelectQueryFluentBuilder
	.AddTable("Invoices")
	.SelectColumns("City", "Country", "Salesperson", "OrderDate", "Shippers.CompanyName", "ProductName", "UnitPrice", "Quantity", "Discount", "ExtendedPrice", "Freight")
	.Build("Invoices");
nwindDataSource.Queries.Add(invoicesQuery);
nwindDataSource.ConnectionOptions.DbCommandTimeout = 600;

DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource("Invoices Extract Data Source");
extractDataSource.ExtractSourceOptions.DataSource = nwindDataSource;
extractDataSource.ExtractSourceOptions.DataMember = "Invoices";
extractDataSource.FileName = extractFileName;

To set the correct extract file name for loaded dashboards, handle the ASPxDashboard.ConfigureDataConnection event:

protected void ASPxDashboard1_ConfigureDataConnection(object sender, ConfigureDataConnectionWebEventArgs e) {
	ExtractDataSourceConnectionParameters extractCP = e.ConnectionParameters as ExtractDataSourceConnectionParameters;
	if (extractCP != null) {
		extractCP.FileName = extractFileName;
	}
}

To add the data source to the ASPxDashboard control use the solution described in the Register Default Data Sources help topic:

DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
dataSourceStorage.RegisterDataSource("extractDataSource", GetExtractDataSource().SaveToXml());
ASPxDashboard1.SetDataSourceStorage(dataSourceStorage);

To create a data extract file when the dashboard is loaded for the first time, use the following code:

if (!File.Exists(extractFileName)) {
     using (var ds = CreateExtractDataSource()) {
         ds.UpdateExtractFile();
     }
}

To update the data extract file and load the updated data in ASPxDashboard, send an AJAX request to the server and call the DashboardExtractDataSource.UpdateFile method there. Once a new file is created on the server, you can return the callback back to the client and call the ASPxClientDashboard.ReloadData method to reload the control with new data:

function UpdateExtractDataSource() {
    $.ajax({
	url: "Default.aspx/UpdateExtractDataSource",
	type: "POST",
	data: {},
	contentType: "application/json; charset=utf-8"
    }).then(function (result) {
	dashboard.ReloadData();
	DevExpress.ui.notify(result.d, "success", 5000);
    }, function () {
	DevExpress.ui.notify("We could not update extract data source.", "error", 2000)
    });
}
[WebMethod]
public static string UpdateExtractDataSource() {
    DashboardExtractDataSource ds = CreateExtractDataSource();
    StringBuilder sb = new StringBuilder("We updated your extract data source. ");
    var task = DashboardExtractDataSource.UpdateFile(ds,
	(fileName, result) => {
	    sb.AppendLine($"{DateTime.Now.ToString("T")} - Data Updated - {result} - {Path.GetFileName(fileName)}. ");
	},
	(fileName, result) => {
	    sb.AppendLine($"{DateTime.Now.ToString("T")} - File Updated - {result} - {Path.GetFileName(fileName)}. ");
	});
    // Wait until the data is refreshed in the Extract Data Source.
    task.Wait();
    return sb.ToString();
}

In this example, click a button to extract data. However, in a real-life application, this solution can be insufficient (for example, the site may be deployed to the web farm server). We recommend that you create a separate windows service that updates data automatically every hour or every day.

Files to Look At

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

web-forms-dashboard-extract-data-source's People

Contributors

alexanderkovalenko avatar briandx avatar devexpressexamplebot avatar konstantinkhrupachev avatar natakazakova avatar sergeynakhankov avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.