the recent version of lg-sim 2019.09 has additionally support for webUI, cloud, which is a big enhencement. the following code review is focusing on new components to support WebUI, cluster management.
database
database used sqlite
project, which is an embedded in-memory db; the ORM used PetaPoco
project; there are a few db related serices, e.g. vehicleService, simulationService, which will be used in RESTful web request.
DatabaseManager
:
|
|
database ORMs
using PetaPoco
to define ORM
models, such asusers
, sessions
, maps
, vehicles
, clusters
, simulations
PetaPoco
a few operators in PetaPoco, such as Page
, used to query a page; Single
, used to query a single item; Insert
; Delete
; Update
database provider
|
|
called inside DatabaseManager::Init()
.
database services
VehicleService : IVehicleService
MapService
NotificationService => NotificationManager.SendNotification()
DownloadService => DownloadManager.AddDownloadToQueue()
ClusterService
SessionService
SimulationService
Web model
web model is where WebUI server located, which is served by Nancy
project, in which a new design metholody is applied: Inversin of Control Contaner(IoC), namely 控制反转
in chinese. IoC is used to inject implementation of class, and manage lifecycle, dependencies.
web model is the server where talk to webUI through routes, which is defined in the React project.
Nancy
used to build HTTP based web service,
- FileStream
- StreamResponse
- TinyIoC
- UnityBootstrapper : DefaultNancyBootstrapper, used to automatic discovery of modules, custm model binders, dependencies.
- /Assets/Scripts/Web/Nancy/NancyUnityUtils
|
|
inside some of the route modules will do query or update the sqlite database for special objects. till here is the complete web back-end server, with a http server and an in-memory database.
the webUI frontend is based on React, about React check a previous blog. in the React WebUI project will have http requests corresponding to each of routes defined here.
React front end is very independent framework, which should be handled by an independent team in standard pipeline.
Config & Loader
- /Assets/Scripts/Web/Config.cs:
used to define WebHost
, WebPort
, ApiHost
, ClourUrl
, Headless
, Sensors
, Bridges
e.t.c
- Loader.cs :
|
|
- DownloadManager
class Download();
Init(){ client = new WebClient(); ManageDownloads(); }
network module
network module
is used for communication among master and clients(workers) in the cluster network for cloud support. the P2P network is built on LiteNetLib
which is a reliable UDP lib.
LiteNetLib
LiteNetLibis Udp package, used to P2P communication among master node and slave nodes here, where are defined as MasterManager
, ClientManager
.
usage of LiteNetLib can be found in the wiki-usage)