- public async start(): Promise<void> {
- if (!isMainThread) {
- throw new Error('Cannot start charging stations simulator from worker thread');
- }
- if (this.started === false) {
- if (this.starting === false) {
- this.starting = true;
- this.initializeCounters();
- this.initializeWorkerImplementation();
- await this.workerImplementation?.start();
- await this.storage?.open();
- this.uiServer?.start();
+ public get numberOfChargingStationTemplates (): number {
+ return this.chargingStationsByTemplate.size
+ }
+
+ public get numberOfConfiguredChargingStations (): number {
+ return [...this.chargingStationsByTemplate.values()].reduce(
+ (accumulator, value) => accumulator + value.configured,
+ 0
+ )
+ }
+
+ public getLastIndex (templateName: string): number {
+ return this.chargingStationsByTemplate.get(templateName)?.lastIndex ?? 0
+ }
+
+ private get numberOfAddedChargingStations (): number {
+ return [...this.chargingStationsByTemplate.values()].reduce(
+ (accumulator, value) => accumulator + value.added,
+ 0
+ )
+ }
+
+ private get numberOfStartedChargingStations (): number {
+ return [...this.chargingStationsByTemplate.values()].reduce(
+ (accumulator, value) => accumulator + value.started,
+ 0
+ )
+ }
+
+ public async start (): Promise<void> {
+ if (!this.started) {
+ if (!this.starting) {
+ this.starting = true
+ this.on(ChargingStationWorkerMessageEvents.added, this.workerEventAdded)
+ this.on(ChargingStationWorkerMessageEvents.started, this.workerEventStarted)
+ this.on(ChargingStationWorkerMessageEvents.stopped, this.workerEventStopped)
+ this.on(ChargingStationWorkerMessageEvents.updated, this.workerEventUpdated)
+ this.on(
+ ChargingStationWorkerMessageEvents.performanceStatistics,
+ this.workerEventPerformanceStatistics
+ )
+ this.initializeCounters()
+ const workerConfiguration = Configuration.getConfigurationSection<WorkerConfiguration>(
+ ConfigurationSection.worker
+ )
+ this.initializeWorkerImplementation(workerConfiguration)
+ await this.workerImplementation?.start()
+ const performanceStorageConfiguration =
+ Configuration.getConfigurationSection<StorageConfiguration>(
+ ConfigurationSection.performanceStorage
+ )
+ if (performanceStorageConfiguration.enabled === true) {
+ this.storage = StorageFactory.getStorage(
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ performanceStorageConfiguration.type!,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ performanceStorageConfiguration.uri!,
+ this.logPrefix()
+ )
+ await this.storage?.open()
+ }
+ Configuration.getConfigurationSection<UIServerConfiguration>(ConfigurationSection.uiServer)
+ .enabled === true && this.uiServer?.start()