Skip to content

Commit 0dc41cf

Browse files
committed
update cs solution
1 parent 826ccba commit 0dc41cf

12 files changed

+114
-145
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
23
<PropertyGroup>
3-
<TargetFramework>net6</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RootNamespace>asp_net_core_server</RootNamespace>
48
</PropertyGroup>
9+
510
<ItemGroup>
6-
<PackageReference Include="DevExpress.AspNetCore.Dashboard" Version="22.2.2" />
11+
<PackageReference Include="DevExpress.AspNetCore.Dashboard" Version="23.2.*-*" />
12+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
713
</ItemGroup>
14+
815
</Project>
916

Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31424.327
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32929.385
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCoreDashboardBackend", "AspNetCoreDashboardBackend.csproj", "{6F34FBA6-07A1-4069-B8DD-04329B30CCA9}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCoreDashboardBackend", "AspNetCoreDashboardBackend.csproj", "{C8AA0760-B20C-4F63-AAB3-959A7A4BE740}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
1111
Release|Any CPU = Release|Any CPU
1212
EndGlobalSection
1313
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{6F34FBA6-07A1-4069-B8DD-04329B30CCA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15-
{6F34FBA6-07A1-4069-B8DD-04329B30CCA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16-
{6F34FBA6-07A1-4069-B8DD-04329B30CCA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17-
{6F34FBA6-07A1-4069-B8DD-04329B30CCA9}.Release|Any CPU.Build.0 = Release|Any CPU
14+
{C8AA0760-B20C-4F63-AAB3-959A7A4BE740}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C8AA0760-B20C-4F63-AAB3-959A7A4BE740}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C8AA0760-B20C-4F63-AAB3-959A7A4BE740}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C8AA0760-B20C-4F63-AAB3-959A7A4BE740}.Release|Any CPU.Build.0 = Release|Any CPU
1818
EndGlobalSection
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode = FALSE
2121
EndGlobalSection
2222
GlobalSection(ExtensibilityGlobals) = postSolution
23-
SolutionGuid = {F9D49D45-6E1E-4F46-A27D-EDB1068C68AF}
23+
SolutionGuid = {15ED6E2B-FDE2-4DEB-A6BB-498DE2052884}
2424
EndGlobalSection
2525
EndGlobal

asp-net-core-server/App_Data/Dashboards/support.xml renamed to asp-net-core-server/Data/Dashboards/support.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</Node>
1616
</Schema>
1717
</JsonDataSource>
18-
<JsonDataSource Name="Categories" RootElement="Products" ComponentName="jsonDataSource2">
18+
<JsonDataSource Name="Categories" RootElement="Products" ComponentName="jsonDataSource2" ConnectionName="jsonCategories">
1919
<Source SourceType="DevExpress.DataAccess.Json.UriJsonSource" />
2020
<Schema>
2121
<Node Name="root" Type="System.Object" Selected="true" NodeType="Object">

asp-net-core-server/App_Data/Categories.json renamed to asp-net-core-server/Data/categories.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,4 @@
164164

165165
}
166166
]
167-
}
167+
}

