import ChargingStationInfo from '../types/ChargingStationInfo';
import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants';
-import { FileType } from '../types/FileType';
-import FileUtils from '../utils/FileUtils';
import { SampledValueTemplate } from '../types/MeasurandPerPhaseSampledValueTemplates';
import { StandardParametersKey } from '../types/ocpp/Configuration';
import Utils from '../utils/Utils';
import { WebSocketCloseEventStatusString } from '../types/WebSocket';
import { WorkerProcessType } from '../types/Worker';
import crypto from 'crypto';
-import fs from 'fs';
+import { fileURLToPath } from 'url';
import logger from '../utils/Logger';
import moment from 'moment';
import path from 'path';
public static workerPoolInUse(): boolean {
return [WorkerProcessType.DYNAMIC_POOL, WorkerProcessType.STATIC_POOL].includes(
- Configuration.getWorkerProcess()
+ Configuration.getWorker().processType
);
}
public static workerDynamicPoolInUse(): boolean {
- return Configuration.getWorkerProcess() === WorkerProcessType.DYNAMIC_POOL;
+ return Configuration.getWorker().processType === WorkerProcessType.DYNAMIC_POOL;
}
/**
}
public static createStationInfoHash(stationInfo: ChargingStationInfo): void {
- const previousInfoHash = stationInfo?.infoHash ?? '';
delete stationInfo.infoHash;
- const currentInfoHash = crypto
+ stationInfo.infoHash = crypto
.createHash(Constants.DEFAULT_HASH_ALGORITHM)
.update(JSON.stringify(stationInfo))
.digest('hex');
- if (
- Utils.isEmptyString(previousInfoHash) ||
- (!Utils.isEmptyString(previousInfoHash) && currentInfoHash !== previousInfoHash)
- ) {
- stationInfo.infoHash = currentInfoHash;
- } else {
- stationInfo.infoHash = previousInfoHash;
- }
}
public static createSerialNumber(
);
}
- public static getAuthorizedTags(
- stationInfo: ChargingStationInfo,
- templateFile: string,
- logPrefix: string
- ): string[] {
- let authorizedTags: string[] = [];
- const authorizationFile = ChargingStationUtils.getAuthorizationFile(stationInfo);
- if (authorizationFile) {
- try {
- // Load authorization file
- authorizedTags = JSON.parse(fs.readFileSync(authorizationFile, 'utf8')) as string[];
- } catch (error) {
- FileUtils.handleFileException(
- logPrefix,
- FileType.Authorization,
- authorizationFile,
- error as NodeJS.ErrnoException
- );
- }
- } else {
- logger.info(logPrefix + ' No authorization file given in template file ' + templateFile);
- }
- return authorizedTags;
- }
-
public static getAuthorizationFile(stationInfo: ChargingStationInfo): string | undefined {
return (
stationInfo.authorizationFile &&
path.join(
- path.resolve(__dirname, '../'),
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
'assets',
path.basename(stationInfo.authorizationFile)
)