modules/Config.psm1
using module '.\Enums.psm1' using module '.\Helper\ObjectHelper.psm1' class Config{ #region Properties hidden [string] $globalSettingsFile = '~\PowerShell\SportsbookXray\global.settings.json' hidden [string] $userSettingsFile = '~\PowerShell\SportsbookXray\local.settings.json' [PSCustomObject] $autoUpdate [string] $auditLogFolder [hashtable] $endpoints [hashtable] $processors [hashtable] $downloaders [hashtable] $modules [double[]] $percentile #endregion #region Constructors hidden Config() { # Load global settings and merge user preferences $settings = [ObjectHelper]::MergeObject($this.LoadGlobalSettings(), $this.LoadUserSettings()) if ($settings){ $global:DEBUG = $settings.debug $global:VERBOSE = $settings.verbose $this.autoUpdate = $settings.autoUpdate $this.auditLogFolder = $settings.auditLogFolder $this.endpoints = @{} foreach ($operator in $settings.endpoints.PSObject.Properties){ $this.endpoints.Add([OPERATOR]($operator.Name), $operator.Value) } $this.processors = @{} foreach ($item in $settings.processors.PSobject.Properties) { $this.processors.Add([SOURCE_TYPE]($item.Name), $item.Value) } $this.downloaders = @{} foreach ($item in $settings.downloaders.PSobject.Properties) { $this.downloaders.Add($item.Name, $item.Value) } $this.modules = @{} foreach ($item in $settings.modules.PSobject.Properties) { $this.modules.Add([MODULE]$item.Name, $item.Value) } $this.percentile = $settings.percentile } else { throw "Cannot find settings file, please create it before you proceed with the analysis!" } } static [Config] Load(){ return [Config]::new() } #endregion hidden [PSCustomObject] LoadGlobalSettings(){ return $this.LoadSettings($this.globalSettingsFile) } hidden [PSCustomObject] LoadUserSettings(){ return $this.LoadSettings($this.userSettingsFile) } hidden [PSCustomObject] LoadSettings([string] $settingsFile){ $settings = $null if (Test-Path $settingsFile){ $settings = (Get-Content -Path $settingsFile | ConvertFrom-Json) } return $settings } static [PSCustomObject] DownloadSettings([string] $urlSettings){ $newSettings = (Invoke-WebRequest -Method GET -uri $urlSettings) $newSettings.content | Out-File -FilePath ([Config]::globalSettingsFile) return ($newSettings.content) } } |