|
1 | | -Imports System |
2 | | -Imports System.Web.Hosting |
3 | | -Imports DevExpress.DashboardCommon |
4 | | -Imports DevExpress.DashboardWeb |
5 | | -Imports DevExpress.DataAccess.DataFederation |
6 | | -Imports DevExpress.DataAccess.Excel |
7 | | -Imports DevExpress.DataAccess.Json |
8 | | -Imports DevExpress.DataAccess.Sql |
9 | | - |
10 | | -Namespace AspNetWebFormsDataFederation |
11 | | - |
12 | | - Public Partial Class [Default] |
13 | | - Inherits Web.UI.Page |
14 | | - |
15 | | - Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) |
16 | | - Dim dashboardFileStorage As DashboardFileStorage = New DashboardFileStorage("~/App_Data/Dashboards") |
17 | | - ASPxDashboard1.SetDashboardStorage(dashboardFileStorage) |
18 | | - ' Uncomment this string to allow end users to create new data sources based on predefined connection strings. |
19 | | - 'ASPxDashboard1.SetConnectionStringsProvider(new DevExpress.DataAccess.Web.ConfigFileConnectionStringsProvider()); |
20 | | - Dim dataSourceStorage As DataSourceInMemoryStorage = New DataSourceInMemoryStorage() |
21 | | - ' Configures an SQL data source. |
22 | | - Dim sqlDataSource As DashboardSqlDataSource = New DashboardSqlDataSource("SQL Data Source", "NWindConnectionString") |
23 | | - Dim query As SelectQuery = SelectQueryFluentBuilder.AddTable("Orders").SelectAllColumnsFromTable().Build("SQL Orders") |
24 | | - sqlDataSource.Queries.Add(query) |
25 | | - ' Configures an Object data source. |
26 | | - Dim objDataSource As DashboardObjectDataSource = New DashboardObjectDataSource("Object Data Source") |
27 | | - objDataSource.DataId = "odsInvoices" |
28 | | - ' Configures an Excel data source. |
29 | | - Dim excelDataSource As DashboardExcelDataSource = New DashboardExcelDataSource("Excel Data Source") |
30 | | - excelDataSource.ConnectionName = "excelSales" |
31 | | - excelDataSource.FileName = HostingEnvironment.MapPath("~/App_Data/SalesPerson.xlsx") |
32 | | - excelDataSource.SourceOptions = New ExcelSourceOptions(New ExcelWorksheetSettings("Data")) |
33 | | - ' Configures a JSON data source. |
34 | | - Dim jsonDataSource As DashboardJsonDataSource = New DashboardJsonDataSource("JSON Data Source") |
35 | | - jsonDataSource.ConnectionName = "jsonCategories" |
36 | | - Dim fileUri As Uri = New Uri(HostingEnvironment.MapPath("~/App_Data/Categories.json"), UriKind.RelativeOrAbsolute) |
37 | | - jsonDataSource.JsonSource = New UriJsonSource(fileUri) |
38 | | - ' Registers a Federated data source. |
39 | | - dataSourceStorage.RegisterDataSource("federatedDataSource", CreateFederatedDataSource(sqlDataSource, excelDataSource, objDataSource, jsonDataSource).SaveToXml()) |
40 | | - ASPxDashboard1.SetDataSourceStorage(dataSourceStorage) |
41 | | - End Sub |
42 | | - |
43 | | - Protected Sub ASPxDashboard1_ConfigureDataConnection(ByVal sender As Object, ByVal e As ConfigureDataConnectionWebEventArgs) |
44 | | - If Equals(e.ConnectionName, "excelSales") Then |
45 | | - TryCast(e.ConnectionParameters, ExcelDataSourceConnectionParameters).FileName = HostingEnvironment.MapPath("~/App_Data/SalesPerson.xlsx") |
46 | | - ElseIf Equals(e.ConnectionName, "jsonCategories") Then |
47 | | - e.ConnectionParameters = New JsonSourceConnectionParameters() With {.JsonSource = New UriJsonSource(New Uri(HostingEnvironment.MapPath("~/App_Data/Categories.json"), UriKind.RelativeOrAbsolute))} |
48 | | - End If |
49 | | - End Sub |
50 | | - |
51 | | - Protected Sub DataLoading(ByVal sender As Object, ByVal e As DataLoadingWebEventArgs) |
52 | | - If Equals(e.DataId, "odsInvoices") Then |
53 | | - e.Data = Invoices.CreateData() |
54 | | - End If |
55 | | - End Sub |
56 | | - |
57 | | - Private Shared Function CreateFederatedDataSource(ByVal sqlDS As DashboardSqlDataSource, ByVal excelDS As DashboardExcelDataSource, ByVal objDS As DashboardObjectDataSource, ByVal jsonDS As DashboardJsonDataSource) As DashboardFederationDataSource |
58 | | - Dim federationDataSource As DashboardFederationDataSource = New DashboardFederationDataSource("Federated Data Source") |
59 | | - Dim sqlSource As Source = New Source("sqlSource", sqlDS, "SQL Orders") |
60 | | - Dim excelSource As Source = New Source("excelSource", excelDS, "") |
61 | | - Dim objectSource As Source = New Source("objectSource", objDS, "") |
62 | | - Dim jsonSourceNode As SourceNode = New SourceNode(New Source("json", jsonDS, "")) |
63 | | - ' Join |
64 | | - Dim joinQuery As SelectNode = sqlSource.From().Select("OrderDate", "ShipCity", "ShipCountry").Join(excelSource, "[excelSource.OrderID] = [sqlSource.OrderID]").Select("CategoryName", "ProductName", "Extended Price").Join(objectSource, "[objectSource.Country] = [excelSource.Country]").Select("Country", "UnitPrice").Build("Join query") |
65 | | - federationDataSource.Queries.Add(joinQuery) |
66 | | - ' Union and UnionAll |
67 | | - Dim queryUnionAll As UnionNode = sqlSource.From().Select("OrderID", "OrderDate").Build("OrdersSqlite").UnionAll(excelSource.From().Select("OrderID", "OrderDate").Build("OrdersExcel")).Build("OrdersUnionAll") |
68 | | - queryUnionAll.Alias = "Union query" |
69 | | - Dim queryUnion As UnionNode = sqlSource.From().Select("OrderID", "OrderDate").Build("OrdersSqlite").Union(excelSource.From().Select("OrderID", "OrderDate").Build("OrdersExcel")).Build("OrdersUnion") |
70 | | - queryUnion.Alias = "UnionAll query" |
71 | | - federationDataSource.Queries.Add(queryUnionAll) |
72 | | - federationDataSource.Queries.Add(queryUnion) |
73 | | - ' Transformation |
74 | | - Dim unfoldNode As TransformationNode = New TransformationNode(jsonSourceNode) With {.[Alias] = "Unfold"} |
75 | | - Dim unfoldFlattenNode As TransformationNode = New TransformationNode(jsonSourceNode) With {.[Alias] = "Unfold and Flatten"} |
76 | | - federationDataSource.Queries.Add(unfoldNode) |
77 | | - federationDataSource.Queries.Add(unfoldFlattenNode) |
78 | | - Return federationDataSource |
79 | | - End Function |
80 | | - End Class |
81 | | -End Namespace |
| 1 | +Imports System |
| 2 | +Imports System.Web.Hosting |
| 3 | +Imports DevExpress.DashboardCommon |
| 4 | +Imports DevExpress.DashboardWeb |
| 5 | +Imports DevExpress.DataAccess.DataFederation |
| 6 | +Imports DevExpress.DataAccess.Excel |
| 7 | +Imports DevExpress.DataAccess.Json |
| 8 | +Imports DevExpress.DataAccess.Sql |
| 9 | + |
| 10 | +Namespace AspNetWebFormsDataFederation |
| 11 | + |
| 12 | + Public Partial Class [Default] |
| 13 | + Inherits Web.UI.Page |
| 14 | + |
| 15 | + Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) |
| 16 | + Dim dashboardFileStorage As DashboardFileStorage = New DashboardFileStorage("~/App_Data/Dashboards") |
| 17 | + ASPxDashboard1.SetDashboardStorage(dashboardFileStorage) |
| 18 | + ' Uncomment this string to allow end users to create new data sources based on predefined connection strings. |
| 19 | + 'ASPxDashboard1.SetConnectionStringsProvider(new DevExpress.DataAccess.Web.ConfigFileConnectionStringsProvider()); |
| 20 | + Dim dataSourceStorage As DataSourceInMemoryStorage = New DataSourceInMemoryStorage() |
| 21 | + ' Configures an SQL data source. |
| 22 | + Dim sqlDataSource As DashboardSqlDataSource = New DashboardSqlDataSource("SQL Data Source", "NWindConnectionString") |
| 23 | + Dim query As SelectQuery = SelectQueryFluentBuilder.AddTable("Orders").SelectAllColumnsFromTable().Build("SQL Orders") |
| 24 | + sqlDataSource.Queries.Add(query) |
| 25 | + ' Configures an Object data source. |
| 26 | + Dim objDataSource As DashboardObjectDataSource = New DashboardObjectDataSource("Object Data Source") |
| 27 | + objDataSource.DataId = "odsInvoices" |
| 28 | + ' Configures an Excel data source. |
| 29 | + Dim excelDataSource As DashboardExcelDataSource = New DashboardExcelDataSource("Excel Data Source") |
| 30 | + excelDataSource.ConnectionName = "excelSales" |
| 31 | + excelDataSource.FileName = HostingEnvironment.MapPath("~/App_Data/SalesPerson.xlsx") |
| 32 | + excelDataSource.SourceOptions = New ExcelSourceOptions(New ExcelWorksheetSettings("Data")) |
| 33 | + ' Configures a JSON data source. |
| 34 | + Dim jsonDataSource As DashboardJsonDataSource = New DashboardJsonDataSource("JSON Data Source") |
| 35 | + jsonDataSource.ConnectionName = "jsonCategories" |
| 36 | + Dim fileUri As Uri = New Uri(HostingEnvironment.MapPath("~/App_Data/Categories.json"), UriKind.RelativeOrAbsolute) |
| 37 | + jsonDataSource.JsonSource = New UriJsonSource(fileUri) |
| 38 | + ' Registers a Federated data source. |
| 39 | + dataSourceStorage.RegisterDataSource("federatedDataSource", CreateFederatedDataSource(sqlDataSource, excelDataSource, objDataSource, jsonDataSource).SaveToXml()) |
| 40 | + ASPxDashboard1.SetDataSourceStorage(dataSourceStorage) |
| 41 | + End Sub |
| 42 | + |
| 43 | + Protected Sub ASPxDashboard1_ConfigureDataConnection(ByVal sender As Object, ByVal e As ConfigureDataConnectionWebEventArgs) |
| 44 | + If Equals(e.ConnectionName, "excelSales") Then |
| 45 | + TryCast(e.ConnectionParameters, ExcelDataSourceConnectionParameters).FileName = HostingEnvironment.MapPath("~/App_Data/SalesPerson.xlsx") |
| 46 | + ElseIf Equals(e.ConnectionName, "jsonCategories") Then |
| 47 | + e.ConnectionParameters = New JsonSourceConnectionParameters() With {.JsonSource = New UriJsonSource(New Uri(HostingEnvironment.MapPath("~/App_Data/Categories.json"), UriKind.RelativeOrAbsolute))} |
| 48 | + End If |
| 49 | + End Sub |
| 50 | + |
| 51 | + Protected Sub DataLoading(ByVal sender As Object, ByVal e As DataLoadingWebEventArgs) |
| 52 | + If Equals(e.DataId, "odsInvoices") Then |
| 53 | + e.Data = Invoices.CreateData() |
| 54 | + End If |
| 55 | + End Sub |
| 56 | + |
| 57 | + Private Shared Function CreateFederatedDataSource(ByVal sqlDS As DashboardSqlDataSource, ByVal excelDS As DashboardExcelDataSource, ByVal objDS As DashboardObjectDataSource, ByVal jsonDS As DashboardJsonDataSource) As DashboardFederationDataSource |
| 58 | + Dim federationDataSource As DashboardFederationDataSource = New DashboardFederationDataSource("Federated Data Source") |
| 59 | + Dim sqlSource As Source = New Source("sqlSource", sqlDS, "SQL Orders") |
| 60 | + Dim excelSource As Source = New Source("excelSource", excelDS, "") |
| 61 | + Dim objectSource As Source = New Source("objectSource", objDS, "") |
| 62 | + Dim jsonSourceNode As SourceNode = New SourceNode(New Source("json", jsonDS, "")) |
| 63 | + ' Join |
| 64 | + Dim joinQuery As SelectNode = sqlSource.From().Select("OrderDate", "ShipCity", "ShipCountry").Join(excelSource, "[excelSource.OrderID] = [sqlSource.OrderID]").Select("CategoryName", "ProductName", "Extended Price").Join(objectSource, "[objectSource.Country] = [excelSource.Country]").Select("Country", "UnitPrice").Build("Join query") |
| 65 | + federationDataSource.Queries.Add(joinQuery) |
| 66 | + ' Union and UnionAll |
| 67 | + Dim queryUnionAll As UnionNode = sqlSource.From().Select("OrderID", "OrderDate").Build("OrdersSqlite").UnionAll(excelSource.From().Select("OrderID", "OrderDate").Build("OrdersExcel")).Build("OrdersUnionAll") |
| 68 | + queryUnionAll.Alias = "Union query" |
| 69 | + Dim queryUnion As UnionNode = sqlSource.From().Select("OrderID", "OrderDate").Build("OrdersSqlite").Union(excelSource.From().Select("OrderID", "OrderDate").Build("OrdersExcel")).Build("OrdersUnion") |
| 70 | + queryUnion.Alias = "UnionAll query" |
| 71 | + federationDataSource.Queries.Add(queryUnionAll) |
| 72 | + federationDataSource.Queries.Add(queryUnion) |
| 73 | + ' Transformation |
| 74 | + Dim unfoldNode As TransformationNode = New TransformationNode(jsonSourceNode) With {.[Alias] = "Unfold"} |
| 75 | + Dim unfoldFlattenNode As TransformationNode = New TransformationNode(jsonSourceNode) With {.[Alias] = "Unfold and Flatten"} |
| 76 | + federationDataSource.Queries.Add(unfoldNode) |
| 77 | + federationDataSource.Queries.Add(unfoldFlattenNode) |
| 78 | + Return federationDataSource |
| 79 | + End Function |
| 80 | + End Class |
| 81 | +End Namespace |
0 commit comments