+ static getSupervisionUrlDistribution(): SupervisionUrlDistribution | undefined {
+ Configuration.warnDeprecatedConfigurationKey(
+ 'distributeStationToTenantEqually',
+ undefined,
+ "Use 'supervisionUrlDistribution' instead"
+ );
+ Configuration.warnDeprecatedConfigurationKey(
+ 'distributeStationsToTenantsEqually',
+ undefined,
+ "Use 'supervisionUrlDistribution' instead"
+ );
+ return Utils.hasOwnProp(Configuration.getConfig(), 'supervisionUrlDistribution')
+ ? Configuration.getConfig()?.supervisionUrlDistribution
+ : SupervisionUrlDistribution.ROUND_ROBIN;
+ }
+
+ private static logPrefix = (): string => {
+ return `${new Date().toLocaleString()} Simulator configuration |`;
+ };
+
+ private static warnDeprecatedConfigurationKey(
+ key: string,
+ sectionName?: string,
+ logMsgToAppend = ''
+ ) {
+ if (
+ sectionName &&
+ !Utils.isUndefined(Configuration.getConfig()[sectionName]) &&
+ !Utils.isUndefined((Configuration.getConfig()[sectionName] as Record<string, unknown>)[key])
+ ) {
+ console.error(
+ chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage in section '${sectionName}'${
+ logMsgToAppend.trim().length > 0 ? `. ${logMsgToAppend}` : ''
+ }}`
+ );
+ } else if (!Utils.isUndefined(Configuration.getConfig()[key])) {
+ console.error(
+ chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage${
+ logMsgToAppend.trim().length > 0 ? `. ${logMsgToAppend}` : ''
+ }}`
+ );
+ }
+ }
+
+ // Read the config file
+ private static getConfig(): ConfigurationData | null {
+ if (!Configuration.configuration) {
+ try {
+ Configuration.configuration = JSON.parse(
+ fs.readFileSync(Configuration.configurationFile, 'utf8')
+ ) as ConfigurationData;
+ } catch (error) {
+ FileUtils.handleFileException(
+ Configuration.configurationFile,
+ FileType.Configuration,
+ error as NodeJS.ErrnoException,
+ Configuration.logPrefix(),
+ { consoleOut: true }
+ );
+ }
+ if (!Configuration.configurationFileWatcher) {
+ Configuration.configurationFileWatcher = Configuration.getConfigurationFileWatcher();
+ }
+ }
+ return Configuration.configuration;
+ }
+
+ private static getConfigurationFileWatcher(): fs.FSWatcher | undefined {
+ try {
+ return fs.watch(Configuration.configurationFile, (event, filename): void => {
+ if (filename?.trim().length > 0 && event === 'change') {
+ // Nullify to force configuration file reading
+ Configuration.configuration = null;
+ if (!Utils.isUndefined(Configuration.configurationChangeCallback)) {
+ Configuration.configurationChangeCallback().catch((error) => {
+ throw typeof error === 'string' ? new Error(error) : error;
+ });
+ }
+ }
+ });
+ } catch (error) {
+ FileUtils.handleFileException(
+ Configuration.configurationFile,
+ FileType.Configuration,
+ error as NodeJS.ErrnoException,
+ Configuration.logPrefix(),
+ { consoleOut: true }
+ );
+ }
+ }
+
+ private static getDefaultPerformanceStorageUri(storageType: StorageType) {
+ switch (storageType) {
+ case StorageType.JSON_FILE:
+ return `file://${path.join(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
+ Constants.DEFAULT_PERFORMANCE_RECORDS_FILENAME
+ )}`;
+ case StorageType.SQLITE:
+ return `file://${path.join(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
+ `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`
+ )}`;
+ default:
+ throw new Error(`Performance storage URI is mandatory with storage type '${storageType}'`);
+ }