+ return Configuration.getConfig()?.supervisionUrls;
+ }
+
+ 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) {
+ Configuration.handleFileException(
+ Configuration.configurationFile,
+ FileType.Configuration,
+ error as NodeJS.ErrnoException,
+ Configuration.logPrefix()
+ );
+ }
+ 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) {
+ Configuration.handleFileException(
+ Configuration.configurationFile,
+ FileType.Configuration,
+ error as NodeJS.ErrnoException,
+ Configuration.logPrefix()
+ );
+ }
+ }
+
+ private static handleFileException(
+ file: string,
+ fileType: FileType,
+ error: NodeJS.ErrnoException,
+ logPrefix: string
+ ): void {
+ const prefix = Utils.isNotEmptyString(logPrefix) ? `${logPrefix} ` : '';
+ let logMsg: string;
+ switch (error.code) {
+ case 'ENOENT':
+ logMsg = `${fileType} file ${file} not found:`;
+ break;
+ case 'EEXIST':
+ logMsg = `${fileType} file ${file} already exists:`;
+ break;
+ case 'EACCES':
+ logMsg = `${fileType} file ${file} access denied:`;
+ break;
+ default:
+ logMsg = `${fileType} file ${file} error:`;
+ }
+ console.warn(`${chalk.green(prefix)}${chalk.yellow(`${logMsg} `)}`, error);
+ }
+
+ private static getDefaultPerformanceStorageUri(storageType: StorageType) {
+ switch (storageType) {
+ case StorageType.JSON_FILE:
+ return Configuration.buildPerformanceUriFilePath(
+ Constants.DEFAULT_PERFORMANCE_RECORDS_FILENAME
+ );
+ case StorageType.SQLITE:
+ return Configuration.buildPerformanceUriFilePath(
+ `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`
+ );
+ default:
+ throw new Error(`Performance storage URI is mandatory with storage type '${storageType}'`);
+ }