- public async start(): Promise<void> {
- if (isMainThread && this.started === false) {
- try {
- // Enable unconditionally for now
- this.logUnhandledRejection();
- this.logUncaughtException();
- this.initialize();
- await this.storage?.open();
- await this.workerImplementation.start();
- this.uiServer?.start();
- const stationTemplateUrls = Configuration.getStationTemplateUrls();
- this.numberOfChargingStationTemplates = stationTemplateUrls.length;
- // Start ChargingStation object in worker thread
- if (!Utils.isEmptyArray(stationTemplateUrls)) {
- for (const stationTemplateUrl of stationTemplateUrls) {
- try {
- const nbStations = stationTemplateUrl.numberOfStations ?? 0;
- for (let index = 1; index <= nbStations; index++) {
- await this.startChargingStation(index, stationTemplateUrl);
- }
- } catch (error) {
- console.error(
- chalk.red(
- 'Error at starting charging station with template file ' +
- stationTemplateUrl.file +
- ': '
- ),
- error
- );
+ public getPerformanceStatistics (): IterableIterator<Statistics> | undefined {
+ return this.storage?.getPerformanceStatistics()
+ }
+
+ private get numberOfAddedChargingStations (): number {
+ return [...this.templateStatistics.values()].reduce(
+ (accumulator, value) => accumulator + value.added,
+ 0
+ )
+ }
+
+ private get numberOfStartedChargingStations (): number {
+ return [...this.templateStatistics.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.deleted, this.workerEventDeleted)
+ this.on(ChargingStationWorkerMessageEvents.started, this.workerEventStarted)
+ this.on(ChargingStationWorkerMessageEvents.stopped, this.workerEventStopped)
+ this.on(ChargingStationWorkerMessageEvents.updated, this.workerEventUpdated)
+ this.on(
+ ChargingStationWorkerMessageEvents.performanceStatistics,
+ this.workerEventPerformanceStatistics
+ )
+ // eslint-disable-next-line @typescript-eslint/unbound-method
+ if (isAsyncFunction(this.workerImplementation?.start)) {
+ await this.workerImplementation.start()
+ } else {
+ (this.workerImplementation?.start as () => void)()
+ }
+ 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()
+ }
+ if (
+ !this.uiServerStarted &&
+ Configuration.getConfigurationSection<UIServerConfiguration>(
+ ConfigurationSection.uiServer
+ ).enabled === true
+ ) {
+ this.uiServer.start()
+ this.uiServerStarted = true
+ }
+ // Start ChargingStation object instance in worker thread
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ for (const stationTemplateUrl of Configuration.getStationTemplateUrls()!) {
+ try {
+ const nbStations = stationTemplateUrl.numberOfStations
+ for (let index = 1; index <= nbStations; index++) {
+ await this.addChargingStation(index, stationTemplateUrl.file)