Skip to content

Commit dab46db

Browse files
committed
Added server-side app (ServerApp) for Flutter later
1 parent 7bf9058 commit dab46db

71 files changed

Lines changed: 41698 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/launch.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Flutter-ServerApp",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
"program": "${workspaceFolder}/Samples/Flutter/ServerApp/bin/Debug/net5.0/ServerApp.dll",
13+
"args": [],
14+
"cwd": "${workspaceFolder}/Samples/Flutter/ServerApp",
15+
"stopAtEntry": false,
16+
"serverReadyAction": {
17+
"action": "openExternally",
18+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
19+
},
20+
"env": {
21+
"ASPNETCORE_ENVIRONMENT": "Development"
22+
},
23+
"sourceFileMap": {
24+
"/Views": "${workspaceFolder}/Views"
25+
}
26+
},
27+
{
28+
"name": ".NET Core Attach",
29+
"type": "coreclr",
30+
"request": "attach"
31+
}
32+
]
33+
}

.vscode/tasks.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/Samples/Flutter/ServerApp/ServerApp.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/Samples/Flutter/ServerApp/ServerApp.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"${workspaceFolder}/Samples/Flutter/ServerApp/ServerApp.csproj",
36+
"/property:GenerateFullPaths=true",
37+
"/consoleloggerparameters:NoSummary"
38+
],
39+
"problemMatcher": "$msCompile"
40+
}
41+
]
42+
}

NETCoreSync.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MobileSample.Android", "Sam
3333
EndProject
3434
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MobileSample.iOS", "Samples\DatabaseTimeStamp\MobileSample.iOS\MobileSample.iOS.csproj", "{9926FEB8-3A8D-4193-9BEA-BB9A04B7700F}"
3535
EndProject
36+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Flutter", "Flutter", "{F4136F18-FC7F-46D6-BFDB-64F37AC2436B}"
37+
EndProject
38+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerApp", "Samples\Flutter\ServerApp\ServerApp.csproj", "{866CD30E-CF42-4730-B1B2-4C1F11133ACA}"
39+
EndProject
3640
Global
3741
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3842
Debug|Any CPU = Debug|Any CPU
@@ -159,6 +163,18 @@ Global
159163
{9926FEB8-3A8D-4193-9BEA-BB9A04B7700F}.Release|iPhone.Build.0 = Release|iPhone
160164
{9926FEB8-3A8D-4193-9BEA-BB9A04B7700F}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
161165
{9926FEB8-3A8D-4193-9BEA-BB9A04B7700F}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
166+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
167+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Debug|Any CPU.Build.0 = Debug|Any CPU
168+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Debug|iPhone.ActiveCfg = Debug|Any CPU
169+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Debug|iPhone.Build.0 = Debug|Any CPU
170+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
171+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
172+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Release|Any CPU.ActiveCfg = Release|Any CPU
173+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Release|Any CPU.Build.0 = Release|Any CPU
174+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Release|iPhone.ActiveCfg = Release|Any CPU
175+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Release|iPhone.Build.0 = Release|Any CPU
176+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
177+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
162178
EndGlobalSection
163179
GlobalSection(SolutionProperties) = preSolution
164180
HideSolutionNode = FALSE
@@ -174,6 +190,8 @@ Global
174190
{8509338B-4690-4A54-A2C2-D903F009D3F8} = {17CFC0CB-D653-41BB-AF54-44933074FD3F}
175191
{6EAEE106-5DDF-4358-95B1-8353294812AE} = {17CFC0CB-D653-41BB-AF54-44933074FD3F}
176192
{9926FEB8-3A8D-4193-9BEA-BB9A04B7700F} = {17CFC0CB-D653-41BB-AF54-44933074FD3F}
193+
{F4136F18-FC7F-46D6-BFDB-64F37AC2436B} = {6329311D-90E0-40F9-A2BF-24811567F6D3}
194+
{866CD30E-CF42-4730-B1B2-4C1F11133ACA} = {F4136F18-FC7F-46D6-BFDB-64F37AC2436B}
177195
EndGlobalSection
178196
GlobalSection(ExtensibilityGlobals) = postSolution
179197
SolutionGuid = {F49E31F8-8627-4F02-B730-FFC003E9B7CF}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Logging;
8+
using ServerApp.Models;
9+
10+
namespace ServerApp.Controllers
11+
{
12+
public class HomeController : Controller
13+
{
14+
private readonly ILogger<HomeController> _logger;
15+
16+
public HomeController(ILogger<HomeController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
public IActionResult Index()
22+
{
23+
return View();
24+
}
25+
26+
public IActionResult Privacy()
27+
{
28+
return View();
29+
}
30+
31+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
32+
public IActionResult Error()
33+
{
34+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
35+
}
36+
}
37+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using ServerApp.Models;
8+
9+
namespace ServerApp.Controllers
10+
{
11+
public class SetupController : Controller
12+
{
13+
private readonly DatabaseContext databaseContext;
14+
15+
public SetupController(DatabaseContext databaseContext)
16+
{
17+
this.databaseContext = databaseContext;
18+
}
19+
20+
public IActionResult Index()
21+
{
22+
return View();
23+
}
24+
25+
public IActionResult ResetDatabase()
26+
{
27+
databaseContext.Employees.RemoveRange(databaseContext.Employees);
28+
databaseContext.Departments.RemoveRange(databaseContext.Departments);
29+
databaseContext.Knowledges.RemoveRange(databaseContext.Knowledges);
30+
databaseContext.SaveChanges();
31+
32+
return RedirectToAction("Index", "Home");
33+
}
34+
}
35+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.IO;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.AspNetCore.Http;
8+
using Microsoft.AspNetCore.Mvc.Rendering;
9+
using Microsoft.EntityFrameworkCore;
10+
using ServerApp.Models;
11+
using NETCoreSync;
12+
using Newtonsoft.Json.Linq;
13+
14+
namespace ServerApp.Controllers
15+
{
16+
public class SyncController : Controller
17+
{
18+
private readonly DatabaseContext databaseContext;
19+
private readonly SyncConfiguration syncConfiguration;
20+
21+
public SyncController(DatabaseContext databaseContext, SyncConfiguration syncConfiguration)
22+
{
23+
this.databaseContext = databaseContext;
24+
this.syncConfiguration = syncConfiguration;
25+
}
26+
27+
[HttpPost]
28+
[Consumes("multipart/form-data")]
29+
public IActionResult Index()
30+
{
31+
try
32+
{
33+
CustomSyncEngine customSyncEngine = new CustomSyncEngine(databaseContext, syncConfiguration);
34+
SyncServer syncServer = new SyncServer(customSyncEngine);
35+
36+
IFormFile syncData = Request.Form.Files.FirstOrDefault();
37+
if (syncData == null) throw new NullReferenceException(nameof(syncData));
38+
byte[] syncDataBytes = null;
39+
using (var memoryStream = new MemoryStream())
40+
{
41+
syncData.CopyTo(memoryStream);
42+
memoryStream.Seek(0, SeekOrigin.Begin);
43+
syncDataBytes = new byte[memoryStream.Length];
44+
memoryStream.Read(syncDataBytes, 0, syncDataBytes.Length);
45+
}
46+
JObject result = syncServer.Process(syncDataBytes);
47+
return Json(result);
48+
}
49+
catch (Exception e)
50+
{
51+
return Json(SyncServer.JsonErrorResponse(e.Message));
52+
}
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)