Skip to content

Commit a7dd088

Browse files
committed
chore: add server grouping service
1 parent c5f5601 commit a7dd088

File tree

13 files changed

+324
-0
lines changed

13 files changed

+324
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29418.71
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "aspnetmvc-ajax-service", "aspnetmvc-ajax-service\aspnetmvc-ajax-service.csproj", "{B5D08BD1-F9C1-4096-99D4-437499692F63}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B5D08BD1-F9C1-4096-99D4-437499692F63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B5D08BD1-F9C1-4096-99D4-437499692F63}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B5D08BD1-F9C1-4096-99D4-437499692F63}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B5D08BD1-F9C1-4096-99D4-437499692F63}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {812C263E-BB96-4085-A87B-4AC17DFE6079}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using aspnetmvc_ajax_service.Data;
6+
using Kendo.Mvc.Extensions;
7+
using Kendo.Mvc.UI;
8+
using Microsoft.AspNetCore.Mvc;
9+
10+
namespace aspnetmvc_ajax_service.Controllers
11+
{
12+
[ApiController]
13+
[Route("[controller]")]
14+
public class CustomersController : Controller
15+
{
16+
private SampleEntitiesDataContext context;
17+
18+
public CustomersController(SampleEntitiesDataContext context)
19+
{
20+
this.context = context;
21+
}
22+
23+
[HttpGet]
24+
public IActionResult Get([DataSourceRequest]DataSourceRequest request)
25+
{
26+
return Json(this.context.Customers.ToDataSourceResult(request));
27+
}
28+
}
29+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace aspnetmvc_ajax_service.Data
7+
{
8+
public class Customer
9+
{
10+
public string CustomerID { get; set; }
11+
public string Address { get; set; }
12+
public string City { get; set; }
13+
public string CompanyName { get; set; }
14+
public string ContactName { get; set; }
15+
public string ContactTitle { get; set; }
16+
public string Country { get; set; }
17+
public string Fax { get; set; }
18+
public string Phone { get; set; }
19+
public string PostalCode { get; set; }
20+
}
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace aspnetmvc_ajax_service.Data
9+
{
10+
public partial class SampleEntitiesDataContext : DbContext
11+
{
12+
public SampleEntitiesDataContext()
13+
: base(new DbContextOptions<SampleEntitiesDataContext>())
14+
{
15+
}
16+
17+
protected override void OnConfiguring(DbContextOptionsBuilder options)
18+
{
19+
var dataDirectory = Path.Combine(Startup.WebRootPath, "App_Data");
20+
21+
options.UseSqlite(@"Data Source=" + dataDirectory + System.IO.Path.DirectorySeparatorChar + @"sample.db;");
22+
}
23+
public virtual DbSet<Customer> Customers { get; set; }
24+
}
25+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace aspnetmvc_ajax_service.Data
7+
{
8+
public static class Seeder
9+
{
10+
public static void Seed(SampleEntitiesDataContext context, int count)
11+
{
12+
var addresses = context.Customers.Select(x => x.Address).ToList();
13+
var cities = context.Customers.Select(x => x.City).ToList();
14+
var companynames = context.Customers.Select(x => x.CompanyName).ToList();
15+
var contactnames = context.Customers.Select(x => x.ContactName).ToList();
16+
var contacttitles = context.Customers.Select(x => x.ContactTitle).ToList();
17+
var countries = context.Customers.Select(x => x.Country).ToList();
18+
var faxes = context.Customers.Select(x => x.Fax).ToList();
19+
var phones = context.Customers.Select(x => x.Phone).ToList();
20+
var postalcodes = context.Customers.Select(x => x.PostalCode).ToList();
21+
var random = new Random();
22+
23+
for (int i = 0; i < count; i++)
24+
{
25+
context.Customers.Add(new Customer
26+
{
27+
Address = addresses[random.Next(0, addresses.Count - 1)],
28+
City = cities[random.Next(0, cities.Count - 1)],
29+
CompanyName = companynames[random.Next(0, companynames.Count - 1)]+" " + cities[random.Next(0, cities.Count - 1)],
30+
ContactName = contactnames[random.Next(0, contactnames.Count - 1)],
31+
ContactTitle = contacttitles[random.Next(0, contacttitles.Count - 1)],
32+
Country = countries[random.Next(0, countries.Count - 1)],
33+
Fax = faxes[random.Next(0, faxes.Count - 1)],
34+
Phone = phones[random.Next(0, phones.Count - 1)],
35+
PostalCode = phones[random.Next(0, phones.Count - 1)],
36+
CustomerID = Seeder.RandomString(15, random)
37+
});
38+
}
39+
40+
context.SaveChanges();
41+
}
42+
43+
public static string RandomString(int length, Random random)
44+
{
45+
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
46+
return new string(Enumerable.Repeat(chars, length)
47+
.Select(s => s[random.Next(s.Length)]).ToArray());
48+
}
49+
}
50+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
10+
11+
namespace aspnetmvc_ajax_service
12+
{
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
CreateWebHostBuilder(args).Build().Run();
18+
}
19+
20+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
21+
WebHost.CreateDefaultBuilder(args)
22+
.UseStartup<Startup>();
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:61473",
8+
"sslPort": 44330
9+
}
10+
},
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"launchUrl": "api/values",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"aspnetmvc_ajax_service": {
21+
"commandName": "Project",
22+
"launchBrowser": true,
23+
"launchUrl": "api/values",
24+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
25+
"environmentVariables": {
26+
"ASPNETCORE_ENVIRONMENT": "Development"
27+
}
28+
}
29+
}
30+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using aspnetmvc_ajax_service.Data;
6+
using Microsoft.AspNetCore.Builder;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.HttpsPolicy;
9+
using Microsoft.AspNetCore.Mvc;
10+
using Microsoft.Extensions.Configuration;
11+
using Microsoft.Extensions.DependencyInjection;
12+
using Microsoft.Extensions.Logging;
13+
using Microsoft.Extensions.Options;
14+
using Newtonsoft.Json.Serialization;
15+
16+
namespace aspnetmvc_ajax_service
17+
{
18+
public class Startup
19+
{
20+
public Startup(IConfiguration configuration, IHostingEnvironment env)
21+
{
22+
WebRootPath = env.WebRootPath;
23+
Configuration = configuration;
24+
var context = new SampleEntitiesDataContext();
25+
26+
if (context.Customers.Count() < 5000)
27+
{
28+
Seeder.Seed(context, 5000);
29+
}
30+
}
31+
32+
public static string WebRootPath
33+
{
34+
get; private set;
35+
}
36+
37+
public IConfiguration Configuration { get; }
38+
39+
public void ConfigureServices(IServiceCollection services)
40+
{
41+
services.AddCors(options => options.AddPolicy("CorsPolicy", builder =>
42+
{
43+
builder
44+
.AllowAnyMethod()
45+
.AllowAnyHeader()
46+
.AllowAnyOrigin();
47+
}));
48+
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
49+
.AddJsonOptions(options =>
50+
options.SerializerSettings.ContractResolver = new DefaultContractResolver());
51+
52+
// Add the Kendo UI services to the services container.
53+
services.AddKendo();
54+
55+
// SampleEntities db context
56+
services.AddDbContext<SampleEntitiesDataContext>();
57+
}
58+
59+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
60+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
61+
{
62+
if (env.IsDevelopment())
63+
{
64+
app.UseDeveloperExceptionPage();
65+
}
66+
else
67+
{
68+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
69+
app.UseHsts();
70+
}
71+
72+
app.UseHttpsRedirection();
73+
app.UseMvc();
74+
}
75+
}
76+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug",
5+
"System": "Information",
6+
"Microsoft": "Information"
7+
}
8+
}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Warning"
5+
}
6+
},
7+
"AllowedHosts": "*"
8+
}

0 commit comments

Comments
 (0)