asp-net-core-server/DefaultDashboardController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace AspNetCoreDashboardBackend {
66
public class DefaultDashboardController : DashboardController {
7-
public DefaultDashboardController(DashboardConfigurator configurator, IDataProtectionProvider dataProtectionProvider = null)
7+
public DefaultDashboardController(DashboardConfigurator configurator, IDataProtectionProvider? dataProtectionProvider)
88
: base(configurator, dataProtectionProvider) {
99
}
1010
}

asp-net-core-server/Program.cs

+81-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,83 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Hosting;
6-
using Microsoft.Extensions.Configuration;
7-
using Microsoft.Extensions.Hosting;
8-
using Microsoft.Extensions.Logging;
9-
10-
namespace AspNetCoreDashboardBackend {
11-
public class Program {
12-
public static void Main(string[] args) {
13-
CreateHostBuilder(args).Build().Run();
14-
}
15-
16-
public static IHostBuilder CreateHostBuilder(string[] args) =>
17-
Host.CreateDefaultBuilder(args)
18-
.ConfigureWebHostDefaults(webBuilder => {
19-
webBuilder.UseStartup<Startup>();
20-
});
1+
using DevExpress.DashboardAspNetCore;
2+
using DevExpress.DashboardWeb.Native;
3+
using DevExpress.DashboardWeb;
4+
using Microsoft.Extensions.FileProviders;
5+
using DevExpress.AspNetCore;
6+
using DevExpress.DashboardCommon;
7+
using DevExpress.DataAccess.Json;
8+
9+
var builder = WebApplication.CreateBuilder(args);
10+
11+
IFileProvider? fileProvider = builder.Environment.ContentRootFileProvider;
12+
IConfiguration? configuration = builder.Configuration;
13+
14+
// Configures CORS policies.
15+
builder.Services.AddCors(options => {
16+
options.AddPolicy("CorsPolicy", builder => {
17+
builder.AllowAnyOrigin();
18+
builder.AllowAnyMethod();
19+
builder.WithHeaders("Content-Type");
20+
});
21+
});
22+
23+
// Adds the DevExpress middleware.
24+
builder.Services.AddDevExpressControls();
25+
// Adds controllers.
26+
builder.Services.AddControllersWithViews();
27+
28+
// Configures the dashboard backend.
29+
builder.Services.AddScoped<DashboardConfigurator>((IServiceProvider serviceProvider) => {
30+
DashboardConfigurator configurator = new DashboardConfigurator();
31+
configurator.SetDashboardStorage(new DashboardFileStorage(fileProvider.GetFileInfo("Data/Dashboards").PhysicalPath));
32+
configurator.SetDataSourceStorage(CreateDataSourceStorage());
33+
configurator.SetConnectionStringsProvider(new DashboardConnectionStringsProvider(configuration));
34+
configurator.ConfigureDataConnection += Configurator_ConfigureDataConnection;
35+
return configurator;
36+
});
37+
38+
void Configurator_ConfigureDataConnection(object sender, ConfigureDataConnectionWebEventArgs e) {
39+
if (e.ConnectionName == "jsonSupport") {
40+
Uri fileUri = new Uri(fileProvider.GetFileInfo("Data/support.json").PhysicalPath, UriKind.RelativeOrAbsolute);
41+
JsonSourceConnectionParameters jsonParams = new JsonSourceConnectionParameters();
42+
jsonParams.JsonSource = new UriJsonSource(fileUri);
43+
e.ConnectionParameters = jsonParams;
2144
}
45+
if (e.ConnectionName == "jsonCategories") {
46+
Uri fileUri = new Uri(fileProvider.GetFileInfo("Data/categories.json").PhysicalPath, UriKind.RelativeOrAbsolute);
47+
JsonSourceConnectionParameters jsonParams = new JsonSourceConnectionParameters();
48+
jsonParams.JsonSource = new UriJsonSource(fileUri);
49+
e.ConnectionParameters = jsonParams;
50+
}
51+
}
52+
53+
DataSourceInMemoryStorage CreateDataSourceStorage() {
54+
DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
55+
56+
DashboardJsonDataSource jsonDataSourceSupport = new DashboardJsonDataSource("Support");
57+
jsonDataSourceSupport.ConnectionName = "jsonSupport";
58+
jsonDataSourceSupport.RootElement = "Employee";
59+
dataSourceStorage.RegisterDataSource("jsonDataSourceSupport", jsonDataSourceSupport.SaveToXml());
60+
61+
DashboardJsonDataSource jsonDataSourceCategories = new DashboardJsonDataSource("Categories");
62+
jsonDataSourceCategories.ConnectionName = "jsonCategories";
63+
jsonDataSourceCategories.RootElement = "Products";
64+
dataSourceStorage.RegisterDataSource("jsonDataSourceCategories", jsonDataSourceCategories.SaveToXml());
65+
return dataSourceStorage;
2266
}
67+
68+
var app = builder.Build();
69+
70+
// Registers the DevExpress middleware.
71+
app.UseDevExpressControls();
72+
73+
// Registers routing.
74+
app.UseRouting();
75+
// Registers CORS policies.
76+
app.UseCors("CorsPolicy");
77+
78+
// Maps the dashboard route.
79+
app.MapDashboardRoute("api/dashboard", "DefaultDashboard");
80+
// Requires CORS policies.
81+
app.MapControllers().RequireCors("CorsPolicy");
82+
83+
app.Run();
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
{
1+
{
22
"iisSettings": {
33
"windowsAuthentication": false,
44
"anonymousAuthentication": true,
55
"iisExpress": {
6-
"applicationUrl": "http://localhost:56736/",
7-
"sslPort": 44397
6+
"applicationUrl": "http://localhost:37326",
7+
"sslPort": 44355
88
}
99
},
1010
"profiles": {
11-
"IIS Express": {
12-
"commandName": "IISExpress",
11+
"asp_net_core_server": {
12+
"commandName": "Project",
13+
"dotnetRunMessages": true,
1314
"launchBrowser": true,
15+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
1416
"environmentVariables": {
1517
"ASPNETCORE_ENVIRONMENT": "Development"
1618
}
1719
},
18-
"AspNetCoreDashboardBackend": {
19-
"commandName": "Project",
20+
"IIS Express": {
21+
"commandName": "IISExpress",
2022
"launchBrowser": true,
2123
"environmentVariables": {
2224
"ASPNETCORE_ENVIRONMENT": "Development"
23-
},
24-
"applicationUrl": "https://localhost:5001;http://localhost:5000"
25+
}
2526
}
2627
}
27-
}
28+
}

asp-net-core-server/Startup.cs

-95
This file was deleted.

asp-net-core-server/appsettings.Development.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"Logging": {
33
"LogLevel": {
44
"Default": "Information",
5-
"Microsoft": "Warning",
6-
"Microsoft.Hosting.Lifetime": "Information"
5+
"Microsoft.AspNetCore": "Warning"
76
}
87
}
98
}

asp-net-core-server/appsettings.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
"Logging": {
33
"LogLevel": {
44
"Default": "Information",
5-
"Microsoft": "Warning",
6-
"Microsoft.Hosting.Lifetime": "Information"
5+
"Microsoft.AspNetCore": "Warning"
76
}
87
},
9-
"ConnectionStrings": {
10-
"Customers": "file=https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"
11-
},
128
"AllowedHosts": "*"
139
}

0 commit comments

Comments
 (0)